Search in sources :

Example 1 with ExtractLocalDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor in project eclipse.jdt.ls by eclipse.

the class ExtractTempRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.ExtractTempRefactoring_checking_preconditions, 1);
        ExtractLocalDescriptor descriptor = createRefactoringDescriptor();
        fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return fChange;
    } finally {
        pm.done();
    }
}
Also used : ExtractLocalDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 2 with ExtractLocalDescriptor

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

the class ExtractTempRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.ExtractTempRefactoring_checking_preconditions, 1);
        ExtractLocalDescriptor descriptor = createRefactoringDescriptor();
        fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return fChange;
    } finally {
        pm.done();
    }
}
Also used : ExtractLocalDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 3 with ExtractLocalDescriptor

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

the class ExtractTempRefactoring method createRefactoringDescriptor.

private final ExtractLocalDescriptor createRefactoringDescriptor() {
    final Map<String, String> arguments = new HashMap<String, String>();
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final String description = Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fTempName));
    final String expression = ASTNodes.asString(fSelectedExpression.getAssociatedExpression());
    final String header = Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTempName), BasicElementLabels.getJavaCodeString(expression) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_name_pattern, BasicElementLabels.getJavaElementName(fTempName)));
    final BodyDeclaration decl = (BodyDeclaration) ASTNodes.getParent(fSelectedExpression.getAssociatedExpression(), BodyDeclaration.class);
    if (decl instanceof MethodDeclaration) {
        final IMethodBinding method = ((MethodDeclaration) decl).resolveBinding();
        final String label = method != null ? BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED) : BasicElementLabels.getJavaElementName('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
        comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_destination_pattern, label));
    }
    comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_expression_pattern, BasicElementLabels.getJavaCodeString(expression)));
    if (fReplaceAllOccurrences)
        comment.addSetting(RefactoringCoreMessages.ExtractTempRefactoring_replace_occurrences);
    if (fDeclareFinal)
        comment.addSetting(RefactoringCoreMessages.ExtractTempRefactoring_declare_final);
    final ExtractLocalDescriptor descriptor = RefactoringSignatureDescriptorFactory.createExtractLocalDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.NONE);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fTempName);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, //$NON-NLS-1$
    new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllOccurrences).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    return descriptor;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ExtractLocalDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 4 with ExtractLocalDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor in project eclipse.jdt.ls by eclipse.

the class ExtractTempRefactoring method createRefactoringDescriptor.

private final ExtractLocalDescriptor createRefactoringDescriptor() {
    final Map<String, String> arguments = new HashMap<>();
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null) {
        project = javaProject.getElementName();
    }
    final String description = Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fTempName));
    final String expression = ASTNodes.asString(fSelectedExpression.getAssociatedExpression());
    final String header = Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTempName), BasicElementLabels.getJavaCodeString(expression) });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_name_pattern, BasicElementLabels.getJavaElementName(fTempName)));
    final BodyDeclaration decl = (BodyDeclaration) ASTNodes.getParent(fSelectedExpression.getAssociatedExpression(), BodyDeclaration.class);
    if (decl instanceof MethodDeclaration) {
        final IMethodBinding method = ((MethodDeclaration) decl).resolveBinding();
        final String label = method != null ? BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED) : BasicElementLabels.getJavaElementName('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
        comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_destination_pattern, label));
    }
    comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_expression_pattern, BasicElementLabels.getJavaCodeString(expression)));
    if (fReplaceAllOccurrences) {
        comment.addSetting(RefactoringCoreMessages.ExtractTempRefactoring_replace_occurrences);
    }
    if (fDeclareFinal) {
        comment.addSetting(RefactoringCoreMessages.ExtractTempRefactoring_declare_final);
    }
    final ExtractLocalDescriptor descriptor = RefactoringSignatureDescriptorFactory.createExtractLocalDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.NONE);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fTempName);
    // $NON-NLS-1$
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllOccurrences).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    return descriptor;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ExtractLocalDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) JDTRefactoringDescriptorComment(org.eclipse.jdt.ls.core.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

ExtractLocalDescriptor (org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor)4 HashMap (java.util.HashMap)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)2 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)1 JDTRefactoringDescriptorComment (org.eclipse.jdt.ls.core.internal.corext.refactoring.JDTRefactoringDescriptorComment)1