Search in sources :

Example 51 with RenameJavaElementDescriptor

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;
}
Also used : RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 52 with RenameJavaElementDescriptor

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IAdaptable(org.eclipse.core.runtime.IAdaptable) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 53 with RenameJavaElementDescriptor

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()));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 54 with RenameJavaElementDescriptor

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);
}
Also used : IField(org.eclipse.jdt.core.IField) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 55 with RenameJavaElementDescriptor

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);
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Aggregations

RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)120 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 IType (org.eclipse.jdt.core.IType)55 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)55 Test (org.junit.Test)33 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)29 IMethod (org.eclipse.jdt.core.IMethod)28 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)26 IJavaProject (org.eclipse.jdt.core.IJavaProject)25 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)25 IField (org.eclipse.jdt.core.IField)24 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)21 ArrayList (java.util.ArrayList)19 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)19 JavaModelException (org.eclipse.jdt.core.JavaModelException)15 IPath (org.eclipse.core.runtime.IPath)12 TextChange (org.eclipse.ltk.core.refactoring.TextChange)10 IFile (org.eclipse.core.resources.IFile)9