use of org.eclipse.text.edits.TextEdit in project che by eclipse.
the class TextChange method createTextEditProcessor.
private TextEditProcessor createTextEditProcessor(IDocument document, int flags, boolean preview) {
if (fEdit == null)
return new TextEditProcessor(document, new MultiTextEdit(0, 0), flags);
List excludes = new ArrayList(0);
TextEditBasedChangeGroup[] groups = getChangeGroups();
for (int index = 0; index < groups.length; index++) {
TextEditBasedChangeGroup edit = groups[index];
if (!edit.isEnabled()) {
excludes.addAll(Arrays.asList(edit.getTextEditGroup().getTextEdits()));
}
}
if (preview) {
fCopier = new TextEditCopier(fEdit);
TextEdit copiedEdit = fCopier.perform();
boolean keep = getKeepPreviewEdits();
if (keep)
flags = flags | TextEdit.UPDATE_REGIONS;
LocalTextEditProcessor result = new LocalTextEditProcessor(document, copiedEdit, flags);
result.setExcludes(mapEdits((TextEdit[]) excludes.toArray(new TextEdit[excludes.size()]), fCopier));
if (!keep)
fCopier = null;
return result;
} else {
LocalTextEditProcessor result = new LocalTextEditProcessor(document, fEdit, flags | TextEdit.UPDATE_REGIONS);
result.setExcludes((TextEdit[]) excludes.toArray(new TextEdit[excludes.size()]));
return result;
}
}
use of org.eclipse.text.edits.TextEdit in project che by eclipse.
the class CompilationUnitChangeNode method coveredBy.
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;
}
use of org.eclipse.text.edits.TextEdit in project che by eclipse.
the class TextChangeCompatibility method addTextEdit.
public static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException {
Assert.isNotNull(change);
Assert.isNotNull(name);
Assert.isNotNull(edit);
TextEdit root = change.getEdit();
if (root == null) {
root = new MultiTextEdit();
change.setEdit(root);
}
insert(root, edit);
change.addTextEditGroup(new TextEditGroup(name, edit));
}
use of org.eclipse.text.edits.TextEdit in project che by eclipse.
the class SurroundWithTryCatchRefactoring method createChange.
/* non Java-doc
* @see IRefactoring#createChange(IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
final String NN = "";
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();
}
}
use of org.eclipse.text.edits.TextEdit in project che by eclipse.
the class TextEditUtil method flatten.
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);
}
}
}
Aggregations