本文整理汇总了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);
}
}
示例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));
}
示例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()));
}
示例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()));
}
}
示例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));
}
}
示例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()));
}
}
示例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));
}
}
示例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));
}
示例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));
}
}
示例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());
}
示例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);
}
示例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);
}
示例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));
}
}
示例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));
}
示例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));
}