Search in sources :

Example 1 with IntroduceIndirectionDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.IntroduceIndirectionDescriptor in project che by eclipse.

the class IntroduceIndirectionRefactoring method createChange.

// ******************** CHANGE CREATION ***********************
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fTargetMethod.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final IType declaring = fTargetMethod.getDeclaringType();
    try {
        if (declaring.isLocal() || declaring.isAnonymous())
            flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
    } catch (JavaModelException exception) {
        JavaPlugin.log(exception);
    }
    final String description = Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fTargetMethod.getElementName()));
    final String header = Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description, new String[] { JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_original_pattern, JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_method_pattern, BasicElementLabels.getJavaElementName(fIntermediaryMethodName)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_declaring_pattern, JavaElementLabels.getTextLabel(fIntermediaryType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    if (fUpdateReferences)
        comment.addSetting(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references);
    final IntroduceIndirectionDescriptor descriptor = RefactoringSignatureDescriptorFactory.createIntroduceIndirectionDescriptor(project, description, comment.asString(), arguments, flags);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fTargetMethod));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fIntermediaryMethodName);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1, JavaRefactoringDescriptorUtil.elementToHandle(project, fIntermediaryType));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES, Boolean.valueOf(fUpdateReferences).toString());
    return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.IntroduceIndirectionRefactoring_introduce_indirection, fTextChangeManager.getAllChanges());
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IntroduceIndirectionDescriptor(org.eclipse.jdt.core.refactoring.descriptors.IntroduceIndirectionDescriptor) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) IType(org.eclipse.jdt.core.IType) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

HashMap (java.util.HashMap)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IntroduceIndirectionDescriptor (org.eclipse.jdt.core.refactoring.descriptors.IntroduceIndirectionDescriptor)1 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)1 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)1