Search in sources :

Example 6 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.

the class Changes method getModifiedFiles.

private static void getModifiedFiles(List<IFile> result, Change[] changes) {
    for (int i = 0; i < changes.length; i++) {
        Change change = changes[i];
        Object modifiedElement = change.getModifiedElement();
        if (modifiedElement instanceof IAdaptable) {
            IFile file = (IFile) ((IAdaptable) modifiedElement).getAdapter(IFile.class);
            if (file != null)
                result.add(file);
        }
        if (change instanceof CompositeChange) {
            getModifiedFiles(result, ((CompositeChange) change).getChildren());
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 7 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.

the class MoveResourcesProcessor method createChange.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", fResourcesToMove.length);
    try {
        CompositeChange compositeChange = new CompositeChange(getMoveDescription());
        compositeChange.markAsSynthetic();
        RefactoringChangeDescriptor descriptor = new RefactoringChangeDescriptor(createDescriptor());
        for (int i = 0; i < fResourcesToMove.length; i++) {
            MoveResourceChange moveChange = new MoveResourceChange(fResourcesToMove[i], fDestination);
            moveChange.setDescriptor(descriptor);
            compositeChange.add(moveChange);
        }
        return compositeChange;
    } finally {
        pm.done();
    }
}
Also used : MoveResourceChange(org.eclipse.ltk.core.refactoring.resource.MoveResourceChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 8 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.

the class ProcessorBasedRefactoring method addToTextChangeMap.

private void addToTextChangeMap(Change change) {
    if (change instanceof TextChange) {
        Object element = ((TextChange) change).getModifiedElement();
        if (element != null) {
            fTextChangeMap.put(element, change);
        }
        // under the file resource into the hash table if possible.
        if (change instanceof TextFileChange && !change.getClass().equals(TextFileChange.class)) {
            IFile file = ((TextFileChange) change).getFile();
            fTextChangeMap.put(file, change);
        }
    } else if (change instanceof CompositeChange) {
        Change[] children = ((CompositeChange) change).getChildren();
        for (int i = 0; i < children.length; i++) {
            addToTextChangeMap(children[i]);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 9 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.

the class CompositeRefactoringProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    SubMonitor monitor = SubMonitor.convert(pm, processors.size());
    CompositeChange compositeChange = new CompositeChange(getProcessorName());
    for (RefactoringProcessor processor : processors) {
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        compositeChange.add(processor.createChange(monitor.newChild(1)));
    }
    return textChangeCombiner.combineChanges(compositeChange);
}
Also used : RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 10 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.

the class TextChangeCombinerTest method assertTextType.

protected void assertTextType(Change change) {
    if (change instanceof CompositeChange) {
        for (Change child : ((CompositeChange) change).getChildren()) {
            assertTextType(child);
        }
    } else {
        assertTrue(change.getClass().getName(), change instanceof TextEditBasedChange);
        assertEquals(TEXT_TYPE, ((TextEditBasedChange) change).getTextType());
    }
}
Also used : TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Aggregations

CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)49 Change (org.eclipse.ltk.core.refactoring.Change)22 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)14 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)9 TextChange (org.eclipse.ltk.core.refactoring.TextChange)9 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)6 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)6 CoreException (org.eclipse.core.runtime.CoreException)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)3 TextEdit (org.eclipse.text.edits.TextEdit)3 IOException (java.io.IOException)2