當前位置: 首頁>>代碼示例>>Java>>正文


Java Document類代碼示例

本文整理匯總了Java中org.eclipse.jface.text.Document的典型用法代碼示例。如果您正苦於以下問題:Java Document類的具體用法?Java Document怎麽用?Java Document使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Document類屬於org.eclipse.jface.text包,在下文中一共展示了Document類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fix

import org.eclipse.jface.text.Document; //導入依賴的package包/類
private void fix(IMarker marker, IProgressMonitor monitor) {
	MarkerResolutionGenerator.printAttributes (marker);
	try {
		String filepath  = (String) marker.getAttribute(BuildPolicyConfigurationException.JAVAFILENAME);
		int start = (int) marker.getAttribute(IMarker.CHAR_START);
		int end =  (int) marker.getAttribute(IMarker.CHAR_END);
		IFile ifile = (IFile) ResourceManager.toResource(new Path(filepath));
		ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
		String source = cu.getBuffer().getContents();
		String part1 =  source.substring(0,start);
		String part2 =  source.substring(end);
		source = part1 + "value=\"" + resolutionMarkerDescription.getGenerator() + "\"" + part2;
		final Document document = new Document(source);
		cu.getBuffer().setContents(document.get());
	    cu.save(monitor, false);
	} catch (Exception e) {
		ResourceManager.logException(e);
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:InvalidAnnotationPathGeneratorMarkerResolution.java

示例2: createCompositeXml

import org.eclipse.jface.text.Document; //導入依賴的package包/類
/**
 * This method initializes compositeXml
 * 
 */
private void createCompositeXml() {
	compositeXml = new Composite(sashForm, SWT.NONE);
	compositeXml.setLayout(new FillLayout());

	xmlView = new StructuredTextViewer(compositeXml, null, null, false, SWT.H_SCROLL | SWT.V_SCROLL);
	xmlView.setEditable(false);

	colorManager = new ColorManager();
	xmlView.configure(new XMLConfiguration(colorManager));

	Document document = new Document(
			"Click on the XML generation button to view the XML document generated by Convertigo.");
	IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] {
			XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT, });
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	xmlView.setDocument(document);
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:23,代碼來源:ConnectorEditorPart.java

示例3: documentGenerated

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public void documentGenerated(EngineEvent engineEvent) {
	if (!checkEventSource(engineEvent))
		return;

	if (bDebug) {
		try {
			ConvertigoPlugin.getDefault().debugConsoleStream
					.write("The XML document has been successfully generated.\n");
		} catch (IOException e) {
		}
	}
	lastGeneratedDocument = (org.w3c.dom.Document) engineEvent.getSource();
	final String strXML = XMLUtils.prettyPrintDOMWithEncoding(lastGeneratedDocument);
	getDisplay().asyncExec(new Runnable() {
		public void run() {
			xmlView.getDocument().set(strXML);
			editor.setDirty(false);
		}
	});
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:21,代碼來源:ConnectorEditorPart.java

示例4: createCompositeXml

import org.eclipse.jface.text.Document; //導入依賴的package包/類
/**
 * This method initializes compositeXml	
 *
 */
private void createCompositeXml() {
	compositeXml = new Composite(sashForm, SWT.NONE);
	compositeXml.setLayout(new FillLayout());
	
	xmlView = new StructuredTextViewer(compositeXml, null, null, false, SWT.H_SCROLL | SWT.V_SCROLL);
	xmlView.setEditable(false);

	colorManager = new ColorManager();
	xmlView.configure(new XMLConfiguration(colorManager));

	Document document = new Document("Click on the XML generation button to view the XML document generated by Convertigo.");
	IDocumentPartitioner partitioner =
		new FastPartitioner(
			new XMLPartitionScanner(),
			new String[] { 
				XMLPartitionScanner.XML_TAG,
				XMLPartitionScanner.XML_COMMENT,
			}
		);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	xmlView.setDocument(document);
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:28,代碼來源:SequenceEditorPart.java

示例5: documentGenerated

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public void documentGenerated(EngineEvent engineEvent) {
	if (!checkEventSource(engineEvent))
		return;
	
       if (bDebug) {
       	try {
			ConvertigoPlugin.getDefault().debugConsoleStream.write("The XML document has been successfully generated.\n");
		} catch (IOException e) {}
       }

	lastGeneratedDocument = (org.w3c.dom.Document) engineEvent.getSource();
	final String strXML = XMLUtils.prettyPrintDOMWithEncoding(lastGeneratedDocument);
	getDisplay().asyncExec(new Runnable() {
		public void run() {
			xmlView.getDocument().set(strXML);
	    	editor.setDirty(false);
		}
	});
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:20,代碼來源:SequenceEditorPart.java

示例6: postprocessGlobal

import org.eclipse.jface.text.Document; //導入依賴的package包/類
/**
 * Performs global post-processing of synthesized code:
 * - Adds import declarations
 *
 * @param ast      the owner of the document
 * @param env      environment that was used for synthesis
 * @param document draft program document
 * @throws BadLocationException if an error occurred when rewriting document
 */
private void postprocessGlobal(AST ast, Environment env, Document document)
        throws BadLocationException {
    /* add imports */
    ASTRewrite rewriter = ASTRewrite.create(ast);
    ListRewrite lrw = rewriter.getListRewrite(cu, CompilationUnit.IMPORTS_PROPERTY);
    Set<Class> toImport = new HashSet<>(env.imports);
    toImport.addAll(sketch.exceptionsThrown()); // add all catch(...) types to imports
    for (Class cls : toImport) {
        while (cls.isArray())
            cls = cls.getComponentType();
        if (cls.isPrimitive() || cls.getPackage().getName().equals("java.lang"))
            continue;
        ImportDeclaration impDecl = cu.getAST().newImportDeclaration();
        String className = cls.getName().replaceAll("\\$", "\\.");
        impDecl.setName(cu.getAST().newName(className.split("\\.")));
        lrw.insertLast(impDecl, null);
    }
    rewriter.rewriteAST(document, null).apply(document);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:29,代碼來源:Visitor.java

示例7: apply

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public String apply(String contents) {
    final TextEdit edit = codeFormatter.format(
            CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0,
            contents.length(), 0, Constants.LF);

    if (edit == null) {
        // TODO log a fatal or warning here. Throwing an exception is causing the actual freemarker error to be lost
        return contents;
    }

    IDocument document = new Document(contents);

    try {
        edit.apply(document);
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to format the generated source code.", e);
    }

    return document.get();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:23,代碼來源:JavaCodeFormatter.java

示例8: TMEditor

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public TMEditor(IGrammar grammar, ITokenProvider tokenProvider, String text) {
	shell = new Shell();
	viewer = new TextViewer(shell, SWT.NONE);
	document = new Document();
	viewer.setDocument(document);
	commands = new ArrayList<>();
	collector = new StyleRangesCollector();

	setAndExecute(text);

	reconciler = new TMPresentationReconciler();
	reconciler.addTMPresentationReconcilerListener(collector);
	reconciler.setGrammar(grammar);
	reconciler.setTokenProvider(tokenProvider);
	reconciler.install(viewer);

}
 
開發者ID:eclipse,項目名稱:tm4e,代碼行數:18,代碼來源:TMEditor.java

示例9: formatEclipseStyle

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public static String formatEclipseStyle(final Properties prop, final String content) {
  final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(prop);
  final IDocument document = new Document(content);
  try {
    final TextEdit textEdit =
        codeFormatter.format(
            CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
            content,
            0,
            content.length(),
            0,
            null);
    if (textEdit != null) {
      textEdit.apply(document);
    } else {
      return content;
    }
  } catch (final BadLocationException e) {
    return content;
  }

  return ensureCorrectNewLines(document.get());
}
 
開發者ID:mopemope,項目名稱:meghanada-server,代碼行數:24,代碼來源:JavaFormatter.java

示例10: getWorkspaceItem

import org.eclipse.jface.text.Document; //導入依賴的package包/類
private void getWorkspaceItem(final IProgressMonitor monitor) throws Exception {
    final TFSRepository repository =
        TFSCommonUIClientPlugin.getDefault().getProductPlugin().getRepositoryManager().getDefaultRepository();

    final GetVersionedItemToTempLocationCommand cmd = new GetVersionedItemToTempLocationCommand(
        repository,
        editorFile.getLocation().toOSString(),
        new WorkspaceVersionSpec(repository.getWorkspace()));

    final IStatus status = cmd.run(monitor);
    if (status != null && status.isOK()) {
        FileInputStream in = null;
        try {
            in = new FileInputStream(cmd.getTempLocation());
            final byte[] contents = new byte[in.available()];
            in.read(contents);
            reference = new Document(new String(contents));
        } finally {
            in.close();
        }
    }
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:23,代碼來源:TFSItemReferenceProvider.java

示例11: createDocument1

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public static IDocument createDocument1(){
   IDocument doc = new Document(){
      public String getDefaultLineDelimiter(){
         return String.valueOf(AssistConstants.LINE_DELIM_NL) /*super.getDefaultLineDelimiter()*/;
      }
   };
   IDocumentPartitioner partitioner = new DefaultPartitioner(
         new HPartitionScanner(), 
         new String[] {
             HPartitionScanner.COMMENT,
             HPartitionScanner.PROPERTY_VALUE});
   partitioner.connect(doc);
   doc.setDocumentPartitioner(partitioner);
   
   return doc;  
}
 
開發者ID:nextinterfaces,項目名稱:http4e,代碼行數:17,代碼來源:DocumentUtils.java

示例12: createDocument2

import org.eclipse.jface.text.Document; //導入依賴的package包/類
public static IDocument createDocument2() {
    IDocument document = new Document();
    if( document != null) {
        IDocumentPartitioner partitioner = new XMLPartitioner(
                new XMLPartitionScanner(), new String[] {
                        XMLPartitionScanner.XML_START_TAG,
                        XMLPartitionScanner.XML_PI,
                        XMLPartitionScanner.XML_DOCTYPE,
                        XMLPartitionScanner.XML_END_TAG,
                        XMLPartitionScanner.XML_TEXT,
                        XMLPartitionScanner.XML_CDATA,
                        XMLPartitionScanner.XML_COMMENT });
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);
    }
    return document;
}
 
開發者ID:nextinterfaces,項目名稱:http4e,代碼行數:18,代碼來源:DocumentUtils.java

示例13: visit

import org.eclipse.jface.text.Document; //導入依賴的package包/類
@Override
public boolean visit(CopyTargetEdit edit) {
	try {
		org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit();
		te.setRange(JDTUtils.toRange(compilationUnit, edit.getOffset(), edit.getLength()));

		Document doc = new Document(compilationUnit.getSource());
		edit.apply(doc, TextEdit.UPDATE_REGIONS);
		String content = doc.get(edit.getSourceEdit().getOffset(), edit.getSourceEdit().getLength());
		te.setNewText(content);
		converted.add(te);
	} catch (MalformedTreeException | BadLocationException | CoreException e) {
		JavaLanguageServerPlugin.logException("Error converting TextEdits", e);
	}
	return false; // do not visit children
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:17,代碼來源:TextEditConverter.java

示例14: getRecoveredAST

import org.eclipse.jface.text.Document; //導入依賴的package包/類
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
	CompilationUnit ast = SharedASTProvider.getInstance().getAST(fCompilationUnit, null);
	if (ast != null) {
		recoveredDocument.set(document.get());
		return ast;
	}

	char[] content= document.get().toCharArray();

	// clear prefix to avoid compile errors
	int index= offset - 1;
	while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
		content[index]= ' ';
		index--;
	}

	recoveredDocument.set(new String(content));

	final ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
	parser.setResolveBindings(true);
	parser.setStatementsRecovery(true);
	parser.setSource(content);
	parser.setUnitName(fCompilationUnit.getElementName());
	parser.setProject(fCompilationUnit.getJavaProject());
	return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:27,代碼來源:OverrideCompletionProposal.java

示例15: testWillSaveWaitUntil

import org.eclipse.jface.text.Document; //導入依賴的package包/類
@Test
public void testWillSaveWaitUntil() throws Exception {

	URI srcUri = project.getFile("src/java/Foo4.java").getRawLocationURI();
	ICompilationUnit cu = JDTUtils.resolveCompilationUnit(srcUri);

	StringBuilder buf = new StringBuilder();
	buf.append("package java;\n");
	buf.append("\n");
	buf.append("public class Foo4 {\n");
	buf.append("}\n");

	WillSaveTextDocumentParams params = new WillSaveTextDocumentParams();
	TextDocumentIdentifier document = new TextDocumentIdentifier();
	document.setUri(srcUri.toString());
	params.setTextDocument(document);

	List<TextEdit> result = handler.willSaveWaitUntil(params, monitor);

	Document doc = new Document();
	doc.set(cu.getSource());
	assertEquals(TextEditUtil.apply(doc, result), buf.toString());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:SaveActionHandlerTest.java


注:本文中的org.eclipse.jface.text.Document類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。