use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenamePackageProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
final RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
result.addAll(fChangeManager.getAllChanges());
fRenamePackageChange = new RenamePackageChange(fPackage, getNewElementName(), fRenameSubpackages);
result.add(fRenamePackageChange);
monitor.worked(1);
return result;
} finally {
fChangeManager = null;
fImportsManager = null;
monitor.done();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeParameterProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
Assert.isNotNull(monitor);
try {
Change change = fChange;
if (change != null) {
String project = null;
IJavaProject javaProject = fTypeParameter.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
String description = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()));
String header = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) });
String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(RefactoringDescriptor.NONE);
descriptor.setJavaElement(fTypeParameter);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
change = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change });
}
return change;
} finally {
fChange = null;
monitor.done();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenamePrivateFieldTest method helper2.
private void helper2(String fieldName, String newFieldName, boolean updateReferences, boolean updateTextualMatches, boolean renameGetter, boolean renameSetter, boolean expectedGetterRenameEnabled, boolean expectedSetterRenameEnabled) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType classA = getType(cu, "A");
IField field = classA.getField(fieldName);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
descriptor.setJavaElement(field);
descriptor.setNewName(newFieldName);
descriptor.setUpdateReferences(updateReferences);
descriptor.setUpdateTextualOccurrences(updateTextualMatches);
descriptor.setRenameGetters(renameGetter);
descriptor.setRenameSetters(renameSetter);
RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
assertEquals("getter rename enabled", expectedGetterRenameEnabled, processor.canEnableGetterRenaming() == null);
assertEquals("setter rename enabled", expectedSetterRenameEnabled, processor.canEnableSetterRenaming() == null);
String newGetterName = processor.getNewGetterName();
String newSetterName = processor.getNewSetterName();
List elements = new ArrayList();
elements.add(field);
List args = new ArrayList();
args.add(new RenameArguments(newFieldName, updateReferences));
if (renameGetter && expectedGetterRenameEnabled) {
elements.add(processor.getGetter());
args.add(new RenameArguments(newGetterName, updateReferences));
}
if (renameSetter && expectedSetterRenameEnabled) {
elements.add(processor.getSetter());
args.add(new RenameArguments(newSetterName, updateReferences));
}
String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenamePackageTest method helperMultiProjects.
/**
* Custom project and source folder structure.
*
* @param roots source folders
* @param packageNames package names per root
* @param newPackageName the new package name for packageNames[0][0]
* @param cuNames cu names per package
* @throws Exception if one of the resources cannot be created
*/
private void helperMultiProjects(IPackageFragmentRoot[] roots, String[][] packageNames, String newPackageName, String[][][] cuNames) throws Exception {
ICompilationUnit[][][] cus = new ICompilationUnit[roots.length][][];
IPackageFragment thisPackage = null;
for (int r = 0; r < roots.length; r++) {
IPackageFragment[] packages = new IPackageFragment[packageNames[r].length];
cus[r] = new ICompilationUnit[packageNames[r].length][];
for (int pa = 0; pa < packageNames[r].length; pa++) {
packages[pa] = roots[r].createPackageFragment(packageNames[r][pa], true, null);
cus[r][pa] = new ICompilationUnit[cuNames[r][pa].length];
if (r == 0 && pa == 0)
thisPackage = packages[pa];
for (int typ = 0; typ < cuNames[r][pa].length; typ++) {
cus[r][pa][typ] = createCUfromTestFile(packages[pa], cuNames[r][pa][typ], roots[r].getElementName() + "/" + packageNames[r][pa].replace('.', '/') + "/");
}
}
}
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(thisPackage, newPackageName);
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
setFilePatterns(descriptor);
descriptor.setUpdateHierarchy(fRenameSubpackages);
RefactoringStatus result = performRefactoring(descriptor);
TestCase.assertEquals("preconditions were supposed to pass", null, result);
assertTrue("package not renamed", !roots[0].getPackageFragment(packageNames[0][0]).exists());
IPackageFragment newPackage = roots[0].getPackageFragment(newPackageName);
assertTrue("new package does not exist", newPackage.exists());
for (int r = 0; r < cuNames.length; r++) {
for (int pa = 0; pa < cuNames[r].length; pa++) {
String packageName = roots[r].getElementName() + "/" + ((r == 0 && pa == 0) ? newPackageName : packageNames[r][pa]).replace('.', '/') + "/";
for (int typ = 0; typ < cuNames[r][pa].length; typ++) {
String s1 = getFileContents(getOutputTestFileName(cuNames[r][pa][typ], packageName));
ICompilationUnit cu = (r == 0 && pa == 0) ? newPackage.getCompilationUnit(cuNames[r][pa][typ] + ".java") : cus[r][pa][typ];
//DebugUtils.dump("cu:" + cu.getElementName());
String s2 = cu.getSource();
//DebugUtils.dump("expected:" + s1);
//DebugUtils.dump("was:" + s2);
assertEqualLines("invalid update in file " + cu.toString(), s1, s2);
}
}
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameVirtualMethodInClassTest method test18.
@Test
public void test18() throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");
IType classB = getType(cu, "B");
IMethod method = classB.getMethod("m", new String[] { "I" });
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setNewName("kk");
descriptor.setUpdateReferences(true);
final RefactoringStatus status = new RefactoringStatus();
final Refactoring refactoring = descriptor.createRefactoring(status);
assertNotNull("Refactoring should not be null", refactoring);
assertTrue("status should be ok", status.isOK());
assertEquals("was supposed to pass", null, performRefactoring(refactoring));
assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertEqualLines("invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource());
}
Aggregations