use of org.eclipse.ltk.core.refactoring.TextChange in project che by eclipse.
the class RenameFieldProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
TextChange[] changes = fChangeManager.getAllChanges();
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.TextChange 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.ltk.core.refactoring.TextChange in project che by eclipse.
the class QualifiedNameSearchResult method getSingleChange.
public Change getSingleChange(IFile[] alreadyTouchedFiles) {
Collection<TextChange> values = fChanges.values();
if (values.size() == 0)
return null;
CompositeChange result = new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name);
result.markAsSynthetic();
List<IFile> files = Arrays.asList(alreadyTouchedFiles);
for (Iterator<TextChange> iter = values.iterator(); iter.hasNext(); ) {
TextFileChange change = (TextFileChange) iter.next();
if (!files.contains(change.getFile())) {
result.add(change);
}
}
return result;
}
use of org.eclipse.ltk.core.refactoring.TextChange in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method createEdits.
private void createEdits(ICompilationUnit unit, ASTRewrite rewriter, List<TextEditGroup> groups, ImportRewrite importRewrite) throws CoreException {
TextChange change = fChangeManager.get(unit);
MultiTextEdit root = new MultiTextEdit();
change.setEdit(root);
root.addChild(importRewrite.rewriteImports(null));
root.addChild(rewriter.rewriteAST());
for (Iterator<TextEditGroup> iter = groups.iterator(); iter.hasNext(); ) {
change.addTextEditGroup(iter.next());
}
}
use of org.eclipse.ltk.core.refactoring.TextChange in project eclipse.platform.text by eclipse.
the class ReplaceRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
if (fReplaceString == null) {
return RefactoringStatus.createFatalErrorStatus(SearchMessages.ReplaceRefactoring_error_no_replace_string);
}
Pattern pattern = null;
FileSearchQuery query = getQuery();
if (query.isRegexSearch()) {
pattern = createSearchPattern(query);
}
RefactoringStatus resultingStatus = new RefactoringStatus();
Collection<IFile> allFilesSet = fMatches.keySet();
IFile[] allFiles = allFilesSet.toArray(new IFile[allFilesSet.size()]);
Arrays.sort(allFiles, new Comparator<IFile>() {
private Collator fCollator = Collator.getInstance();
@Override
public int compare(IFile o1, IFile o2) {
String p1 = o1.getFullPath().toString();
String p2 = o2.getFullPath().toString();
return fCollator.compare(p1, p2);
}
});
checkFilesToBeChanged(allFiles, resultingStatus);
if (resultingStatus.hasFatalError()) {
return resultingStatus;
}
CompositeChange compositeChange = new CompositeChange(SearchMessages.ReplaceRefactoring_composite_change_name);
compositeChange.markAsSynthetic();
ArrayList<MatchGroup> matchGroups = new ArrayList<>();
boolean hasChanges = false;
try {
for (IFile file : allFiles) {
Set<FileMatch> bucket = fMatches.get(file);
if (!bucket.isEmpty()) {
try {
TextChange change = createFileChange(file, pattern, bucket, resultingStatus, matchGroups);
if (change != null) {
compositeChange.add(change);
hasChanges = true;
}
} catch (CoreException e) {
String message = Messages.format(SearchMessages.ReplaceRefactoring_error_access_file, new Object[] { file.getName(), e.getLocalizedMessage() });
return RefactoringStatus.createFatalErrorStatus(message);
}
}
}
} catch (PatternSyntaxException e) {
String message = Messages.format(SearchMessages.ReplaceRefactoring_error_replacement_expression, e.getLocalizedMessage());
return RefactoringStatus.createFatalErrorStatus(message);
}
if (!hasChanges && resultingStatus.isOK()) {
return RefactoringStatus.createFatalErrorStatus(SearchMessages.ReplaceRefactoring_error_no_changes);
}
compositeChange.add(new SearchResultUpdateChange(fResult, matchGroups.toArray(new MatchGroup[matchGroups.size()]), fIgnoredMatches));
fChange = compositeChange;
return resultingStatus;
}
Aggregations