Search in sources :

Example 16 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.

the class RenamePrivateFieldTest method helper1_0.

private void helper1_0(String fieldName, String newFieldName, String typeName, boolean renameGetter, boolean renameSetter) throws Exception {
    IType declaringType = getType(createCUfromTestFile(getPackageP(), "A"), typeName);
    IField field = declaringType.getField(fieldName);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
    descriptor.setJavaElement(field);
    descriptor.setNewName(newFieldName);
    descriptor.setUpdateReferences(true);
    descriptor.setRenameGetters(renameGetter);
    descriptor.setRenameSetters(renameSetter);
    RefactoringStatus result = performRefactoring(descriptor);
    assertNotNull("precondition was supposed to fail", result);
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IField(org.eclipse.jdt.core.IField) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType)

Example 17 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.

the class RenameVirtualMethodInClassTest method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
    final ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    final IType classA = getType(cu, "A");
    final IMethod method = classA.getMethod(methodName, signatures);
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setNewName(newMethodName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setKeepOriginal(createDelegate);
    descriptor.setDeprecateDelegate(createDelegate);
    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));
    if (!shouldPass) {
        assertTrue("incorrect renaming because of java model", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
        return;
    }
    String expectedRenaming = getFileContents(getOutputTestFileName("A"));
    String actuaRenaming = cu.getSource();
    assertEqualLines("incorrect renaming", expectedRenaming, actuaRenaming);
    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) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) 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 18 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.

the class RenameStaticMethodTest method helper1_0.

private void helper1_0(String methodName, String newMethodName, String[] signatures) throws Exception {
    IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
    IMethod method = classA.getMethod(methodName, signatures);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setNewName(newMethodName);
    descriptor.setUpdateReferences(true);
    RefactoringStatus result = performRefactoring(descriptor);
    assertNotNull("precondition was supposed to fail", result);
}
Also used : 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 19 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.

the class RenameStaticMethodTest method test10.

@Test
public void test10() throws Exception {
    //		printTestDisabledMessage("bug 40628");
    //		if (true)	return;
    ICompilationUnit cuA = createCUfromTestFile(getPackageP(), "A");
    ICompilationUnit cuB = createCUfromTestFile(getPackageP(), "B");
    IType classB = getType(cuB, "B");
    IMethod method = classB.getMethod("method", new String[0]);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setUpdateReferences(true);
    descriptor.setJavaElement(method);
    descriptor.setNewName("newmethod");
    assertEquals("was supposed to pass", null, performRefactoring(descriptor));
    assertEqualLines("invalid renaming in A", getFileContents(getOutputTestFileName("A")), cuA.getSource());
    assertEqualLines("invalid renaming in B", getFileContents(getOutputTestFileName("B")), cuB.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 20 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.

the class RenameTypeTest method testSimilarElements24.

@Test
public void testSimilarElements24() throws Exception {
    // Test transplanter for ICompilationUnit and IFile
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
    IType someClass = getType(cu, "SomeClass");
    IJavaElement[] someClassMembers = someClass.getChildren();
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, "SomeNewClass");
    setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
    Refactoring ref = createRefactoring(descriptor);
    RefactoringStatus status = performRefactoring(ref);
    Assert.assertNull("was supposed to pass", status);
    checkResultInClass("SomeNewClass");
    checkMappers(ref, someClass, "SomeNewClass.java", someClassMembers);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) 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) 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