Search in sources :

Example 56 with RenameJavaElementDescriptor

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

the class BinaryReferencesTests method testRenameType01.

@Test
public void testRenameType01() throws Exception {
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
    descriptor.setJavaElement(findType("source.BaseClass"));
    descriptor.setNewName("RenamedBaseClass");
    descriptor.setUpdateReferences(true);
    List<SearchMatch> matches = doRefactoring(descriptor);
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(SubClass.class[SubClass", "=BinaryReference/binary<ref(SubClass.class[SubClass", "=BinaryReference/binary<ref(SubClass.class[SubClass~compareTo~Lsource.BaseClass;" });
}
Also used : SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 57 with RenameJavaElementDescriptor

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

the class BinaryReferencesTests method testRenamePackage02.

@Test
public void testRenamePackage02() throws Exception {
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    IPackageFragment pack = findType("source.BaseClass").getPackageFragment();
    descriptor.setJavaElement(pack);
    descriptor.setNewName("newName");
    descriptor.setUpdateReferences(true);
    descriptor.setUpdateHierarchy(true);
    RefactoringStatus status = new RefactoringStatus();
    Refactoring refactoring = descriptor.createRefactoring(status);
    assertTrue(status.isOK());
    CheckConditionsOperation op = new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
    op.run(null);
    RefactoringStatus validationStatus = op.getStatus();
    assertFalse(validationStatus.hasFatalError());
    assertTrue(validationStatus.hasError());
    assertEquals(2, validationStatus.getEntries().length);
    ReferencesInBinaryContext context = (ReferencesInBinaryContext) validationStatus.getEntryAt(0).getContext();
    List<SearchMatch> matches = context.getMatches();
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(SubClass.class[SubClass", "=BinaryReference/binary<ref(SubClass.class[SubClass" });
    context = (ReferencesInBinaryContext) validationStatus.getEntryAt(1).getContext();
    matches = context.getMatches();
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass~main~\\[Ljava.lang.String;", "=BinaryReference/binary<ref(SubClass.class[SubClass" });
}
Also used : ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) InlineMethodRefactoring(org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring) MoveRefactoring(org.eclipse.ltk.core.refactoring.participants.MoveRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) Test(org.junit.Test)

Example 58 with RenameJavaElementDescriptor

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

the class BinaryReferencesTests method testRenameType02.

@Test
public void testRenameType02() throws Exception {
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
    descriptor.setJavaElement(findType("source.Color"));
    descriptor.setNewName("Colour");
    descriptor.setUpdateSimilarDeclarations(true);
    descriptor.setMatchStrategy(RenameJavaElementDescriptor.STRATEGY_SUFFIX);
    descriptor.setUpdateReferences(true);
    RefactoringStatus status = new RefactoringStatus();
    Refactoring refactoring = descriptor.createRefactoring(status);
    assertTrue(status.isOK());
    CheckConditionsOperation op = new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
    op.run(null);
    RefactoringStatus validationStatus = op.getStatus();
    assertFalse(validationStatus.hasFatalError());
    assertTrue(validationStatus.hasError());
    assertEquals(2, validationStatus.getEntries().length);
    ReferencesInBinaryContext context = (ReferencesInBinaryContext) validationStatus.getEntryAt(0).getContext();
    List<SearchMatch> matches = context.getMatches();
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(SubClass.class[SubClass", "=BinaryReference/binary<ref(SubClass.class[SubClass~paintColor~Lsource.Color;" });
    context = (ReferencesInBinaryContext) validationStatus.getEntryAt(1).getContext();
    matches = context.getMatches();
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass~main~\\[Ljava.lang.String;" });
}
Also used : ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) InlineMethodRefactoring(org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring) MoveRefactoring(org.eclipse.ltk.core.refactoring.participants.MoveRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) Test(org.junit.Test)

Example 59 with RenameJavaElementDescriptor

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

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 60 with RenameJavaElementDescriptor

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

the class RenamePackageProcessor method createRefactoringDescriptor.

private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project = null;
    IJavaProject javaProject = fPackage.getJavaProject();
    if (javaProject != null)
        project = javaProject.getElementName();
    final int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final String description = Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
    final String header = Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName() });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    if (fRenameSubpackages)
        comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment.asString());
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fPackage);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
    if (// $NON-NLS-1$
    fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns))
        descriptor.setFileNamePatterns(fFilePatterns);
    descriptor.setUpdateHierarchy(fRenameSubpackages);
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Aggregations

RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)120 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 IType (org.eclipse.jdt.core.IType)55 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)55 Test (org.junit.Test)33 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)29 IMethod (org.eclipse.jdt.core.IMethod)28 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)26 IJavaProject (org.eclipse.jdt.core.IJavaProject)25 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)25 IField (org.eclipse.jdt.core.IField)24 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)21 ArrayList (java.util.ArrayList)19 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)19 JavaModelException (org.eclipse.jdt.core.JavaModelException)15 IPath (org.eclipse.core.runtime.IPath)12 TextChange (org.eclipse.ltk.core.refactoring.TextChange)10 IFile (org.eclipse.core.resources.IFile)9