Search in sources :

Example 1 with ChangeMethodSignatureDescriptor

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

the class ChangeSignatureProcessor method createDescriptor.

public JavaRefactoringDescriptor createDescriptor() {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fMethod.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    ChangeMethodSignatureDescriptor descriptor = null;
    try {
        final String description = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
        final String header = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description, new String[] { getOldMethodSignature(), getNewMethodSignature() });
        final JDTRefactoringDescriptorComment comment = createComment(project, header);
        descriptor = RefactoringSignatureDescriptorFactory.createChangeMethodSignatureDescriptor(project, description, comment.asString(), arguments, getDescriptorFlags());
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fMethod));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fMethodName);
        arguments.put(ATTRIBUTE_DELEGATE, Boolean.valueOf(fDelegateUpdating).toString());
        arguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDelegateDeprecation).toString());
        if (fReturnTypeInfo.isTypeNameChanged())
            arguments.put(ATTRIBUTE_RETURN, fReturnTypeInfo.getNewTypeName());
        try {
            if (!isVisibilitySameAsInitial())
                arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
        } catch (JavaModelException exception) {
            JavaPlugin.log(exception);
        }
        int count = 1;
        for (final Iterator<ParameterInfo> iterator = fParameterInfos.iterator(); iterator.hasNext(); ) {
            final ParameterInfo info = iterator.next();
            final StringBuffer buffer = new StringBuffer(64);
            if (info.isAdded())
                //$NON-NLS-1$
                buffer.append("{added}");
            else
                buffer.append(info.getOldTypeName());
            //$NON-NLS-1$
            buffer.append(" ");
            if (info.isAdded())
                //$NON-NLS-1$
                buffer.append("{added}");
            else
                buffer.append(info.getOldName());
            //$NON-NLS-1$
            buffer.append(" ");
            buffer.append(info.getOldIndex());
            //$NON-NLS-1$
            buffer.append(" ");
            if (info.isDeleted())
                //$NON-NLS-1$
                buffer.append("{deleted}");
            else
                //$NON-NLS-1$//$NON-NLS-2$
                buffer.append(info.getNewTypeName().replaceAll(" ", ""));
            //$NON-NLS-1$
            buffer.append(" ");
            if (info.isDeleted())
                //$NON-NLS-1$
                buffer.append("{deleted}");
            else
                buffer.append(info.getNewName());
            //$NON-NLS-1$
            buffer.append(" ");
            buffer.append(info.isDeleted());
            arguments.put(ATTRIBUTE_PARAMETER + count, buffer.toString());
            final String value = info.getDefaultValue();
            if (//$NON-NLS-1$
            value != null && !"".equals(value))
                arguments.put(ATTRIBUTE_DEFAULT + count, value);
            count++;
        }
        count = 1;
        for (final Iterator<ExceptionInfo> iterator = fExceptionInfos.iterator(); iterator.hasNext(); ) {
            final ExceptionInfo info = iterator.next();
            arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count, JavaRefactoringDescriptorUtil.elementToHandle(project, info.getElement()));
            arguments.put(ATTRIBUTE_KIND + count, new Integer(info.getKind()).toString());
            count++;
        }
    } catch (JavaModelException exception) {
        JavaPlugin.log(exception);
        return null;
    }
    return descriptor;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) IJavaProject(org.eclipse.jdt.core.IJavaProject) ChangeMethodSignatureDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ChangeMethodSignatureDescriptor) ExceptionInfo(org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ChangeMethodSignatureDescriptor (org.eclipse.jdt.core.refactoring.descriptors.ChangeMethodSignatureDescriptor)1 ExceptionInfo (org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)1 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)1 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)1