use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.
the class RenameFieldProcessor method addAccessorOccurrences.
private void addAccessorOccurrences(IProgressMonitor pm, IMethod accessor, String editName, String newAccessorName, RefactoringStatus status) throws CoreException {
Assert.isTrue(accessor.exists());
IJavaSearchScope scope = RefactoringScopeFactory.create(accessor);
SearchPattern pattern = SearchPattern.createPattern(accessor, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchResultGroup[] groupedResults = RefactoringSearchEngine.search(pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);
for (int i = 0; i < groupedResults.length; i++) {
ICompilationUnit cu = groupedResults[i].getCompilationUnit();
if (cu == null)
continue;
SearchMatch[] results = groupedResults[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch searchResult = results[j];
TextEdit edit = new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
addTextEdit(fChangeManager.get(cu), editName, edit);
}
}
}
use of org.eclipse.text.edits.ReplaceEdit in project che 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 che 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 AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method replaceLineCommentBeforeJavaElement.
private void replaceLineCommentBeforeJavaElement(List<TextEdit> commentEdits, LineComment lineComment, List<LineComment> lineComments, int i, String source, TreeSet<Integer> lineStarts) {
final int replaceLength = "//".length();
final boolean isFirst = i == 0;
String replacementText;
final SourceLocation indentLoc = getIndentForJavadoc(lineComment, source, lineStarts);
if (isFirst) {
// TODO JNR how to obey configured indentation?
replacementText = "/**" + lineSeparator + indentLoc.substring(source) + " *";
} else {
replacementText = " *";
}
final boolean commentStartsWithSlash = source.charAt(lineComment.getStartPosition() + replaceLength) == '/';
if (commentStartsWithSlash) {
replacementText += " ";
}
commentEdits.add(new ReplaceEdit(lineComment.getStartPosition(), replaceLength, replacementText));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
final boolean isLast = i == lineComments.size() - 1;
if (isLast) {
// TODO JNR how to obey configured indentation?
final int position = getEndPosition(lineComment);
commentEdits.add(new InsertEdit(position, lineSeparator + indentLoc.substring(source) + " */"));
}
}
use of org.eclipse.text.edits.ReplaceEdit in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addSingleLineCommentToJavadocEdits.
private void addSingleLineCommentToJavadocEdits(List<TextEdit> commentEdits, ASTNode nextNode, List<LineComment> lineComments, String source, TreeSet<Integer> lineStarts) {
final int nodeStart = nextNode.getStartPosition();
final LineComment lineComment = lineComments.get(0);
// TODO JNR how to obey configured indentation?
// TODO JNR how to obey configured line length?
final int commentStart = lineComment.getStartPosition();
if (commentStart < nodeStart) {
// assume comment is situated exactly before target node for javadoc
final String spaceAtStart = getSpaceAtStart(source, lineComment);
commentEdits.add(new ReplaceEdit(commentStart, "//".length(), "/**" + spaceAtStart));
commentEdits.add(new InsertEdit(getEndPosition(lineComment), getSpaceAtEnd(source, lineComment) + "*/"));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
} else {
// assume comment is situated exactly after target node for javadoc
final StringBuilder newJavadoc = new StringBuilder().append("/**").append(getSpaceAtStart(source, lineComment));
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
SourceLocation indent = getIndent(nextNode, lineStarts);
newJavadoc.append(getSpaceAtEnd(source, lineComment)).append("*/").append(lineSeparator).append(source, indent.getStartPosition(), indent.getEndPosition());
commentEdits.add(new InsertEdit(nodeStart, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
}
Aggregations