当前位置: 首页>>代码示例>>Java>>正文


Java TextEdit.addChild方法代码示例

本文整理汇总了Java中org.eclipse.text.edits.TextEdit.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java TextEdit.addChild方法的具体用法?Java TextEdit.addChild怎么用?Java TextEdit.addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.text.edits.TextEdit的用法示例。


在下文中一共展示了TextEdit.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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(JavaUIStatus.createError(IStatus.ERROR, e));
    }
  }
  if (fImportRewrite != null) {
    editRoot.addChild(fImportRewrite.rewriteImports(new NullProgressMonitor()));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ASTRewriteCorrectionProposal.java

示例7: 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(JavaUIStatus.createError(IStatus.ERROR, e));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:JavadocTagsSubProcessor.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.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, 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,项目名称:che,代码行数:23,代码来源:RenameNodeCorrectionProposal.java

示例9: addEdits

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
  super.addEdits(document, rootEdit);

  try {
    Position pos = getUpdatedPosition(document);
    if (pos != null) {
      rootEdit.addChild(new ReplaceEdit(pos.getOffset(), pos.getLength(), "")); // $NON-NLS-1$
    } else {
      rootEdit.addChild(
          new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), "")); // $NON-NLS-1$
    }
  } catch (BadLocationException e) {
    throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:TaskMarkerProposal.java

示例10: testPerform

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
public void testPerform() throws CoreException {
  // Create a dummy change for updating references in RefactorTest.java
  // to the class R to its new name 'RRR'
  ICompilationUnit cu = refactorTestClass.getCompilationUnit();
  GWTRefactoringSupport support = new DummyRefactoringSupport();
  JsniReferenceChangeFactory factory = new JsniReferenceChangeFactory(support);
  IJsniReferenceChange jsniChange = factory.createChange(cu);

  // Add one dummy edit to the change
  TextEdit oldRootEdit = new MultiTextEdit();
  oldRootEdit.addChild(new ReplaceEdit(252, 0, ""));
  ((TextFileChange)jsniChange).setEdit(oldRootEdit);

  // Perform the change (this should replace the original edits with new ones
  // with the correct offsets).
  ((TextFileChange)jsniChange).perform(new NullProgressMonitor());

  // Verify that the change still has one edit
  TextEdit newRootEdit = ((TextFileChange)jsniChange).getEdit();
  assertEquals(1, newRootEdit.getChildrenSize());
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:22,代码来源:JsniReferenceChangeTest.java

示例11: addEdits

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit rootEdit) throws CoreException {
	super.addEdits(doc, rootEdit);

	TextEdit edit= new ReplaceEdit(fOffset, fLength, fReplacementString);
	rootEdit.addChild(edit);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:ReplaceCorrectionProposal.java

示例12: doCommand

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
@Override
protected void doCommand(IDocument document) throws BadLocationException {
	ISourceRange srTarget = target.getSourceRange();
	int insertOffset = srTarget.getOffset(); // BEFORE
	if (location == Insert.AFTER) {
		insertOffset += target.getLengthWithSep();
	}

	int docLen = document.getLength();
	String prefix = "";
	if (insertOffset > docLen) {
		insertOffset -= target.getLineDelim().length();
		prefix = target.getLineDelim();
	}

	TextEdit edit = new MultiTextEdit();
	String suffix = "";
	for (PagePart part : parts) {
		ISourceRange range = part.getSourceRange();
		int offset = range.getOffset();
		int len = part.getLengthWithSep();

		if (offset + len > docLen) {
			len -= target.getLineDelim().length();
			suffix = target.getLineDelim();
		}

		String text = prefix + document.get(offset, len) + suffix;
		edit.addChild(new DeleteEdit(offset, len));
		edit.addChild(new InsertEdit(insertOffset, text));
	}

	edit.apply(document);
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:35,代码来源:MovePartsCommand.java

示例13: formatBlank

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
private static void formatBlank(PagePart part, TextEdit edit) {
	ISourceRange range = part.getSourceRange();
	int eols = range.getEndLine() - range.getBeginLine() + 1;
	String rep = Strings.dup(part.getLineDelim(), eols);
	if (range.getOffset() + range.getLength() <= docLength) {
		edit.addChild(new ReplaceEdit(range.getOffset(), range.getLength(), rep));
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:9,代码来源:MkFormatter.java

示例14: formatText

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
private static void formatText(PagePart part, TextEdit edit, int cols) {
	ISourceRange range = part.getSourceRange();
	int offset = range.getOffset();
	int len = range.getLength() - part.getLineDelim().length();
	if (len <= 0) return;

	String content = part.getContent(true);
	content = TextFormatter.wrap(content, cols, part.getLineDelim());

	edit.addChild(new ReplaceEdit(offset, len, content));
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:12,代码来源:MkFormatter.java

示例15: formatListItem

import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
private static void formatListItem(PagePart part, int mark, TextEdit edit, int cols, int tabWidth) {
	ISourceRange range = part.getSublistRange(mark);
	int offset = range.getOffset();
	int len = range.getLength() - part.getLineDelim().length();
	if (len <= 0) return;

	String listItem = part.getSublistContent(mark);
	int indent = Indent.measureIndentInTabs(listItem, tabWidth);
	int markWidth = listMarkWidth(listItem);
	listItem = TextFormatter.wrap(listItem, cols, part.getLineDelim(), tabWidth * indent,
			(tabWidth * indent) + markWidth);

	edit.addChild(new ReplaceEdit(offset, len, listItem));
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:15,代码来源:MkFormatter.java


注:本文中的org.eclipse.text.edits.TextEdit.addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。