Search in sources :

Example 1 with CompositeChange

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

the class RefactoringSession method getChangePreview.

public PreviewNode getChangePreview() {
    CompositeChange compositeChange;
    if (change instanceof CompositeChange) {
        compositeChange = (CompositeChange) change;
    } else {
        //$NON-NLS-1$
        compositeChange = new CompositeChange("Dummy Change");
        compositeChange.add(change);
    }
    previewNode = AbstractChangeNode.createNode(null, compositeChange);
    return previewNode;
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 2 with CompositeChange

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

the class RenameLinkedModeRefactoringSession method doRename.

/**
     * Make rename operation.
     * @param newName the name which will be applied
     * @return result of the rename operation
     * @throws CoreException if an error occurs while creating the refactoring instance
     * @throws InvocationTargetException if an error occurred while executing the
     * operation.
     * @throws InterruptedException if the operation has been canceled by the
     * user.
     */
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
    if (fOriginalName.equals(newName)) {
        return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
    }
    RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
    if (renameSupport == null)
        return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
    RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
    PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
    if (operation == null) {
        return refactoringResult;
    }
    CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
    Change[] changes = operationChange.getChildren();
    List<ChangeInfo> changesInfo = new ArrayList<>();
    prepareChangesInfo(changes, changesInfo);
    refactoringResult.setChanges(changesInfo);
    return refactoringResult;
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 3 with CompositeChange

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

the class DeleteChangeCreator method createPackageFragmentRootDeleteChange.

private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root) throws JavaModelException {
    IResource resource = root.getResource();
    if (resource != null && resource.isLinked()) {
        //XXX using this code is a workaround for jcore bug 31998
        //jcore cannot handle linked stuff
        //normally, we should always create DeletePackageFragmentRootChange
        CompositeChange composite = new DynamicValidationStateChange(RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root);
        ClasspathChange change = ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry());
        if (change != null) {
            composite.add(change);
        }
        //checked in preconditions
        Assert.isTrue(!Checks.isClasspathDelete(root));
        composite.add(createDeleteChange(resource));
        return composite;
    } else {
        Assert.isTrue(!root.isExternal());
        // TODO remove the query argument
        return new DeletePackageFragmentRootChange(root, true, null);
    }
}
Also used : ClasspathChange(org.eclipse.jdt.internal.corext.refactoring.changes.ClasspathChange) DeletePackageFragmentRootChange(org.eclipse.jdt.internal.corext.refactoring.changes.DeletePackageFragmentRootChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)

Example 4 with CompositeChange

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

the class JavaMoveProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    Assert.isTrue(fMovePolicy.getJavaElementDestination() == null || fMovePolicy.getResourceDestination() == null);
    Assert.isTrue(fMovePolicy.getJavaElementDestination() != null || fMovePolicy.getResourceDestination() != null);
    try {
        final DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.JavaMoveProcessor_change_name) {

            @Override
            public ChangeDescriptor getDescriptor() {
                return fMovePolicy.getDescriptor();
            }

            @Override
            public Change perform(IProgressMonitor pm2) throws CoreException {
                Change change = super.perform(pm2);
                Change[] changes = getChildren();
                for (int index = 0; index < changes.length; index++) {
                    if (!(changes[index] instanceof TextEditBasedChange))
                        return null;
                }
                return change;
            }
        };
        CreateTargetExecutionLog log = null;
        if (fCreateTargetQueries instanceof MonitoringCreateTargetQueries) {
            final MonitoringCreateTargetQueries queries = (MonitoringCreateTargetQueries) fCreateTargetQueries;
            final ICreateTargetQueries delegate = queries.getDelegate();
            if (delegate instanceof LoggedCreateTargetQueries)
                log = queries.getCreateTargetExecutionLog();
        }
        if (log != null) {
            final Object[] selected = log.getSelectedElements();
            for (int index = 0; index < selected.length; index++) {
                result.add(new LoggedCreateTargetChange(selected[index], fCreateTargetQueries));
            }
        }
        Change change = fMovePolicy.createChange(pm);
        if (change instanceof CompositeChange) {
            CompositeChange subComposite = (CompositeChange) change;
            result.merge(subComposite);
        } else {
            result.add(change);
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 5 with CompositeChange

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

the class DeletePackageFragmentRootChange method doDelete.

@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
    if (!confirmDeleteIfReferenced())
        return new NullChange();
    int resourceUpdateFlags = IResource.KEEP_HISTORY;
    int jCoreUpdateFlags = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
    //$NON-NLS-1$
    pm.beginTask("", 2);
    IPackageFragmentRoot root = getRoot();
    IResource rootResource = root.getResource();
    CompositeChange result = new CompositeChange(getName());
    ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
    IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
    HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
    for (int i = 0; i < referencingProjects.length; i++) {
        IJavaProject javaProject = referencingProjects[i];
        //$NON-NLS-1$
        IFile classpathFile = javaProject.getProject().getFile(".classpath");
        if (classpathFile.exists()) {
            classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
        }
    }
    root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));
    rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
    for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<IFile, String> entry = iterator.next();
        IFile file = entry.getKey();
        String contents = entry.getValue();
        //Restore time stamps? This should probably be some sort of UndoTextFileChange.
        TextFileChange classpathUndo = new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
        classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
        result.add(classpathUndo);
    }
    result.add(new UndoDeleteResourceChange(rootDescription));
    pm.done();
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource)

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