Search in sources :

Example 6 with DynamicValidationStateChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange 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 7 with DynamicValidationStateChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange in project che by eclipse.

the class RenameCompilationUnitProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    // renaming the file is taken care of in renameTypeRefactoring
    if (fWillRenameType)
        return fRenameTypeProcessor.createChange(pm);
    fRenameTypeProcessor = null;
    final String newName = getNewElementName();
    final IResource resource = fCu.getResource();
    if (resource != null && resource.isLinked()) {
        final IProject project = resource.getProject();
        final String name = project.getName();
        final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getResourceName(resource.getName()));
        final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getResourceName(resource.getName()) });
        final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
        final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
        final RenameResourceDescriptor descriptor = (RenameResourceDescriptor) RefactoringCore.getRefactoringContribution(RenameResourceDescriptor.ID).createDescriptor();
        descriptor.setProject(name);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(flags);
        descriptor.setResourcePath(resource.getFullPath());
        descriptor.setNewName(newName);
        RenameResourceChange resourceChange = new RenameResourceChange(resource.getFullPath(), newName);
        resourceChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return new DynamicValidationStateChange(resourceChange);
    }
    String label = JavaElementLabels.getTextLabel(fCu, JavaElementLabels.ALL_FULLY_QUALIFIED);
    final String name = fCu.getJavaProject().getElementName();
    final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getFileName(fCu));
    final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { label, BasicElementLabels.getResourceName(newName) });
    final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
    final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_COMPILATION_UNIT);
    descriptor.setProject(name);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fCu);
    descriptor.setNewName(newName);
    return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameCompilationUnitRefactoring_name, new Change[] { new RenameCompilationUnitChange(fCu, newName) });
}
Also used : RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenameResourceDescriptor(org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)

Aggregations

DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)7 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)3 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)3 HashMap (java.util.HashMap)2 IResource (org.eclipse.core.resources.IResource)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)2 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)2 Change (org.eclipse.ltk.core.refactoring.Change)2 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1