Search in sources :

Example 11 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)

Example 12 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)

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