Search in sources :

Example 6 with DynamicValidationRefactoringChange

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

the class ReplaceInvocationsRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    // TODO: update for fSelectionStart == -1
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fSelectionTypeRoot.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final IMethodBinding binding = fSourceProvider.getDeclaration().resolveBinding();
    int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
    if (!Modifier.isPrivate(binding.getModifiers()))
        flags |= RefactoringDescriptor.MULTI_CHANGE;
    final String description = Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
    final String header = Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringClass(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    if (!fTargetProvider.isSingle())
        comment.addSetting(RefactoringCoreMessages.ReplaceInvocationsRefactoring_replace_references);
    //REVIEW Unregistered ID!
    final JavaRefactoringDescriptor descriptor = new JavaRefactoringDescriptor(ID_REPLACE_INVOCATIONS, project, description, comment.asString(), arguments, flags) {
    };
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionTypeRoot));
    //$NON-NLS-1$
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_MODE, new Integer(fTargetProvider.isSingle() ? 0 : 1).toString());
    return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ReplaceInvocationsRefactoring_change_name, fChangeManager.getAllChanges());
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 7 with DynamicValidationRefactoringChange

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

Example 8 with DynamicValidationRefactoringChange

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

the class RenameFieldProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
        TextChange[] changes = fChangeManager.getAllChanges();
        RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
        return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
    } finally {
        monitor.done();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 9 with DynamicValidationRefactoringChange

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

the class RenamePackageProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
        final RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
        final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
        result.addAll(fChangeManager.getAllChanges());
        fRenamePackageChange = new RenamePackageChange(fPackage, getNewElementName(), fRenameSubpackages);
        result.add(fRenamePackageChange);
        monitor.worked(1);
        return result;
    } finally {
        fChangeManager = null;
        fImportsManager = null;
        monitor.done();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 10 with DynamicValidationRefactoringChange

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

the class RenameTypeParameterProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    Assert.isNotNull(monitor);
    try {
        Change change = fChange;
        if (change != null) {
            String project = null;
            IJavaProject javaProject = fTypeParameter.getJavaProject();
            if (javaProject != null)
                project = javaProject.getElementName();
            String description = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()));
            String header = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) });
            String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
            RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER);
            descriptor.setProject(project);
            descriptor.setDescription(description);
            descriptor.setComment(comment);
            descriptor.setFlags(RefactoringDescriptor.NONE);
            descriptor.setJavaElement(fTypeParameter);
            descriptor.setNewName(getNewElementName());
            descriptor.setUpdateReferences(fUpdateReferences);
            change = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change });
        }
        return change;
    } finally {
        fChange = null;
        monitor.done();
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)12 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)9 HashMap (java.util.HashMap)6 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)5 TextChange (org.eclipse.ltk.core.refactoring.TextChange)5 IType (org.eclipse.jdt.core.IType)3 IResource (org.eclipse.core.resources.IResource)2 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)2 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)2 Change (org.eclipse.ltk.core.refactoring.Change)2 RenameResourceChange (org.eclipse.ltk.core.refactoring.resource.RenameResourceChange)2 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1