Search in sources :

Example 11 with RenameJavaElementDescriptor

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

Example 12 with RenameJavaElementDescriptor

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

Example 13 with RenameJavaElementDescriptor

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

Example 14 with RenameJavaElementDescriptor

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) INameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IType(org.eclipse.jdt.core.IType)

Example 15 with RenameJavaElementDescriptor

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

Aggregations

RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)40 IType (org.eclipse.jdt.core.IType)24 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)21 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)18 IMethod (org.eclipse.jdt.core.IMethod)12 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)11 Test (org.junit.Test)10 IField (org.eclipse.jdt.core.IField)9 ArrayList (java.util.ArrayList)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)8 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)8 List (java.util.List)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)6 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)6 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3