Search in sources :

Example 1 with INameUpdating

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

the class RenameTypeTest method helperWithTextual.

private String[] helperWithTextual(String oldCuName, String oldName, String newName, String newCUName, boolean updateReferences, boolean updateTextualMatches) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName);
    IType classA = getType(cu, oldName);
    IJavaElement[] classAMembers = classA.getChildren();
    IPackageFragment pack = (IPackageFragment) cu.getParent();
    String[] renameHandles = null;
    if (classA.getDeclaringType() == null && cu.getElementName().startsWith(classA.getElementName())) {
        renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource());
    } else {
        renameHandles = ParticipantTesting.createHandles(classA);
    }
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setUpdateTextualOccurrences(updateTextualMatches);
    Refactoring refactoring = createRefactoring(descriptor);
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java");
    TestCase.assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists());
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newCUName)), newcu.getSource());
    INameUpdating nameUpdating = ((INameUpdating) refactoring.getAdapter(INameUpdating.class));
    IType newElement = (IType) nameUpdating.getNewElement();
    TestCase.assertTrue("new element does not exist:\n" + newElement.toString(), newElement.exists());
    checkMappers(refactoring, classA, newCUName + ".java", classAMembers);
    return renameHandles;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) INameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IType(org.eclipse.jdt.core.IType)

Example 2 with INameUpdating

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

the class RenameSession method validateNewName.

public RefactoringStatus validateNewName(String newName) {
    INameUpdating updating = getNameUpdating();
    updating.setNewElementName(newName);
    try {
        return updating.checkNewElementName(newName);
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return RefactoringStatus.createFatalErrorStatus("An unexpected exception occurred. See the error log for more details.");
    }
}
Also used : INameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with INameUpdating

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

the class JDTRefactoringDescriptorComment method initializeInferredSettings.

/**
	 * Initializes the inferred settings.
	 *
	 * @param object
	 *            the refactoring object
	 */
private void initializeInferredSettings(final Object object) {
    if (object instanceof INameUpdating) {
        final INameUpdating updating = (INameUpdating) object;
        fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(updating.getElements()[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
        try {
            final Object element = updating.getNewElement();
            if (element != null)
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED)));
            else {
                final String newLabel = BasicElementLabels.getJavaElementName(updating.getCurrentElementName());
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, newLabel));
            }
        } catch (CoreException exception) {
            JavaPlugin.log(exception);
        }
    } else if (object instanceof RefactoringProcessor) {
        final RefactoringProcessor processor = (RefactoringProcessor) object;
        final Object[] elements = processor.getElements();
        if (elements != null) {
            if (elements.length == 1 && elements[0] != null)
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
            else if (elements.length > 1) {
                final StringBuffer buffer = new StringBuffer(128);
                buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
                for (int index = 0; index < elements.length; index++) {
                    if (elements[index] != null) {
                        buffer.append(LINE_DELIMITER);
                        buffer.append(ELEMENT_DELIMITER);
                        buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
                    } else {
                        buffer.append(LINE_DELIMITER);
                        buffer.append(ELEMENT_DELIMITER);
                        buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
                    }
                }
                fSettings.add(buffer.toString());
            }
        }
    } else if (object instanceof IReorgPolicy) {
        final IReorgPolicy policy = (IReorgPolicy) object;
        Object destination = policy.getJavaElementDestination();
        if (destination != null)
            fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        else {
            destination = policy.getResourceDestination();
            if (destination != null)
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        }
        final List<IAdaptable> list = new ArrayList<IAdaptable>();
        list.addAll(Arrays.asList(policy.getJavaElements()));
        list.addAll(Arrays.asList(policy.getResources()));
        final Object[] elements = list.toArray();
        if (elements != null) {
            if (elements.length == 1 && elements[0] != null)
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
            else if (elements.length > 1) {
                final StringBuffer buffer = new StringBuffer(128);
                buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
                for (int index = 0; index < elements.length; index++) {
                    if (elements[index] != null) {
                        buffer.append(LINE_DELIMITER);
                        buffer.append(ELEMENT_DELIMITER);
                        buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
                    } else {
                        buffer.append(LINE_DELIMITER);
                        buffer.append(ELEMENT_DELIMITER);
                        buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
                    }
                }
                fSettings.add(buffer.toString());
            }
        }
        if (object instanceof IMovePolicy) {
            final IMovePolicy extended = (IMovePolicy) object;
            if (extended.isTextualMove())
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptorComment_textual_move_only);
        }
    }
    if (object instanceof IReferenceUpdating) {
        final IReferenceUpdating updating = (IReferenceUpdating) object;
        if (updating.getUpdateReferences())
            fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references);
    }
    if (object instanceof ISimilarDeclarationUpdating) {
        final ISimilarDeclarationUpdating updating = (ISimilarDeclarationUpdating) object;
        if (updating.canEnableSimilarDeclarationUpdating() && updating.getUpdateSimilarDeclarations()) {
            final int strategy = updating.getMatchStrategy();
            if (strategy == RenamingNameSuggestor.STRATEGY_EXACT)
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar);
            else if (strategy == RenamingNameSuggestor.STRATEGY_EMBEDDED)
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_embedded);
            else if (strategy == RenamingNameSuggestor.STRATEGY_SUFFIX)
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_suffix);
        }
    }
    if (object instanceof IQualifiedNameUpdating) {
        final IQualifiedNameUpdating updating = (IQualifiedNameUpdating) object;
        if (updating.canEnableQualifiedNameUpdating() && updating.getUpdateQualifiedNames()) {
            final String patterns = updating.getFilePatterns();
            if (//$NON-NLS-1$
            patterns != null && !"".equals(patterns))
                fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names_pattern, BasicElementLabels.getFilePattern(patterns.trim())));
            else
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names);
        }
    }
    if (object instanceof ITextUpdating) {
        final ITextUpdating updating = (ITextUpdating) object;
        if (updating.canEnableTextUpdating())
            fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_textual_occurrences);
    }
    if (object instanceof IDelegateUpdating) {
        final IDelegateUpdating updating = (IDelegateUpdating) object;
        if (updating.canEnableDelegateUpdating() && updating.getDelegateUpdating()) {
            if (updating.getDeprecateDelegates())
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original_deprecated);
            else
                fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original);
        }
    }
}
Also used : IMovePolicy(org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.IMovePolicy) IAdaptable(org.eclipse.core.runtime.IAdaptable) INameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating) ArrayList(java.util.ArrayList) IQualifiedNameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.IQualifiedNameUpdating) IReferenceUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating) IDelegateUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.IDelegateUpdating) IReorgPolicy(org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy) CoreException(org.eclipse.core.runtime.CoreException) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) ISimilarDeclarationUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.ISimilarDeclarationUpdating) ITextUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating)

Aggregations

INameUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating)3 CoreException (org.eclipse.core.runtime.CoreException)2 ArrayList (java.util.ArrayList)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IType (org.eclipse.jdt.core.IType)1 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)1 IReorgPolicy (org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy)1 IMovePolicy (org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.IMovePolicy)1 IDelegateUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.IDelegateUpdating)1 IQualifiedNameUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.IQualifiedNameUpdating)1 IReferenceUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating)1 ISimilarDeclarationUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.ISimilarDeclarationUpdating)1 ITextUpdating (org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating)1 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)1 RefactoringProcessor (org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1