use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class RenameMethodProcessor method simpleUpdate.
private void simpleUpdate(SearchMatch element, ICompilationUnit cu, TextChange textChange) {
String editName = RefactoringCoreMessages.RenameMethodRefactoring_update_occurrence;
ReplaceEdit replaceEdit = createReplaceEdit(element, cu);
addTextEdit(textChange, editName, replaceEdit);
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls 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 eclipse.jdt.ls by eclipse.
the class MoveCuUpdateCreator method addReferenceUpdates.
private void addReferenceUpdates(TextChangeManager changeManager, ICompilationUnit movedUnit, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException, CoreException {
List<ICompilationUnit> cuList = Arrays.asList(fCus);
SearchResultGroup[] references = getReferences(movedUnit, pm, status);
for (int i = 0; i < references.length; i++) {
SearchResultGroup searchResultGroup = references[i];
ICompilationUnit referencingCu = searchResultGroup.getCompilationUnit();
if (referencingCu == null) {
continue;
}
boolean simpleReferencesNeedNewImport = simpleReferencesNeedNewImport(movedUnit, referencingCu, cuList);
SearchMatch[] results = searchResultGroup.getSearchResults();
for (int j = 0; j < results.length; j++) {
// TODO: should update type references with results from addImport
TypeReference reference = (TypeReference) results[j];
if (reference.isImportDeclaration()) {
ImportRewrite rewrite = getImportRewrite(referencingCu);
IImportDeclaration importDecl = (IImportDeclaration) SearchUtils.getEnclosingJavaElement(results[j]);
if (Flags.isStatic(importDecl.getFlags())) {
rewrite.removeStaticImport(importDecl.getElementName());
addStaticImport(movedUnit, importDecl, rewrite);
} else {
rewrite.removeImport(importDecl.getElementName());
rewrite.addImport(createStringForNewImport(movedUnit, importDecl));
}
} else if (reference.isQualified()) {
TextChange textChange = changeManager.get(referencingCu);
String changeName = RefactoringCoreMessages.MoveCuUpdateCreator_update_references;
TextEdit replaceEdit = new ReplaceEdit(reference.getOffset(), reference.getSimpleNameStart() - reference.getOffset(), fNewPackage);
TextChangeCompatibility.addTextEdit(textChange, changeName, replaceEdit);
} else if (simpleReferencesNeedNewImport) {
ImportRewrite importEdit = getImportRewrite(referencingCu);
String typeName = reference.getSimpleName();
importEdit.addImport(getQualifiedType(fDestination.getElementName(), typeName));
}
}
}
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class CreateCopyOfCompilationUnitChange method createChangeManager.
private static TextChangeManager createChangeManager(IProgressMonitor monitor, ICompilationUnit copy, String newName) throws CoreException {
TextChangeManager manager = new TextChangeManager();
SearchResultGroup refs = getReferences(copy, monitor);
if (refs == null) {
return manager;
}
if (refs.getCompilationUnit() == null) {
return manager;
}
String name = RefactoringCoreMessages.CopyRefactoring_update_ref;
SearchMatch[] results = refs.getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch searchResult = results[j];
if (searchResult.getAccuracy() == SearchMatch.A_INACCURATE) {
continue;
}
int offset = searchResult.getOffset();
int length = searchResult.getLength();
TextChangeCompatibility.addTextEdit(manager.get(copy), name, new ReplaceEdit(offset, length, newName));
}
return manager;
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.jdt.ls by eclipse.
the class FormatterHandler method convertEdit.
private static org.eclipse.lsp4j.TextEdit convertEdit(TextEdit edit, IDocument document) {
org.eclipse.lsp4j.TextEdit textEdit = new org.eclipse.lsp4j.TextEdit();
if (edit instanceof ReplaceEdit) {
ReplaceEdit replaceEdit = (ReplaceEdit) edit;
textEdit.setNewText(replaceEdit.getText());
int offset = edit.getOffset();
textEdit.setRange(new Range(createPosition(document, offset), createPosition(document, offset + edit.getLength())));
}
return textEdit;
}
Aggregations