Search in sources :

Example 21 with CompositeChange

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

the class JSPTypeMoveParticipant method createChange.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    if (pm != null && pm.isCanceled()) {
        return null;
    }
    CompositeChange multiChange = null;
    Object dest = getArguments().getDestination();
    if (dest instanceof IPackageFragment) {
        Change[] changes = JSPTypeMoveChange.createChangesFor(fType, ((IPackageFragment) dest).getElementName());
        if (changes.length > 0) {
            multiChange = new CompositeChange(JsUIMessages.JSP_changes, changes);
        }
    }
    return multiChange;
}
Also used : IPackageFragment(org.eclipse.wst.jsdt.core.IPackageFragment) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 22 with CompositeChange

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

the class JSPMoveParticipant method createChange.

/**
 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(
 * 	org.eclipse.core.runtime.IProgressMonitor)
 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    // $NON-NLS-1$
    this.getTextChange("");
    // create one multi change to contain all new created changes
    CompositeChange multiChange = new CompositeChange(JSPUIMessages.JSP_changes);
    // for each element get the changes for it and add it to the multi change
    Iterator iter = fElementAndArgumentPairs.values().iterator();
    while (iter.hasNext()) {
        ElementAndArgumentsPair elemArgsPair = (ElementAndArgumentsPair) iter.next();
        Object dest = elemArgsPair.fArgs.getDestination();
        if (dest instanceof IPackageFragment) {
            Change[] changes = createChangesFor(elemArgsPair.fElement, ((IPackageFragment) dest).getElementName(), pm);
            /* add all new text changes to the local list of text changes so that
				 * future iterations through the while loop will be aware of already
				 * existing changes
				 */
            for (int i = 0; i < changes.length; ++i) {
                if (changes[i] instanceof TextChange) {
                    fLocalTextChanges.put(((TextChange) changes[i]).getModifiedElement(), changes[i]);
                }
            }
            if (changes.length > 0) {
                multiChange.addAll(changes);
            }
        }
    }
    // unless there are actually new changes return null
    Change result = null;
    if (multiChange.getChildren().length > 0) {
        result = multiChange;
    }
    return result;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Iterator(java.util.Iterator) TextChange(org.eclipse.ltk.core.refactoring.TextChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 23 with CompositeChange

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

the class PerformUnsavedRefactoringOperation method run.

public void run(IProgressMonitor pm) {
    if (pm == null) {
        pm = new NullProgressMonitor();
    }
    try {
        refactoring.checkAllConditions(pm);
        Change change = refactoring.createChange(pm);
        if (change instanceof CompositeChange) {
            CompositeChange compositeChange = (CompositeChange) change;
            setSaveMode(compositeChange);
        }
        change.perform(pm);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 24 with CompositeChange

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

the class DeleteResourcesProcessor 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, OperationCanceledException {
    pm.beginTask(RefactoringCoreMessages.DeleteResourcesProcessor_create_task, fResources.length);
    try {
        RefactoringChangeDescriptor descriptor = new RefactoringChangeDescriptor(createDescriptor());
        CompositeChange change = new CompositeChange(RefactoringCoreMessages.DeleteResourcesProcessor_change_name);
        change.markAsSynthetic();
        for (int i = 0; i < fResources.length; i++) {
            pm.worked(1);
            DeleteResourceChange dc = new DeleteResourceChange(fResources[i].getFullPath(), true, fDeleteContents);
            dc.setDescriptor(descriptor);
            change.add(dc);
        }
        return change;
    } finally {
        pm.done();
    }
}
Also used : DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 25 with CompositeChange

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

the class RenamePackageProcessor method postCreateChange.

@Override
public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException {
    if (fQualifiedNameSearchResult != null) {
        CompositeChange parent = (CompositeChange) fRenamePackageChange.getParent();
        try {
            /*
				 * Sneak text changes in before the package rename to ensure
				 * modified files are still at original location (see
				 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154238)
				 */
            parent.remove(fRenamePackageChange);
            parent.add(fQualifiedNameSearchResult.getSingleChange(Changes.getModifiedFiles(participantChanges)));
        } finally {
            fQualifiedNameSearchResult = null;
            parent.add(fRenamePackageChange);
            fRenamePackageChange = null;
        }
    }
    return null;
}
Also used : 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