use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class RenameTypeTests 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 eclipse.jdt.ui by eclipse-jdt.
the class RenameTypeTests 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<IAdaptable> handleList = new ArrayList<>();
List<RenameArguments> argumentList = new ArrayList<>();
List<String> similarOldHandleList = new ArrayList<>();
List<String> similarNewNameList = new ArrayList<>();
List<String> 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 = argumentList.toArray(new RenameArguments[0]);
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, newName);
setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
RefactoringStatus status = performRefactoring(descriptor);
assertNull("was supposed to pass", status);
checkResultInClass(newName);
checkResultInClass("SomeOtherClass");
ParticipantTesting.testRename(handles, arguments);
ParticipantTesting.testSimilarElements(similarOldHandleList, similarNewNameList, similarNewHandleList);
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class ValidateEditTests method testCURename.
@Test
public void testCURename() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuilder buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append("}\n");
ICompilationUnit cu1 = fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
setReadOnly(cu1);
buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("public class C extends MyClass {\n");
buf.append("}\n");
ICompilationUnit cu2 = fragment.createCompilationUnit("C.java", buf.toString(), true, null);
setReadOnly(cu2);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_COMPILATION_UNIT);
descriptor.setJavaElement(cu1);
descriptor.setNewName("MyClass2.java");
descriptor.setUpdateReferences(true);
RefactoringStatus status = performRefactoring(descriptor);
if (status != null)
assertTrue(status.toString(), status.isOK());
Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
assertEquals(2, validatedEditPaths.size());
assertTrue(validatedEditPaths.contains(cu1.getPath()));
assertTrue(validatedEditPaths.contains(cu2.getPath()));
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class BinaryReferencesTests method doRenameField.
private List<SearchMatch> doRenameField(String typeName, String fieldName) throws CoreException {
IField field = findType(typeName).getField(fieldName);
String refactoringID = field.isEnumConstant() ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(refactoringID);
descriptor.setJavaElement(field);
descriptor.setNewName(field.isEnumConstant() ? "BLA" : "newName");
descriptor.setUpdateReferences(true);
return doRefactoring(descriptor);
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class BinaryReferencesTests method doRenameMethod.
private List<SearchMatch> doRenameMethod(String typeName, String methodName) throws CoreException {
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
IMethod method = findMethod(findType(typeName), methodName);
descriptor.setJavaElement(method);
descriptor.setNewName("newName");
descriptor.setUpdateReferences(true);
return doRefactoring(descriptor);
}
Aggregations