Search in sources :

Example 26 with RenameArguments

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

the class RenamePackageTest method testHierarchical01.

@Test
public void testHierarchical01() throws Exception {
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "my", "my.a", "my.b" }, new String[][] { { "MyA" }, { "ATest" }, { "B" } }, "your");
    IPackageFragment thisPackage = rename.fPackages[0];
    ParticipantTesting.reset();
    List toRename = new ArrayList(Arrays.asList(JavaElementUtil.getPackageAndSubpackages(thisPackage)));
    toRename.add(thisPackage.getResource());
    String[] renameHandles = ParticipantTesting.createHandles(toRename.toArray());
    rename.execute();
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(rename.getNewPackageName(rename.fPackageNames[0]), true), new RenameArguments(rename.getNewPackageName(rename.fPackageNames[1]), true), new RenameArguments(rename.getNewPackageName(rename.fPackageNames[2]), true), new RenameArguments("your", true) });
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with RenameArguments

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

the class RenamePackageTest method test2.

@Test
public void test2() throws Exception {
    fIsPreDeltaTest = true;
    RenamePackageProcessor processor = helper2(new String[] { "r", "fred" }, new String[][] { { "A" }, { "A" } }, "p1");
    // test that participants are correctly informed after '< Back': https://bugs.eclipse.org/bugs/show_bug.cgi?id=280068
    performUndo();
    ParticipantTesting.reset();
    String secondName = "pipapo";
    processor.setNewElementName(secondName);
    String[] renameHandles = ParticipantTesting.createHandles(new Object[] { processor.getPackage(), processor.getPackage().getResource() });
    RenameRefactoring refactoring = (RenameRefactoring) processor.getRefactoring();
    refactoring.checkFinalConditions(new NullProgressMonitor());
    refactoring.createChange(new NullProgressMonitor());
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(secondName, true), new RenameArguments(secondName, true) });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenamePackageProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) Test(org.junit.Test)

Example 28 with RenameArguments

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

the class RenameTypeTest method testSimilarElements11.

@Test
public void testSimilarElements11() throws Exception {
    //Assure participants get notified of normal stuff (type rename
    //and resource changes) AND similarly named elements.
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
    IType someClass = getType(cu, "SomeClass");
    IType other = getClassFromTestFile(getPackageP(), "SomeOtherClass");
    List handleList = new ArrayList();
    List argumentList = new ArrayList();
    List similarOldHandleList = new ArrayList();
    List similarNewNameList = new ArrayList();
    List similarNewHandleList = new ArrayList();
    final String newName = "SomeNewClass";
    // f-Field + getters/setters
    IField f3 = other.getField("fSomeClass");
    similarOldHandleList.add(f3.getHandleIdentifier());
    similarNewHandleList.add("Lp/SomeOtherClass;.fSomeNewClass");
    similarNewNameList.add("fSomeNewClass");
    IMethod m3 = other.getMethod("getSomeClass", new String[0]);
    similarOldHandleList.add(m3.getHandleIdentifier());
    similarNewNameList.add("getSomeNewClass");
    similarNewHandleList.add("Lp/SomeOtherClass;.getSomeNewClass()V");
    IMethod m4 = other.getMethod("setSomeClass", new String[] { "QSomeClass;" });
    similarOldHandleList.add(m4.getHandleIdentifier());
    similarNewNameList.add("setSomeNewClass");
    similarNewHandleList.add("Lp/SomeOtherClass;.setSomeNewClass(QSomeNewClass;)V");
    // non-f-field + getter/setters
    IField f1 = someClass.getField("someClass");
    similarOldHandleList.add(f1.getHandleIdentifier());
    similarNewNameList.add("someNewClass");
    similarNewHandleList.add("Lp/SomeNewClass;.someNewClass");
    IMethod m1 = someClass.getMethod("getSomeClass", new String[0]);
    similarOldHandleList.add(m1.getHandleIdentifier());
    similarNewNameList.add("getSomeNewClass");
    similarNewHandleList.add("Lp/SomeNewClass;.getSomeNewClass()V");
    IMethod m2 = someClass.getMethod("setSomeClass", new String[] { "QSomeClass;" });
    similarOldHandleList.add(m2.getHandleIdentifier());
    similarNewNameList.add("setSomeNewClass");
    similarNewHandleList.add("Lp/SomeNewClass;.setSomeNewClass(QSomeNewClass;)V");
    // fs-field
    IField f2 = someClass.getField("fsSomeClass");
    similarOldHandleList.add(f2.getHandleIdentifier());
    similarNewNameList.add("fsSomeNewClass");
    similarNewHandleList.add("Lp/SomeNewClass;.fsSomeNewClass");
    // 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);
    checkResultInClass("SomeOtherClass");
    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) IMethod(org.eclipse.jdt.core.IMethod) 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 29 with RenameArguments

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

the class RenameTypeTest method test0.

@Test
public void test0() throws Exception {
    ParticipantTesting.reset();
    String newName = "B";
    String[] renameHandles = helper2("A", newName);
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(newName, true), new RenameArguments(newName + ".java", true), new RenameArguments(newName + ".java", true) });
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Example 30 with RenameArguments

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

the class RenameTypeTest method test61.

@Test
public void test61() throws Exception {
    ParticipantTesting.reset();
    String[] renameHandles = helperWithTextual("A", "Inner", "InnerB", "A", true, false);
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments("InnerB", true) });
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Aggregations

RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)36 Test (org.junit.Test)15 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)9 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)8 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)7 MoveArguments (org.eclipse.ltk.core.refactoring.participants.MoveArguments)7 IType (org.eclipse.jdt.core.IType)6 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)6 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)5 IFolder (org.eclipse.core.resources.IFolder)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IField (org.eclipse.jdt.core.IField)5 Ignore (org.junit.Ignore)5 IMethod (org.eclipse.jdt.core.IMethod)4 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)3 RenamePackageProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor)3