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());
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameVirtualMethodInClassTest method test40.
@Test
public void test40() throws Exception {
// test for bug 68592
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType localClass = cu.getType("A").getMethod("doit", new String[0]).getType("LocalClass", 1);
IMethod method = localClass.getMethod("method", new String[] { "I" });
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setNewName("method2");
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());
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeTest method createRefactoringDescriptor.
private RenameJavaElementDescriptor createRefactoringDescriptor(IType type, String newName) {
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
descriptor.setJavaElement(type);
descriptor.setNewName(newName);
descriptor.setUpdateReferences(true);
return descriptor;
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeTest method testSimilarElements11.
@Test
public void testSimilarElements11() throws Exception {
//Assure participants get notified of normal stuff (type rename
//and resource changes) AND similarly named elements.
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
IType someClass = getType(cu, "SomeClass");
IType other = getClassFromTestFile(getPackageP(), "SomeOtherClass");
List handleList = new ArrayList();
List argumentList = new ArrayList();
List similarOldHandleList = new ArrayList();
List similarNewNameList = new ArrayList();
List similarNewHandleList = new ArrayList();
final String newName = "SomeNewClass";
// f-Field + getters/setters
IField f3 = other.getField("fSomeClass");
similarOldHandleList.add(f3.getHandleIdentifier());
similarNewHandleList.add("Lp/SomeOtherClass;.fSomeNewClass");
similarNewNameList.add("fSomeNewClass");
IMethod m3 = other.getMethod("getSomeClass", new String[0]);
similarOldHandleList.add(m3.getHandleIdentifier());
similarNewNameList.add("getSomeNewClass");
similarNewHandleList.add("Lp/SomeOtherClass;.getSomeNewClass()V");
IMethod m4 = other.getMethod("setSomeClass", new String[] { "QSomeClass;" });
similarOldHandleList.add(m4.getHandleIdentifier());
similarNewNameList.add("setSomeNewClass");
similarNewHandleList.add("Lp/SomeOtherClass;.setSomeNewClass(QSomeNewClass;)V");
// non-f-field + getter/setters
IField f1 = someClass.getField("someClass");
similarOldHandleList.add(f1.getHandleIdentifier());
similarNewNameList.add("someNewClass");
similarNewHandleList.add("Lp/SomeNewClass;.someNewClass");
IMethod m1 = someClass.getMethod("getSomeClass", new String[0]);
similarOldHandleList.add(m1.getHandleIdentifier());
similarNewNameList.add("getSomeNewClass");
similarNewHandleList.add("Lp/SomeNewClass;.getSomeNewClass()V");
IMethod m2 = someClass.getMethod("setSomeClass", new String[] { "QSomeClass;" });
similarOldHandleList.add(m2.getHandleIdentifier());
similarNewNameList.add("setSomeNewClass");
similarNewHandleList.add("Lp/SomeNewClass;.setSomeNewClass(QSomeNewClass;)V");
// fs-field
IField f2 = someClass.getField("fsSomeClass");
similarOldHandleList.add(f2.getHandleIdentifier());
similarNewNameList.add("fsSomeNewClass");
similarNewHandleList.add("Lp/SomeNewClass;.fsSomeNewClass");
// Type Stuff
handleList.add(someClass);
argumentList.add(new RenameArguments(newName, true));
handleList.add(cu);
argumentList.add(new RenameArguments(newName + ".java", true));
handleList.add(cu.getResource());
argumentList.add(new RenameArguments(newName + ".java", true));
String[] handles = ParticipantTesting.createHandles(handleList.toArray());
RenameArguments[] arguments = (RenameArguments[]) argumentList.toArray(new RenameArguments[0]);
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, newName);
setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
RefactoringStatus status = performRefactoring(descriptor);
Assert.assertNull("was supposed to pass", status);
checkResultInClass(newName);
checkResultInClass("SomeOtherClass");
ParticipantTesting.testRename(handles, arguments);
ParticipantTesting.testSimilarElements(similarOldHandleList, similarNewNameList, similarNewHandleList);
}
Aggregations