use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class TextMatchUpdater method addTextUpdates.
private void addTextUpdates(ICompilationUnit cu, Set<TextMatch> matches) {
for (Iterator<TextMatch> resultIter = matches.iterator(); resultIter.hasNext(); ) {
TextMatch match = resultIter.next();
if (!match.isQualified() && fOnlyQualified)
continue;
int matchStart = match.getStartPosition();
ReplaceEdit edit = new ReplaceEdit(matchStart, fCurrentNameLength, fNewName);
try {
TextChangeCompatibility.addTextEdit(fManager.get(cu), TEXT_EDIT_LABEL, edit, TEXTUAL_MATCHES);
} catch (MalformedTreeException e) {
// conflicting update -> omit text match
}
}
}
use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class CorrectPackageDeclarationProposal method addEdits.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#addEdits(org.eclipse.jdt.internal.corext.textmanipulation
* .TextBuffer)
*/
@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 = StubUtility.getLineDelimiterUsed(cu);
//$NON-NLS-1$
String str = "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim;
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class StringFix method getReplace.
private static ReplaceEdit getReplace(int offset, int length, IBuffer buffer, boolean removeLeadingIndents) {
String replaceString = new String();
boolean hasMoreInComment = false;
// look after the tag
int next = offset + length;
while (next < buffer.getLength()) {
char ch = buffer.getChar(next);
if (IndentManipulation.isIndentChar(ch)) {
// remove all whitespace
next++;
} else if (IndentManipulation.isLineDelimiterChar(ch)) {
length = next - offset;
break;
} else if (ch == '/') {
next++;
if (next == buffer.getLength() || buffer.getChar(next) != '/') {
//$NON-NLS-1$
replaceString = "//";
} else {
length = next - offset - 1;
}
hasMoreInComment = true;
break;
} else {
//$NON-NLS-1$
replaceString = "//";
hasMoreInComment = true;
break;
}
}
if (!hasMoreInComment && removeLeadingIndents) {
while (offset > 0 && IndentManipulation.isIndentChar(buffer.getChar(offset - 1))) {
offset--;
length++;
}
}
if (length > 0) {
ReplaceEdit replaceEdit = new ReplaceEdit(offset, length, replaceString);
return replaceEdit;
} else {
return null;
}
}
use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class RenameNonVirtualMethodProcessor method addReferenceUpdates.
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
SearchResultGroup[] grouped = getOccurrences();
for (int i = 0; i < grouped.length; i++) {
SearchResultGroup group = grouped[i];
SearchMatch[] results = group.getSearchResults();
ICompilationUnit cu = group.getCompilationUnit();
TextChange change = manager.get(cu);
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
if (!(match instanceof MethodDeclarationMatch)) {
ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
addTextEdit(change, editName, replaceEdit);
}
}
}
pm.done();
}
use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class RenameFieldProcessor method addDeclarationUpdate.
private void addDeclarationUpdate() throws CoreException {
ISourceRange nameRange = fField.getNameRange();
TextEdit textEdit = new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
ICompilationUnit cu = fField.getCompilationUnit();
String groupName = RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration;
addTextEdit(fChangeManager.get(cu), groupName, textEdit);
}
Aggregations