Search in sources :

Example 11 with CompositeChange

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

the class TextChangeCombinerTest method testMixedChanges.

@Test
public void testMixedChanges() throws Exception {
    IFile file1 = IResourcesSetupUtil.createFile(PROJECT + "/file1.txt", MODEL);
    ITextEditor editor1 = openInEditor(file1);
    CompositeChange compositeChange = new CompositeChange("test");
    compositeChange.add(createEditorDocumentChange(editor1, 1, 1, "foo"));
    compositeChange.add(createTextFileChange(file0, 1, 1, "foo"));
    CompositeChange compositeChange1 = new CompositeChange("test");
    compositeChange.add(compositeChange1);
    compositeChange1.add(createEditorDocumentChange(editor1, 3, 1, "baz"));
    compositeChange1.add(createTextFileChange(file0, 1, 1, "foo"));
    compositeChange1.add(createTextFileChange(file0, 3, 1, "baz"));
    Change combined = combiner.combineChanges(compositeChange);
    Change undo = combined.perform(new NullProgressMonitor());
    IDocument document1 = getDocument(editor1);
    assertEquals(MODEL.replace("123", "foo2baz"), document1.get());
    assertEquals(MODEL.replace("123", "foo2baz"), getContents(file0));
    undo.perform(new NullProgressMonitor());
    assertEquals(MODEL, document1.get());
    assertEquals(MODEL, getContents(file0));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) 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) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 12 with CompositeChange

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

the class TextChangeCombinerTest method testEmptyChange.

@Test
public void testEmptyChange() throws Exception {
    CompositeChange emptyChange = new CompositeChange("test");
    assertNull(combiner.combineChanges(emptyChange));
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Test(org.junit.Test)

Example 13 with CompositeChange

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

the class TextChangeCombinerTest method testMultipleFileChanges.

@Test
public void testMultipleFileChanges() throws Exception {
    CompositeChange compositeChange = new CompositeChange("test");
    compositeChange.add(createTextFileChange(file0, 1, 1, "foo"));
    compositeChange.add(createTextFileChange(file0, 2, 1, "bar"));
    CompositeChange compositeChange1 = new CompositeChange("test");
    compositeChange.add(compositeChange1);
    compositeChange1.add(createTextFileChange(file0, 3, 1, "baz"));
    compositeChange1.add(createTextFileChange(file0, 2, 1, "bar"));
    compositeChange1.add(createMultiTextFileChange(file0, 1, 1, "foo", 4, 1, "foo"));
    Change combined = combiner.combineChanges(compositeChange);
    assertTrue(combined instanceof CompositeChange);
    assertEquals(1, ((CompositeChange) combined).getChildren().length);
    Change combinedChild = ((CompositeChange) combined).getChildren()[0];
    assertTrue(combinedChild instanceof DisplayChangeWrapper.Wrapper);
    Change delegate = ((DisplayChangeWrapper.Wrapper) combinedChild).getDelegate();
    assertTextType(delegate);
    Change undo = combined.perform(new NullProgressMonitor());
    assertEquals(MODEL.replace("1234", "foobarbazfoo"), getContents(file0));
    undo.perform(new NullProgressMonitor());
    assertEquals(MODEL, getContents(file0));
}
Also used : DisplayChangeWrapper(org.eclipse.xtext.ui.refactoring.impl.DisplayChangeWrapper) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DisplayChangeWrapper(org.eclipse.xtext.ui.refactoring.impl.DisplayChangeWrapper) 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) Test(org.junit.Test)

Example 14 with CompositeChange

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

the class RenameModuleRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final CompositeChange c = (CompositeChange) super.createChange(pm);
    for (final ChangedFile f : changedFiles) {
        if (f.isNameChanged()) {
            final IPath p = f.getPath();
            final String s = f.getNewName();
            final RenameResourceChange rch = new RenameResourceChange(p, s);
            c.add(rch);
        }
    }
    return c;
}
Also used : IPath(org.eclipse.core.runtime.IPath) RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile)

Example 15 with CompositeChange

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

the class WranglerRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    pm.beginTask("Creating changes", changedFiles.size() + 1);
    final CompositeChange change = new CompositeChange(getName());
    pm.internalWorked(1);
    try {
        Change c;
        for (final ChangedFile e : changedFiles) {
            c = e.createChanges();
            if (c != null) {
                change.add(c);
                pm.internalWorked(1);
            }
        }
    } catch (final IOException e) {
        final Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
        throw new CoreException(s);
    } finally {
        pm.done();
    }
    return change;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) IOException(java.io.IOException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile)

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