Search in sources :

Example 1 with ConvertLocalVariableDescriptor

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

the class PromoteTempToFieldRefactoring method getRefactoringDescriptor.

private ConvertLocalVariableDescriptor getRefactoringDescriptor() {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final IVariableBinding binding = fTempDeclarationNode.resolveBinding();
    final String description = Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
    final String header = Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_field_pattern, BasicElementLabels.getJavaElementName(fFieldName)));
    switch(fInitializeIn) {
        case INITIALIZE_IN_CONSTRUCTOR:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_constructor);
            break;
        case INITIALIZE_IN_FIELD:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_declaration);
            break;
        case INITIALIZE_IN_METHOD:
            comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_initialize_method);
            break;
    }
    String visibility = JdtFlags.getVisibilityString(fVisibility);
    if (//$NON-NLS-1$
    "".equals(visibility))
        visibility = RefactoringCoreMessages.PromoteTempToFieldRefactoring_default_visibility;
    comment.addSetting(Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_visibility_pattern, visibility));
    if (fDeclareFinal && fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final_static);
    else if (fDeclareFinal)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_final);
    else if (fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.PromoteTempToFieldRefactoring_declare_static);
    final ConvertLocalVariableDescriptor descriptor = RefactoringSignatureDescriptorFactory.createConvertLocalVariableDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fFieldName);
    //$NON-NLS-1$
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
    arguments.put(ATTRIBUTE_INITIALIZE, new Integer(fInitializeIn).toString());
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ConvertLocalVariableDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ConvertLocalVariableDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

HashMap (java.util.HashMap)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)1 ConvertLocalVariableDescriptor (org.eclipse.jdt.core.refactoring.descriptors.ConvertLocalVariableDescriptor)1 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)1