Search in sources :

Example 6 with JDTRefactoringDescriptorComment

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

the class InferTypeArgumentsRefactoring method createChange.

/*
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.InferTypeArgumentsRefactoring_name, fChangeManager.getAllChanges()) {

            @Override
            public final ChangeDescriptor getDescriptor() {
                final Map<String, String> arguments = new HashMap<String, String>();
                final IJavaProject project = getSingleProject();
                final String description = RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
                final String header = project != null ? Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description_project, BasicElementLabels.getJavaElementName(project.getElementName())) : RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
                final String name = project != null ? project.getElementName() : null;
                final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(name, this, header);
                final String[] settings = new String[fElements.length];
                for (int index = 0; index < settings.length; index++) settings[index] = JavaElementLabels.getTextLabel(fElements[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
                comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_original_elements, settings));
                if (fAssumeCloneReturnsSameType)
                    comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_assume_clone);
                if (fLeaveUnconstrainedRaw)
                    comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_leave_unconstrained);
                final InferTypeArgumentsDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInferTypeArgumentsDescriptor(name, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
                for (int index = 0; index < fElements.length; index++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(name, fElements[index]));
                arguments.put(ATTRIBUTE_CLONE, Boolean.valueOf(fAssumeCloneReturnsSameType).toString());
                arguments.put(ATTRIBUTE_LEAVE, Boolean.valueOf(fLeaveUnconstrainedRaw).toString());
                return new RefactoringChangeDescriptor(descriptor);
            }
        };
        return result;
    } finally {
        pm.done();
    }
}
Also used : InferTypeArgumentsDescriptor(org.eclipse.jdt.core.refactoring.descriptors.InferTypeArgumentsDescriptor) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 7 with JDTRefactoringDescriptorComment

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

Example 8 with JDTRefactoringDescriptorComment

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

the class SelfEncapsulateFieldRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fField.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final IType declaring = fField.getDeclaringType();
    try {
        if (declaring.isAnonymous() || declaring.isLocal())
            flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
    } catch (JavaModelException exception) {
        JavaPlugin.log(exception);
    }
    final String description = Messages.format(RefactoringCoreMessages.SelfEncapsulateField_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
    final String header = Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_getter_pattern, BasicElementLabels.getJavaElementName(fGetterName)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_setter_pattern, BasicElementLabels.getJavaElementName(fSetterName)));
    String visibility = JdtFlags.getVisibilityString(fVisibility);
    if (//$NON-NLS-1$
    "".equals(visibility))
        visibility = RefactoringCoreMessages.SelfEncapsulateField_default_visibility;
    comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_visibility_pattern, visibility));
    if (fEncapsulateDeclaringClass)
        comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_use_accessors);
    else
        comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_do_not_use_accessors);
    if (fGenerateJavadoc)
        comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_generate_comments);
    final EncapsulateFieldDescriptor descriptor = RefactoringSignatureDescriptorFactory.createEncapsulateFieldDescriptor(project, description, comment.asString(), arguments, flags);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fField));
    arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
    arguments.put(ATTRIBUTE_INSERTION, new Integer(fInsertionIndex).toString());
    arguments.put(ATTRIBUTE_SETTER, fSetterName);
    arguments.put(ATTRIBUTE_GETTER, fGetterName);
    arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());
    arguments.put(ATTRIBUTE_DECLARING, Boolean.valueOf(fEncapsulateDeclaringClass).toString());
    final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, getName());
    TextChange[] changes = fChangeManager.getAllChanges();
    pm.beginTask(NO_NAME, changes.length);
    pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_create_changes);
    for (int i = 0; i < changes.length; i++) {
        result.add(changes[i]);
        pm.worked(1);
    }
    pm.done();
    return result;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) EncapsulateFieldDescriptor(org.eclipse.jdt.core.refactoring.descriptors.EncapsulateFieldDescriptor) HashMap(java.util.HashMap) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IType(org.eclipse.jdt.core.IType) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 9 with JDTRefactoringDescriptorComment

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

the class ChangeSignatureProcessor method createComment.

private JDTRefactoringDescriptorComment createComment(String project, final String header) throws JavaModelException {
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    if (!fMethod.getElementName().equals(fMethodName))
        comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_name_pattern, BasicElementLabels.getJavaElementName(fMethodName)));
    if (!isVisibilitySameAsInitial()) {
        String visibility = JdtFlags.getVisibilityString(fVisibility);
        if (//$NON-NLS-1$
        "".equals(visibility))
            visibility = RefactoringCoreMessages.ChangeSignatureRefactoring_default_visibility;
        comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_visibility_pattern, visibility));
    }
    if (fReturnTypeInfo.isTypeNameChanged())
        comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_return_type_pattern, BasicElementLabels.getJavaElementName(fReturnTypeInfo.getNewTypeName())));
    List<String> deleted = new ArrayList<String>();
    List<String> added = new ArrayList<String>();
    List<String> changed = new ArrayList<String>();
    for (final Iterator<ParameterInfo> iterator = fParameterInfos.iterator(); iterator.hasNext(); ) {
        final ParameterInfo info = iterator.next();
        if (info.isDeleted())
            deleted.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_deleted_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getOldTypeName()), BasicElementLabels.getJavaElementName(info.getOldName()) }));
        else if (info.isAdded())
            added.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_added_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getNewTypeName()), BasicElementLabels.getJavaElementName(info.getNewName()) }));
        else if (info.isRenamed() || info.isTypeNameChanged() || info.isVarargChanged())
            changed.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_changed_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getOldTypeName()), BasicElementLabels.getJavaElementName(info.getOldName()) }));
    }
    if (!added.isEmpty())
        comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_added_parameters, added.toArray(new String[added.size()])));
    if (!deleted.isEmpty())
        comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_removed_parameters, deleted.toArray(new String[deleted.size()])));
    if (!changed.isEmpty())
        comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_changed_parameters, changed.toArray(new String[changed.size()])));
    added.clear();
    deleted.clear();
    changed.clear();
    for (final Iterator<ExceptionInfo> iterator = fExceptionInfos.iterator(); iterator.hasNext(); ) {
        final ExceptionInfo info = iterator.next();
        if (info.isAdded())
            added.add(info.getElement().getElementName());
        else if (info.isDeleted())
            deleted.add(info.getElement().getElementName());
    }
    if (!added.isEmpty())
        comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_added_exceptions, added.toArray(new String[added.size()])));
    if (!deleted.isEmpty())
        comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_removed_exceptions, deleted.toArray(new String[deleted.size()])));
    return comment;
}
Also used : ArrayList(java.util.ArrayList) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) ExceptionInfo(org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 10 with JDTRefactoringDescriptorComment

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

the class ConvertAnonymousToNestedRefactoring method createRefactoringDescriptor.

private RefactoringChangeDescriptor createRefactoringDescriptor() {
    final ITypeBinding binding = fAnonymousInnerClassNode.resolveBinding();
    final String[] labels = new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED) };
    final Map<String, String> arguments = new HashMap<String, String>();
    final String projectName = fCu.getJavaProject().getElementName();
    final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
    final String description = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description_short;
    final String header = Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description, labels);
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(projectName, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_class_name_pattern, BasicElementLabels.getJavaElementName(fClassName)));
    String visibility = JdtFlags.getVisibilityString(fVisibility);
    if (visibility.length() == 0)
        visibility = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_default_visibility;
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_visibility_pattern, visibility));
    if (fDeclareFinal && fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final_static);
    else if (fDeclareFinal)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final);
    else if (fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_static);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(projectName, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fClassName);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + ' ' + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
    arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
    ConvertAnonymousDescriptor descriptor = RefactoringSignatureDescriptorFactory.createConvertAnonymousDescriptor(projectName, description, comment.asString(), arguments, flags);
    return new RefactoringChangeDescriptor(descriptor);
}
Also used : ConvertAnonymousDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ConvertAnonymousDescriptor) HashMap(java.util.HashMap) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Aggregations

JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)23 IJavaProject (org.eclipse.jdt.core.IJavaProject)20 HashMap (java.util.HashMap)14 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)10 JavaModelException (org.eclipse.jdt.core.JavaModelException)8 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)8 IType (org.eclipse.jdt.core.IType)5 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)5 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)4 TextChange (org.eclipse.ltk.core.refactoring.TextChange)4 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)3 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)2 ExceptionInfo (org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)2 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)2