本文整理汇总了Java中org.eclipse.text.edits.MultiTextEdit.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java MultiTextEdit.addChild方法的具体用法?Java MultiTextEdit.addChild怎么用?Java MultiTextEdit.addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.text.edits.MultiTextEdit
的用法示例。
在下文中一共展示了MultiTextEdit.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enhanceExistingImportDeclaration
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
QualifiedName qualifiedName,
String optionalAlias, MultiTextEdit result) {
addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
int offset = replaceMe.getOffset();
AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
optionalAlias,
offset,
grammarAccess);
try {
serializer.serialize(
importDeclaration,
observableBuffer,
SaveOptions.newBuilder().noValidation().getOptions());
} catch (IOException e) {
throw new RuntimeException("Should never happen since we write into memory", e);
}
result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
return observableBuffer.getAliasLocation();
}
示例2: removeComment
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void removeComment(IDocument doc, int offset) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
int beg = par.getOffset();
int len = par.getLength();
String comment = doc.get(beg, len);
int eLen = markerLen(comment);
int bLen = eLen + 1;
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg, bLen));
edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing comment " + e.getMessage());
}
}
示例3: toTextEdit
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static void toTextEdit(CodeEdit codeEdit, IDocument document, MultiTextEdit textEdit)
throws TypeScriptException {
String newText = codeEdit.getNewText();
int startLine = codeEdit.getStart().getLine();
int startOffset = codeEdit.getStart().getOffset();
int endLine = codeEdit.getEnd().getLine();
int endOffset = codeEdit.getEnd().getOffset();
int start = DocumentUtils.getPosition(document, startLine, startOffset);
int end = DocumentUtils.getPosition(document, endLine, endOffset);
int length = end - start;
if (newText.isEmpty()) {
if (length > 0) {
textEdit.addChild(new DeleteEdit(start, length));
}
} else {
if (length > 0) {
textEdit.addChild(new ReplaceEdit(start, length, newText));
} else if (length == 0) {
textEdit.addChild(new InsertEdit(start, newText));
}
}
}
示例4: removeAndInsertNew
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void removeAndInsertNew(IBuffer buffer, int contentOffset, int contentEnd, ArrayList stringsToInsert, MultiTextEdit resEdit) {
int pos= contentOffset;
for (int i= 0; i < stringsToInsert.size(); i++) {
String curr= (String) stringsToInsert.get(i);
int idx= findInBuffer(buffer, curr, pos, contentEnd);
if (idx != -1) {
if (idx != pos) {
resEdit.addChild(new DeleteEdit(pos, idx - pos));
}
pos= idx + curr.length();
} else {
resEdit.addChild(new InsertEdit(pos, curr));
}
}
if (pos < contentEnd) {
resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
}
}
示例5: createMethodContent
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
/**
* Creates the method content of the moved method.
*
* @param document
* the document representing the source compilation unit
* @param declaration
* the source method declaration
* @param rewrite
* the ast rewrite to use
* @return the string representing the moved method body
* @throws BadLocationException
* if an offset into the document is invalid
*/
protected String createMethodContent(final IDocument document, final MethodDeclaration declaration, final ASTRewrite rewrite) throws BadLocationException {
Assert.isNotNull(document);
Assert.isNotNull(declaration);
Assert.isNotNull(rewrite);
final IRegion range= new Region(declaration.getStartPosition(), declaration.getLength());
final RangeMarker marker= new RangeMarker(range.getOffset(), range.getLength());
final IJavaProject project= fMethod.getJavaProject();
final TextEdit[] edits= rewrite.rewriteAST(document, project.getOptions(true)).removeChildren();
for (int index= 0; index < edits.length; index++)
marker.addChild(edits[index]);
final MultiTextEdit result= new MultiTextEdit();
result.addChild(marker);
final TextEditProcessor processor= new TextEditProcessor(document, new MultiTextEdit(0, document.getLength()), TextEdit.UPDATE_REGIONS);
processor.getRoot().addChild(result);
processor.performEdits();
final IRegion region= document.getLineInformation(document.getLineOfOffset(marker.getOffset()));
return Strings.changeIndent(document.get(marker.getOffset(), marker.getLength()), Strings.computeIndentUnits(document.get(region.getOffset(), region.getLength()), project), project, "", TextUtilities.getDefaultLineDelimiter(document)); //$NON-NLS-1$
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:32,代码来源:MoveInstanceMethodProcessor.java
示例6: fixEmptyVariables
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
IDocument doc= new Document(buffer.getString());
int nLines= doc.getNumberOfLines();
MultiTextEdit edit= new MultiTextEdit();
HashSet<Integer> removedLines= new HashSet<Integer>();
for (int i= 0; i < variables.length; i++) {
TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets= position.getOffsets();
for (int k= 0; k < offsets.length; k++) {
int line= doc.getLineOfOffset(offsets[k]);
IRegion lineInfo= doc.getLineInformation(line);
int offset= lineInfo.getOffset();
String str= doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
int nextStart= doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例7: applyGenerateProperties
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcessor requestProcessor)
throws BadLocationException, MalformedTreeException, MisconfigurationException {
IDocument refactoringDoc = new Document(data.source);
MultiTextEdit multi = new MultiTextEdit();
for (GeneratePropertiesRequest req : requestProcessor.getRefactoringRequests()) {
SelectionState state = req.getSelectionState();
if (state.isGetter()) {
multi.addChild(new GetterMethodEdit(req).getEdit());
}
if (state.isSetter()) {
multi.addChild(new SetterMethodEdit(req).getEdit());
}
if (state.isDelete()) {
multi.addChild(new DeleteMethodEdit(req).getEdit());
}
multi.addChild(new PropertyEdit(req).getEdit());
}
multi.apply(refactoringDoc);
return refactoringDoc;
}
示例8: addNewImportDeclaration
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private AliasLocation addNewImportDeclaration(QualifiedName moduleName, QualifiedName qualifiedName,
String optionalAlias,
int insertionOffset, MultiTextEdit result) {
final String spacer = lazySpacer.get();
String syntacticModuleName = syntacticModuleName(moduleName);
AliasLocation aliasLocation = null;
String importSpec = (insertionOffset != 0 ? lineDelimiter : "") + "import ";
if (!N4JSLanguageUtils.isDefaultExport(qualifiedName)) { // not an 'default' export
importSpec = importSpec + "{" + spacer + qualifiedName.getLastSegment();
if (optionalAlias != null) {
importSpec = importSpec + " as ";
aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
importSpec = importSpec + optionalAlias;
}
importSpec = importSpec + spacer + "}";
} else { // import default exported element
if (optionalAlias == null) {
importSpec = importSpec + N4JSLanguageUtils.lastSegmentOrDefaultHost(qualifiedName);
} else {
aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
importSpec = importSpec + optionalAlias;
}
}
result.addChild(new InsertEdit(insertionOffset, importSpec + " from "
+ syntacticModuleName + ";"
+ (insertionOffset != 0 ? "" : lineDelimiter)));
return aliasLocation;
}
示例9: computeEdits
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
@Override
public TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model) throws CoreException {
ImportRewrite impRewrite= StubUtility.createImportRewrite(fCompilationUnit, true);
String replaceString= impRewrite.addImport(fTypeProposal);
MultiTextEdit composedEdit= new MultiTextEdit();
composedEdit.addChild(new ReplaceEdit(position.getOffset(), position.getLength(), replaceString));
composedEdit.addChild(impRewrite.rewriteImports(null));
return composedEdit;
}
示例10: createChange
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
final String NN = ""; //$NON-NLS-1$
if (pm == null) {
pm = new NullProgressMonitor();
}
pm.beginTask(NN, 2);
try {
final CompilationUnitChange result = new CompilationUnitChange(getName(), fCUnit);
if (fLeaveDirty) {
result.setSaveMode(TextFileChange.LEAVE_DIRTY);
}
MultiTextEdit root = new MultiTextEdit();
result.setEdit(root);
fRewriter = ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST());
fRewriter.setTargetSourceRangeComputer(new SelectionAwareSourceRangeComputer(fAnalyzer.getSelectedNodes(), fCUnit.getBuffer(), fSelection.getOffset(), fSelection.getLength()));
fImportRewrite = StubUtility.createImportRewrite(fRootNode, true);
fLinkedProposalModel = new LinkedProposalModel();
fScope = CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection).findScope(fSelection.getOffset(), fSelection.getLength());
fScope.setCursor(fSelection.getOffset());
fSelectedNodes = fAnalyzer.getSelectedNodes();
createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator());
if (fImportRewrite.hasRecordedChanges()) {
TextEdit edit = fImportRewrite.rewriteImports(null);
root.addChild(edit);
result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { edit }));
}
TextEdit change = fRewriter.rewriteAST();
root.addChild(change);
result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { change }));
return result;
} finally {
pm.done();
}
}
示例11: remove
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void remove(int beg, int len, int markLen) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg - markLen, markLen));
edit.addChild(new DeleteEdit(beg + len, markLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing mark" + e.getMessage());
}
}
示例12: addComment
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void addComment(IDocument doc, int beg, int len) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, getCommentBeg()));
edit.addChild(new InsertEdit(beg + len, getCommentEnd()));
try {
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure creating comment " + e.getMessage());
}
}
示例13: fixEmptyVariables
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables)
throws MalformedTreeException, BadLocationException {
IDocument doc = new Document(buffer.getString());
int nLines = doc.getNumberOfLines();
MultiTextEdit edit = new MultiTextEdit();
HashSet<Integer> removedLines = new HashSet<Integer>();
for (int i = 0; i < variables.length; i++) {
TemplateVariable position =
findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets = position.getOffsets();
for (int k = 0; k < offsets.length; k++) {
int line = doc.getLineOfOffset(offsets[k]);
IRegion lineInfo = doc.getLineInformation(line);
int offset = lineInfo.getOffset();
String str = doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str)
&& nLines > line + 1
&& removedLines.add(new Integer(line))) {
int nextStart = doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例14: computeEdits
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
@Override
public TextEdit computeEdits(
int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model)
throws CoreException {
ImportRewrite impRewrite = StubUtility.createImportRewrite(fCompilationUnit, true);
String replaceString = impRewrite.addImport(fTypeProposal);
MultiTextEdit composedEdit = new MultiTextEdit();
composedEdit.addChild(
new ReplaceEdit(position.getOffset(), position.getLength(), replaceString));
composedEdit.addChild(impRewrite.rewriteImports(null));
return composedEdit;
}
示例15: flatten
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static void flatten(TextEdit edit, MultiTextEdit result) {
if (!edit.hasChildren()) {
result.addChild(edit);
} else {
TextEdit[] children = edit.getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit child = children[i];
child.getParent().removeChild(0);
flatten(child, result);
}
}
}