Search in sources :

Example 31 with TextChange

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();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 32 with TextChange

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();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch)

Example 33 with TextChange

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) TextChange(org.eclipse.ltk.core.refactoring.TextChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange)

Example 34 with TextChange

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());
    }
}
Also used : TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextEditGroup(org.eclipse.text.edits.TextEditGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 35 with TextChange

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;
}
Also used : Pattern(java.util.regex.Pattern) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Collator(com.ibm.icu.text.Collator) CoreException(org.eclipse.core.runtime.CoreException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

TextChange (org.eclipse.ltk.core.refactoring.TextChange)44 TextEdit (org.eclipse.text.edits.TextEdit)14 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)13 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)13 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IFile (org.eclipse.core.resources.IFile)7 IDocument (org.eclipse.jface.text.IDocument)7 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)6 Change (org.eclipse.ltk.core.refactoring.Change)6 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)6 Iterator (java.util.Iterator)5 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)5 HashMap (java.util.HashMap)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)4 IOException (java.io.IOException)3