use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameMethodInInterfaceTest method helper1_0.
private void helper1_0(String methodName, String newMethodName, String[] signatures) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType interfaceI = getType(cu, "I");
IMethod method = interfaceI.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setUpdateReferences(true);
descriptor.setNewName(newMethodName);
RefactoringStatus result = performRefactoring(descriptor);
assertNotNull("precondition was supposed to fail", result);
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameMethodInInterfaceTest method helper2_0.
private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType interfaceI = getType(cu, "I");
IMethod method = interfaceI.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setUpdateReferences(updateReferences);
descriptor.setNewName(newMethodName);
descriptor.setKeepOriginal(createDelegate);
descriptor.setDeprecateDelegate(true);
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
if (!shouldPass) {
assertTrue("incorrect renaming because of a java model bug", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
return;
}
assertEqualLines("incorrect renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
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 RenameTypeTest method testSimilarElements22.
@Test
public void testSimilarElements22() throws Exception {
// Test transplanter for fields in types inside of initializers
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
IType someClass = getType(cu, "SomeClass");
List handleList = new ArrayList();
List argumentList = new ArrayList();
List similarOldHandleList = new ArrayList();
List similarNewNameList = new ArrayList();
List similarNewHandleList = new ArrayList();
final String newName = "SomeNewClass";
// field in class in initializer
IField inInitializer = someClass.getInitializer(1).getType("InInitializer", 1).getField("someClassInInitializer");
similarOldHandleList.add(inInitializer.getHandleIdentifier());
similarNewNameList.add("someNewClassInInitializer");
similarNewHandleList.add("Lp/SomeNewClass$InInitializer;.someNewClassInInitializer");
// 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);
ParticipantTesting.testRename(handles, arguments);
ParticipantTesting.testSimilarElements(similarOldHandleList, similarNewNameList, similarNewHandleList);
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor 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;
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeTest method testSimilarElements23.
@Test
public void testSimilarElements23() throws Exception {
// Test transplanter for elements inside types inside fields
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
IType someClass = getType(cu, "SomeClass");
List handleList = new ArrayList();
List argumentList = new ArrayList();
List similarOldHandleList = new ArrayList();
List similarNewNameList = new ArrayList();
List similarNewHandleList = new ArrayList();
final String newName = "SomeNewClass";
// some field
IField anotherSomeClass = someClass.getField("anotherSomeClass");
similarOldHandleList.add(anotherSomeClass.getHandleIdentifier());
similarNewNameList.add("anotherSomeNewClass");
similarNewHandleList.add("Lp/SomeNewClass;.anotherSomeNewClass");
// field in class in method in field declaration ;)
IField inInner = anotherSomeClass.getType("", 1).getMethod("foo", new String[0]).getType("X", 1).getField("someClassInInner");
similarOldHandleList.add(inInner.getHandleIdentifier());
similarNewNameList.add("someNewClassInInner");
similarNewHandleList.add("Lp/SomeNewClass$1$X;.someNewClassInInner");
// 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);
ParticipantTesting.testRename(handles, arguments);
ParticipantTesting.testSimilarElements(similarOldHandleList, similarNewNameList, similarNewHandleList);
}
Aggregations