Search in sources :

Example 21 with RenameJavaElementDescriptor

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

the class RenameLinkedModeRefactoringSession method createRenameDescriptor.

/**
     * Creates a rename descriptor.
     *
     * @param javaElement element to rename
     * @param newName new name
     * @return a rename descriptor with current settings as used in the refactoring dialogs
     * @throws JavaModelException if an error occurs while accessing the element
     */
private RenameJavaElementDescriptor createRenameDescriptor(IJavaElement javaElement, String newName) throws JavaModelException {
    String contributionId;
    // see RefactoringExecutionStarter#createRenameSupport(..):
    int elementType = javaElement.getElementType();
    switch(elementType) {
        case IJavaElement.JAVA_PROJECT:
            contributionId = IJavaRefactorings.RENAME_JAVA_PROJECT;
            break;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            contributionId = IJavaRefactorings.RENAME_SOURCE_FOLDER;
            break;
        case IJavaElement.PACKAGE_FRAGMENT:
            contributionId = IJavaRefactorings.RENAME_PACKAGE;
            break;
        case IJavaElement.COMPILATION_UNIT:
            contributionId = IJavaRefactorings.RENAME_COMPILATION_UNIT;
            break;
        case IJavaElement.TYPE:
            contributionId = IJavaRefactorings.RENAME_TYPE;
            break;
        case IJavaElement.METHOD:
            final IMethod method = (IMethod) javaElement;
            if (method.isConstructor())
                return createRenameDescriptor(method.getDeclaringType(), newName);
            else
                contributionId = IJavaRefactorings.RENAME_METHOD;
            break;
        case IJavaElement.FIELD:
            IField field = (IField) javaElement;
            if (field.isEnumConstant())
                contributionId = IJavaRefactorings.RENAME_ENUM_CONSTANT;
            else
                contributionId = IJavaRefactorings.RENAME_FIELD;
            break;
        case IJavaElement.TYPE_PARAMETER:
            contributionId = IJavaRefactorings.RENAME_TYPE_PARAMETER;
            break;
        case IJavaElement.LOCAL_VARIABLE:
            contributionId = IJavaRefactorings.RENAME_LOCAL_VARIABLE;
            break;
        default:
            return null;
    }
    RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) RefactoringCore.getRefactoringContribution(contributionId).createDescriptor();
    descriptor.setJavaElement(javaElement);
    descriptor.setNewName(newName);
    if (elementType != IJavaElement.PACKAGE_FRAGMENT_ROOT)
        descriptor.setUpdateReferences(true);
    switch(elementType) {
        case IJavaElement.METHOD:
        case IJavaElement.FIELD:
            descriptor.setDeprecateDelegate(/*refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_DEPRECATION)*/
            false);
            descriptor.setKeepOriginal(/*refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_UPDATING)*/
            false);
    }
    switch(elementType) {
        case IJavaElement.TYPE:
            //			case IJavaElement.COMPILATION_UNIT: // TODO
            descriptor.setUpdateSimilarDeclarations(/*refactoringSettings.getBoolean(RenameRefactoringWizard.TYPE_UPDATE_SIMILAR_ELEMENTS)*/
            false);
            int strategy;
            try {
                //refactoringSettings.getInt(RenameRefactoringWizard.TYPE_SIMILAR_MATCH_STRATEGY);
                strategy = 1;
            } catch (NumberFormatException e) {
                strategy = RenamingNameSuggestor.STRATEGY_EXACT;
            }
            descriptor.setMatchStrategy(strategy);
    }
    switch(elementType) {
        case IJavaElement.PACKAGE_FRAGMENT:
            descriptor.setUpdateHierarchy(/*refactoringSettings.getBoolean(RenameRefactoringWizard.PACKAGE_RENAME_SUBPACKAGES)*/
            true);
    }
    switch(elementType) {
        case IJavaElement.PACKAGE_FRAGMENT:
        case IJavaElement.TYPE:
            String fileNamePatterns = /*refactoringSettings.get(RenameRefactoringWizard.QUALIFIED_NAMES_PATTERNS)*/
            "*";
            if (fileNamePatterns != null && fileNamePatterns.length() != 0) {
                descriptor.setFileNamePatterns(fileNamePatterns);
                boolean updateQualifiedNames = /*refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES)*/
                false;
                descriptor.setUpdateQualifiedNames(updateQualifiedNames);
            //                    fShowPreview|= updateQualifiedNames;
            }
    }
    switch(elementType) {
        case IJavaElement.PACKAGE_FRAGMENT:
        case IJavaElement.TYPE:
        case IJavaElement.FIELD:
            //refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES);
            boolean updateTextualOccurrences = false;
            descriptor.setUpdateTextualOccurrences(updateTextualOccurrences);
    }
    switch(elementType) {
        case IJavaElement.FIELD:
            descriptor.setRenameGetters(/*refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_GETTER)*/
            false);
            descriptor.setRenameSetters(/*refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_SETTER)*/
            false);
    }
    return descriptor;
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 22 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor 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 23 with RenameJavaElementDescriptor

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

the class RenameFieldProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
        TextChange[] changes = fChangeManager.getAllChanges();
        RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
        return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
    } finally {
        monitor.done();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 24 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor 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)

Example 25 with RenameJavaElementDescriptor

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

the class RenameLocalVariableProcessor method createChange.

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

Aggregations

RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)40 IType (org.eclipse.jdt.core.IType)24 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)21 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)18 IMethod (org.eclipse.jdt.core.IMethod)12 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)11 Test (org.junit.Test)10 IField (org.eclipse.jdt.core.IField)9 ArrayList (java.util.ArrayList)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)8 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)8 List (java.util.List)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)6 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)6 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3