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


Java TextEdit類代碼示例

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


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

示例1: format

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
/**
 * This method makes sure that no changes are applied (no dirty state), if there are no changes. This fixes bug
 * GHOLD-272
 */
@Override
public void format(IDocument document, IRegion region) {
	IXtextDocument doc = (IXtextDocument) document;
	TextEdit e = doc.priorityReadOnly(new FormattingUnitOfWork(doc, region));

	if (e == null)
		return;
	if (e instanceof ReplaceEdit) {
		ReplaceEdit r = (ReplaceEdit) e;
		if ((r.getOffset() == 0) && (r.getLength() == 0) && (r.getText().isEmpty())) {
			return;
		}
	}
	try {
		e.apply(document);
	} catch (BadLocationException ex) {
		throw new RuntimeException(ex);
	}

}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:25,代碼來源:FixedContentFormatter.java

示例2: save

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
/**
 * Save the AST int he Compilation Unit
 * 
 * @param testInterface
 * @param rewrite
 * @throws CoreException
 */
public static void save(CompilationUnit unit, ASTRewrite rewrite) throws CoreException {

	ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
	IPath path = unit.getJavaElement().getPath();
	try {
		bufferManager.connect(path, null);
		ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
		IDocument document = textFileBuffer.getDocument();
		TextEdit edit = rewrite.rewriteAST(document, null);
		edit.apply(document);
		textFileBuffer.commit(null /* ProgressMonitor */, true /* Overwrite */);
	} catch (Exception e) {
		ResourceManager.logException(e);
	} finally {
		// disconnect the path
		bufferManager.disconnect(path, null);
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:26,代碼來源:JDTManager.java

示例3: applyEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
/**
 * Method will apply all edits to document as single modification. Needs to
 * be executed in UI thread.
 *
 * @param document
 *            document to modify
 * @param edits
 *            list of LSP TextEdits
 */
public static void applyEdits(IDocument document, TextEdit edit) {
	if (document == null) {
		return;
	}

	IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
	if (manager != null) {
		manager.beginCompoundChange();
	}
	try {
		RewriteSessionEditProcessor editProcessor = new RewriteSessionEditProcessor(document, edit,
				org.eclipse.text.edits.TextEdit.NONE);
		editProcessor.performEdits();
	} catch (MalformedTreeException | BadLocationException e) {
		EditorConfigPlugin.logError(e);
	}
	if (manager != null) {
		manager.endCompoundChange();
	}
}
 
開發者ID:angelozerr,項目名稱:ec4e,代碼行數:30,代碼來源:MarkerUtils.java

示例4: apply

import org.eclipse.text.edits.TextEdit; //導入依賴的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

示例5: formatEclipseStyle

import org.eclipse.text.edits.TextEdit; //導入依賴的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

示例6: organizeImportsInCompilationUnit

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
public void organizeImportsInCompilationUnit(ICompilationUnit unit, WorkspaceEdit rootEdit) {
	try {
		InnovationContext context = new InnovationContext(unit, 0, unit.getBuffer().getLength() - 1);
		CUCorrectionProposal proposal = new CUCorrectionProposal("OrganizeImports", unit, IProposalRelevance.ORGANIZE_IMPORTS) {
			@Override
			protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
				CompilationUnit astRoot = context.getASTRoot();
				OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, null);
				editRoot.addChild(op.createTextEdit(null));
			}
		};

		addWorkspaceEdit(unit, proposal, rootEdit);
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Problem organize imports ", e);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:18,代碼來源:OrganizeImportsCommand.java

示例7: visit

import org.eclipse.text.edits.TextEdit; //導入依賴的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

示例8: addEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
	super.addEdits(doc, root);

	// build a full AST
	CompilationUnit unit = SharedASTProvider.getInstance().getAST(getCompilationUnit(), null);

	ASTNode name= NodeFinder.perform(unit, fOffset, fLength);
	if (name instanceof SimpleName) {

		SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
		if (names != null) {
			for (int i= 0; i < names.length; i++) {
				SimpleName curr= names[i];
				root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
			}
			return;
		}
	}
	root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:22,代碼來源:RenameNodeCorrectionProposal.java

示例9: addEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
	super.addEdits(doc, root);

	ICompilationUnit cu= getCompilationUnit();

	IPackageFragment parentPack= (IPackageFragment) cu.getParent();
	IPackageDeclaration[] decls= cu.getPackageDeclarations();

	if (parentPack.isDefaultPackage() && decls.length > 0) {
		for (int i= 0; i < decls.length; i++) {
			ISourceRange range= decls[i].getSourceRange();
			root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
		}
		return;
	}
	if (!parentPack.isDefaultPackage() && decls.length == 0) {
		String lineDelim = "\n";
		String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
		root.addChild(new InsertEdit(0, str));
		return;
	}

	root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:CorrectPackageDeclarationProposal.java

示例10: addEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
@Override
protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
	super.addEdits(document, editRoot);
	ASTRewrite rewrite= getRewrite();
	if (rewrite != null) {
		try {
			TextEdit edit= rewrite.rewriteAST();
			editRoot.addChild(edit);
		} catch (IllegalArgumentException e) {
			throw new CoreException(StatusFactory.newErrorStatus("Invalid AST rewriter", e));
		}
	}
	if (fImportRewrite != null) {
		editRoot.addChild(fImportRewrite.rewriteImports(new NullProgressMonitor()));
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:17,代碼來源:ASTRewriteCorrectionProposal.java

示例11: addEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
	try {
		String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
		final IJavaProject project= getCompilationUnit().getJavaProject();
		IRegion region= document.getLineInformationOfOffset(fInsertPosition);

		String lineContent= document.get(region.getOffset(), region.getLength());
		String indentString= Strings.getIndentString(lineContent, project);
		String str= Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
		InsertEdit edit= new InsertEdit(fInsertPosition, str);
		rootEdit.addChild(edit);
		if (fComment.charAt(fComment.length() - 1) != '\n') {
			rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
			rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
		}
	} catch (BadLocationException e) {
		throw new CoreException(StatusFactory.newErrorStatus("Invalid edit", e));
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:21,代碼來源:JavadocTagsSubProcessor.java

示例12: formatPagePart

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
private static void formatPagePart(PagePart part, TextEdit edit) {
	switch (part.getKind()) {
		case BLANK:
			formatBlank(part, edit);
			break;
		case TEXT:
			formatText(part, edit, cols);
			break;
		case LIST:
			formatList(part, edit, cols, tabWidth);
			break;
		case TABLE:
			formatTable(part, edit);
			break;
		default:
			break;
	}
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:19,代碼來源:MkFormatter.java

示例13: performEdits

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
/**
 * Executes the text edits on the given document. Subclasses that override this method should call
 * <code>super.performEdits(document)</code>.
 *
 * @param document the document
 * @return an object representing the undo of the executed edits
 * @exception MalformedTreeException is thrown if the edit tree isn't in a valid state. This
 *     exception is thrown before any edit is executed. So the document is still in its original
 *     state.
 * @exception BadLocationException is thrown if one of the edits in the tree can't be executed.
 *     The state of the document is undefined if this exception is thrown.
 * @since 3.5
 */
protected UndoEdit performEdits(IDocument document)
    throws BadLocationException, MalformedTreeException {
  DocumentRewriteSession session = null;
  try {
    if (document instanceof IDocumentExtension4) {
      session =
          ((IDocumentExtension4) document)
              .startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
    }

    LinkedModeModel.closeAllModels(document);
    TextEditProcessor processor = createTextEditProcessor(document, TextEdit.CREATE_UNDO, false);
    return processor.performEdits();

  } finally {
    if (session != null) {
      ((IDocumentExtension4) document).stopRewriteSession(session);
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:34,代碼來源:TextChange.java

示例14: formatCode

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
private static String formatCode(String contents, Object codeFormatter) {
	if (codeFormatter instanceof CodeFormatter) {
		IDocument doc = new Document(contents);
		TextEdit edit = ((CodeFormatter) codeFormatter).format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
				doc.get().length(), 0, null);
		if (edit != null) {
			try {
				edit.apply(doc);
				contents = doc.get();
			} catch (Exception e) {
				System.out.println(e);
			}
		}
	}
	return contents;
}
 
開發者ID:stephanrauh,項目名稱:JSFLibraryGenerator,代碼行數:17,代碼來源:JavaFormatter.java

示例15: coveredBy

import org.eclipse.text.edits.TextEdit; //導入依賴的package包/類
private boolean coveredBy(TextEditBasedChangeGroup group, IRegion sourceRegion) {
  int sLength = sourceRegion.getLength();
  if (sLength == 0) return false;
  int sOffset = sourceRegion.getOffset();
  int sEnd = sOffset + sLength - 1;
  TextEdit[] edits = group.getTextEdits();
  for (int i = 0; i < edits.length; i++) {
    TextEdit edit = edits[i];
    if (edit.isDeleted()) return false;
    int rOffset = edit.getOffset();
    int rLength = edit.getLength();
    int rEnd = rOffset + rLength - 1;
    if (rLength == 0) {
      if (!(sOffset < rOffset && rOffset <= sEnd)) return false;
    } else {
      if (!(sOffset <= rOffset && rEnd <= sEnd)) return false;
    }
  }
  return true;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:21,代碼來源:CompilationUnitChangeNode.java


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