Search in sources :

Example 16 with JDTRefactoringDescriptorComment

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

the class InlineTempRefactoring method createChange.

//----- changes
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.InlineTempRefactoring_preview, 2);
        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 = getVariableDeclaration().resolveBinding();
        String text = null;
        final IMethodBinding method = binding.getDeclaringMethod();
        if (method != null)
            text = BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED);
        else
            text = BasicElementLabels.getJavaElementName('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
        final String description = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
        final String header = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), text });
        final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
        comment.addSetting(Messages.format(RefactoringCoreMessages.InlineTempRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        final InlineLocalVariableDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInlineLocalVariableDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.NONE);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, String.valueOf(fSelectionStart) + ' ' + String.valueOf(fSelectionLength));
        CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite(fCu, fASTRoot);
        inlineTemp(cuRewrite);
        removeTemp(cuRewrite);
        final CompilationUnitChange result = cuRewrite.createChange(RefactoringCoreMessages.InlineTempRefactoring_inline, false, new SubProgressMonitor(pm, 1));
        result.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return result;
    } finally {
        pm.done();
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) InlineLocalVariableDescriptor(org.eclipse.jdt.core.refactoring.descriptors.InlineLocalVariableDescriptor) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 17 with JDTRefactoringDescriptorComment

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

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

the class InlineConstantRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.InlineConstantRefactoring_preview, 2);
        final Map<String, String> arguments = new HashMap<String, String>();
        String project = null;
        IJavaProject javaProject = fSelectionCu.getJavaProject();
        if (javaProject != null)
            project = javaProject.getElementName();
        int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
        try {
            if (!Flags.isPrivate(fField.getFlags()))
                flags |= RefactoringDescriptor.MULTI_CHANGE;
        } catch (JavaModelException exception) {
            JavaPlugin.log(exception);
        }
        final String description = Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description_short, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_DEFAULT));
        final String header = Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
        final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
        comment.addSetting(Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        if (fRemoveDeclaration)
            comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_remove_declaration);
        if (fReplaceAllReferences)
            comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_replace_references);
        final InlineConstantDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInlineConstantDescriptor(project, description, comment.asString(), arguments, flags);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionCu));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, //$NON-NLS-1$
        new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
        arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemoveDeclaration).toString());
        arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllReferences).toString());
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.InlineConstantRefactoring_inline, fChanges);
    } finally {
        pm.done();
        fChanges = null;
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) InlineConstantDescriptor(org.eclipse.jdt.core.refactoring.descriptors.InlineConstantDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 19 with JDTRefactoringDescriptorComment

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

the class RenameCompilationUnitProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    // renaming the file is taken care of in renameTypeRefactoring
    if (fWillRenameType)
        return fRenameTypeProcessor.createChange(pm);
    fRenameTypeProcessor = null;
    final String newName = getNewElementName();
    final IResource resource = fCu.getResource();
    if (resource != null && resource.isLinked()) {
        final IProject project = resource.getProject();
        final String name = project.getName();
        final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getResourceName(resource.getName()));
        final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getResourceName(resource.getName()) });
        final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
        final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
        final RenameResourceDescriptor descriptor = (RenameResourceDescriptor) RefactoringCore.getRefactoringContribution(RenameResourceDescriptor.ID).createDescriptor();
        descriptor.setProject(name);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(flags);
        descriptor.setResourcePath(resource.getFullPath());
        descriptor.setNewName(newName);
        RenameResourceChange resourceChange = new RenameResourceChange(resource.getFullPath(), newName);
        resourceChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return new DynamicValidationStateChange(resourceChange);
    }
    String label = JavaElementLabels.getTextLabel(fCu, JavaElementLabels.ALL_FULLY_QUALIFIED);
    final String name = fCu.getJavaProject().getElementName();
    final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getFileName(fCu));
    final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { label, BasicElementLabels.getResourceName(newName) });
    final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
    final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_COMPILATION_UNIT);
    descriptor.setProject(name);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fCu);
    descriptor.setNewName(newName);
    return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameCompilationUnitRefactoring_name, new Change[] { new RenameCompilationUnitChange(fCu, newName) });
}
Also used : RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenameResourceDescriptor(org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)

Example 20 with JDTRefactoringDescriptorComment

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

the class RenameFieldProcessor method createRefactoringDescriptor.

/**
	 * Overridden by subclasses.
	 * @return return the refactoring descriptor for this refactoring
	 */
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project = null;
    IJavaProject javaProject = fField.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
    try {
        if (!Flags.isPrivate(fField.getFlags()))
            flags |= RefactoringDescriptor.MULTI_CHANGE;
    } catch (JavaModelException exception) {
        JavaPlugin.log(exception);
    }
    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.RenameFieldRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
    final String header = Messages.format(RefactoringCoreMessages.RenameFieldProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fField.getElementName()), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementName() });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    if (fRenameGetter)
        comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_getter);
    if (fRenameSetter)
        comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_settter);
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment.asString());
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fField);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    descriptor.setRenameGetters(fRenameGetter);
    descriptor.setRenameSetters(fRenameSetter);
    descriptor.setKeepOriginal(fDelegateUpdating);
    descriptor.setDeprecateDelegate(fDelegateDeprecation);
    return descriptor;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

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