use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class RenameNodeCorrectionProposal method addEdits.
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
// build a full AST
CompilationUnit unit = CoreASTProvider.getInstance().getAST(getCompilationUnit(), CoreASTProvider.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));
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class ReplaceCorrectionProposal method addEdits.
@Override
protected void addEdits(IDocument doc, TextEdit rootEdit) throws CoreException {
super.addEdits(doc, rootEdit);
TextEdit edit = new ReplaceEdit(fOffset, fLength, fReplacementString);
rootEdit.addChild(edit);
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class TextEditConverter method applySourceModifier.
private String applySourceModifier(String content, ISourceModifier modifier) {
if (StringUtils.isBlank(content) || modifier == null) {
return content;
}
SimpleDocument subDocument = new SimpleDocument(content);
TextEdit newEdit = new MultiTextEdit(0, subDocument.getLength());
ReplaceEdit[] replaces = modifier.getModifications(content);
for (ReplaceEdit replace : replaces) {
newEdit.addChild(replace);
}
try {
newEdit.apply(subDocument, TextEdit.NONE);
} catch (BadLocationException e) {
JavaLanguageServerPlugin.logException("Error applying edit to document", e);
}
return subDocument.get();
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class RenameTypeProcessor method addReferenceUpdates.
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
// $NON-NLS-1$
pm.beginTask("", fReferences.length);
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null) {
continue;
}
String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class RenameTypeProcessor method addConstructorRenames.
private void addConstructorRenames(TextChangeManager manager) throws CoreException {
ICompilationUnit cu = fType.getCompilationUnit();
IMethod[] methods = fType.getMethods();
int typeNameLength = fType.getElementName().length();
for (int i = 0; i < methods.length; i++) {
if (methods[i].isConstructor()) {
/*
* constructor declarations cannot be fully qualified so we can use simple replace here
*
* if (methods[i].getNameRange() == null), then it's a binary file so it's wrong anyway
* (checked as a precondition)
*/
String methodName = methods[i].getElementName();
ISourceRange range = methods[i].getNameRange();
String sourceName = cu.getBuffer().getText(range.getOffset(), range.getLength());
boolean isValid = methodName.equals(sourceName);
if (isValid) {
String name = RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor;
TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName()));
}
}
}
}
Aggregations