Search in sources :

Example 11 with RenameArguments

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

the class RenameTypeTest method testSimilarElements22.

@Test
public void testSimilarElements22() throws Exception {
    // Test transplanter for fields in types inside of initializers
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
    IType someClass = getType(cu, "SomeClass");
    List handleList = new ArrayList();
    List argumentList = new ArrayList();
    List similarOldHandleList = new ArrayList();
    List similarNewNameList = new ArrayList();
    List similarNewHandleList = new ArrayList();
    final String newName = "SomeNewClass";
    // field in class in initializer
    IField inInitializer = someClass.getInitializer(1).getType("InInitializer", 1).getField("someClassInInitializer");
    similarOldHandleList.add(inInitializer.getHandleIdentifier());
    similarNewNameList.add("someNewClassInInitializer");
    similarNewHandleList.add("Lp/SomeNewClass$InInitializer;.someNewClassInInitializer");
    // 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);
    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) 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 12 with RenameArguments

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

the class RenameTypeTest method testSimilarElements23.

@Test
public void testSimilarElements23() throws Exception {
    // Test transplanter for elements inside types inside fields
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
    IType someClass = getType(cu, "SomeClass");
    List handleList = new ArrayList();
    List argumentList = new ArrayList();
    List similarOldHandleList = new ArrayList();
    List similarNewNameList = new ArrayList();
    List similarNewHandleList = new ArrayList();
    final String newName = "SomeNewClass";
    // some field
    IField anotherSomeClass = someClass.getField("anotherSomeClass");
    similarOldHandleList.add(anotherSomeClass.getHandleIdentifier());
    similarNewNameList.add("anotherSomeNewClass");
    similarNewHandleList.add("Lp/SomeNewClass;.anotherSomeNewClass");
    // field in class in method in field declaration ;)
    IField inInner = anotherSomeClass.getType("", 1).getMethod("foo", new String[0]).getType("X", 1).getField("someClassInInner");
    similarOldHandleList.add(inInner.getHandleIdentifier());
    similarNewNameList.add("someNewClassInInner");
    similarNewHandleList.add("Lp/SomeNewClass$1$X;.someNewClassInInner");
    // 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);
    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) 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 13 with RenameArguments

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

the class TestRenameParticipantShared method testArguments.

public static void testArguments(RenameArguments[] args) {
    testNumberOfElements(args.length);
    for (int i = 0; i < args.length; i++) {
        RenameArguments expected = args[i];
        RenameArguments actual = (RenameArguments) fgInstance.fArguments.get(i);
        Assert.assertEquals(expected.getNewName(), actual.getNewName());
        Assert.assertEquals(expected.getUpdateReferences(), actual.getUpdateReferences());
    }
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments)

Example 14 with RenameArguments

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

the class RenameCompilationUnitProcessor method computeRenameModifications.

@Override
protected RenameModifications computeRenameModifications() {
    RenameModifications result = new RenameModifications();
    result.rename(fCu, new RenameArguments(getNewElementName(), getUpdateReferences()));
    if (fRenameTypeProcessor != null) {
        String newTypeName = removeFileNameExtension(getNewElementName());
        RenameTypeArguments arguments = new RenameTypeArguments(newTypeName, getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements());
        result.rename(fRenameTypeProcessor.getType(), arguments, getUpdateSimilarDeclarations() ? new RenameTypeProcessor.ParticipantDescriptorFilter() : null);
    }
    return result;
}
Also used : RenameTypeArguments(org.eclipse.jdt.core.refactoring.RenameTypeArguments) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments)

Example 15 with RenameArguments

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

the class RenameFieldProcessor method computeRenameModifications.

@Override
protected RenameModifications computeRenameModifications() throws CoreException {
    RenameModifications result = new RenameModifications();
    result.rename(fField, new RenameArguments(getNewElementName(), getUpdateReferences()));
    if (fRenameGetter) {
        IMethod getter = getGetter();
        if (getter != null) {
            result.rename(getter, new RenameArguments(getNewGetterName(), getUpdateReferences()));
        }
    }
    if (fRenameSetter) {
        IMethod setter = getSetter();
        if (setter != null) {
            result.rename(setter, new RenameArguments(getNewSetterName(), getUpdateReferences()));
        }
    }
    return result;
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) IMethod(org.eclipse.jdt.core.IMethod)

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