Search in sources :

Example 41 with RenameJavaElementDescriptor

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

the class RenameStaticMethodTests 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 42 with RenameJavaElementDescriptor

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

the class RenameStaticMethodTests method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean updateReferences, boolean createDelegate) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IMethod method = classA.getMethod(methodName, signatures);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setJavaElement(method);
    descriptor.setNewName(newMethodName);
    descriptor.setKeepOriginal(createDelegate);
    descriptor.setDeprecateDelegate(true);
    assertNull("was supposed to pass", performRefactoring(descriptor));
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertFalse("! 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());
    assertFalse("! 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 43 with RenameJavaElementDescriptor

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

the class RenameStaticMethodTests 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");
    assertNull("was supposed to pass", 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 44 with RenameJavaElementDescriptor

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

the class RenameMethodInInterfaceTests 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 45 with RenameJavaElementDescriptor

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

the class RenameMethodInInterfaceTests 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);
    assertNull("was supposed to pass", performRefactoring(descriptor));
    if (!shouldPass) {
        assertNotEquals("incorrect renaming because of a java model bug", getFileContents(getOutputTestFileName("A")), cu.getSource());
        return;
    }
    assertEqualLines("incorrect renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertFalse("! 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());
    assertFalse("! 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)

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