Search in sources :

Example 1 with RenameNonVirtualMethodProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor in project che by eclipse.

the class RenameMethodRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws JavaModelException {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    String input = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
    IMethod method = (IMethod) JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), input);
    if (method == null) {
        status.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoringContribution_could_not_create, new Object[] { BasicElementLabels.getResourceName(arguments.getProject()), input }));
        return null;
    }
    JavaRenameProcessor processor;
    if (MethodChecks.isVirtual(method)) {
        processor = new RenameVirtualMethodProcessor(method, arguments, status);
    } else {
        processor = new RenameNonVirtualMethodProcessor(method, arguments, status);
    }
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IMethod(org.eclipse.jdt.core.IMethod)

Example 2 with RenameNonVirtualMethodProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor in project che by eclipse.

the class RenamePrivateMethodTest method helper1_0.

private void helper1_0(String methodName, String newMethodName, String[] signatures) throws Exception {
    IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(classA.getMethod(methodName, signatures));
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName(newMethodName);
    RefactoringStatus result = performRefactoring(refactoring);
    assertNotNull("precondition was supposed to fail", result);
}
Also used : RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IType(org.eclipse.jdt.core.IType)

Example 3 with RenameNonVirtualMethodProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor in project che by eclipse.

the class RenamePrivateMethodTest method test18.

@Test
public void test18() throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");
    IType classB = getType(cu, "B");
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(classB.getMethod("m", new String[] { "I" }));
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName("kk");
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
    assertEqualLines("invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 4 with RenameNonVirtualMethodProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor in project che by eclipse.

the class RenamePrivateMethodTest method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean updateReferences, boolean createDelegate) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IMethod method = classA.getMethod(methodName, signatures);
    String[] handles = ParticipantTesting.createHandles(method);
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(method);
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setUpdateReferences(updateReferences);
    processor.setNewElementName(newMethodName);
    processor.setDelegateUpdating(createDelegate);
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(handles, new RenameArguments[] { new RenameArguments(newMethodName, updateReferences) });
    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) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Aggregations

RenameNonVirtualMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor)4 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)4 IType (org.eclipse.jdt.core.IType)3 RenameMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IMethod (org.eclipse.jdt.core.IMethod)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 JavaRefactoringArguments (org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments)1 JavaRenameProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor)1 RenameVirtualMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)1 Test (org.junit.Test)1