Search in sources :

Example 11 with Refactoring

use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.

the class RenameParametersTest method helper2.

private void helper2(String[] newNames, String[] signature) throws Exception {
    IType classA = getType(createCUfromTestFile(getPackageP(), false, false), "A");
    //DebugUtils.dump("classA" + classA);
    IMethod method = classA.getMethod("m", signature);
    Assert.assertTrue("refactoring not available", RefactoringAvailabilityTester.isChangeSignatureAvailable(method));
    ChangeSignatureProcessor processor = new ChangeSignatureProcessor(method);
    Refactoring ref = new ProcessorBasedRefactoring(processor);
    modifyInfos(processor.getParameterInfos(), newNames);
    RefactoringStatus result = performRefactoring(ref);
    Assert.assertNotNull("precondition was supposed to fail", result);
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) IType(org.eclipse.jdt.core.IType) ChangeSignatureProcessor(org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor)

Example 12 with Refactoring

use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.

the class RenameVirtualMethodInClassTest method test18.

@Test
public void test18() throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");
    IType classB = getType(cu, "B");
    IMethod method = classB.getMethod("m", new String[] { "I" });
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setNewName("kk");
    descriptor.setUpdateReferences(true);
    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));
    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) 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) Test(org.junit.Test)

Example 13 with Refactoring

use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.

the class RenameVirtualMethodInClassTest method test40.

@Test
public void test40() throws Exception {
    // test for bug 68592
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType localClass = cu.getType("A").getMethod("doit", new String[0]).getType("LocalClass", 1);
    IMethod method = localClass.getMethod("method", new String[] { "I" });
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setNewName("method2");
    descriptor.setUpdateReferences(true);
    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));
    assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
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) 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)

Example 14 with Refactoring

use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.

the class RenameTypeTest method helper3.

private void helper3(String oldName, String newName, boolean updateRef, boolean updateTextual, boolean updateSimilar, String nonJavaFiles) throws JavaModelException, CoreException, IOException, Exception {
    RefactoringDescriptor descriptor = initWithAllOptions(oldName, oldName, newName, updateRef, updateTextual, updateSimilar, nonJavaFiles, RenamingNameSuggestor.STRATEGY_EMBEDDED);
    Refactoring ref = createRefactoring(descriptor);
    RefactoringStatus status = performRefactoring(ref);
    Assert.assertNull("was supposed to pass", status);
    checkResultInClass(newName);
    checkMappedSimilarElementsExist(ref);
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)

Example 15 with Refactoring

use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.

the class RenameTypeTest method helper3_inner.

private void helper3_inner(String oldName, String oldInnerName, String newName, String innerNewName, boolean updateRef, boolean updateTextual, boolean updateSimilar, String nonJavaFiles) throws JavaModelException, CoreException, IOException, Exception {
    RefactoringDescriptor descriptor = initWithAllOptions(oldName, oldInnerName, innerNewName, updateRef, updateTextual, updateSimilar, nonJavaFiles, RenamingNameSuggestor.STRATEGY_EMBEDDED);
    Refactoring ref = createRefactoring(descriptor);
    Assert.assertNull("was supposed to pass", performRefactoring(ref));
    checkResultInClass(newName);
    checkMappedSimilarElementsExist(ref);
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)

Aggregations

Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)17 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)13 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)11 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)8 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)8 IType (org.eclipse.jdt.core.IType)7 IMethod (org.eclipse.jdt.core.IMethod)5 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)5 ProcessorBasedRefactoring (org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)5 Test (org.junit.Test)5 IContainer (org.eclipse.core.resources.IContainer)4 IFolder (org.eclipse.core.resources.IFolder)3 IPath (org.eclipse.core.runtime.IPath)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IJavaElementMapper (org.eclipse.jdt.core.refactoring.IJavaElementMapper)2 ChangeSignatureProcessor (org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor)2