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;" });
}
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" });
}
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;" });
}
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) });
}
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;
}
Aggregations