Search in sources :

Example 1 with RenameArguments

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

the class RenameMethodProcessor method computeRenameModifications.

@Override
protected RenameModifications computeRenameModifications() throws CoreException {
    RenameModifications result = new RenameModifications();
    RenameArguments args = new RenameArguments(getNewElementName(), getUpdateReferences());
    for (Iterator<IMethod> iter = fMethodsToRename.iterator(); iter.hasNext(); ) {
        IMethod method = iter.next();
        result.rename(method, args);
    }
    return result;
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) IMethod(org.eclipse.jdt.core.IMethod)

Example 2 with RenameArguments

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

the class RenameTypeProcessor method computeRenameModifications.

@Override
protected RenameModifications computeRenameModifications() {
    RenameModifications result = new RenameModifications();
    result.rename(fType, new RenameTypeArguments(getNewElementName(), getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter());
    if (isPrimaryType()) {
        ICompilationUnit cu = fType.getCompilationUnit();
        String newCUName = getNewCompilationUnit().getElementName();
        result.rename(cu, new RenameArguments(newCUName, getUpdateReferences()));
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameTypeArguments(org.eclipse.jdt.core.refactoring.RenameTypeArguments) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments)

Example 3 with RenameArguments

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

the class ResourceModifications method getParticipants.

public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, String[] natures, SharableParticipants shared) {
    List<RefactoringParticipant> result = new ArrayList<RefactoringParticipant>(5);
    if (fDelete != null) {
        DeleteArguments arguments = new DeleteArguments();
        for (Iterator<IResource> iter = fDelete.iterator(); iter.hasNext(); ) {
            DeleteParticipant[] deletes = ParticipantManager.loadDeleteParticipants(status, processor, iter.next(), arguments, natures, shared);
            result.addAll(Arrays.asList(deletes));
        }
    }
    if (fCreate != null) {
        CreateArguments arguments = new CreateArguments();
        for (Iterator<IResource> iter = fCreate.iterator(); iter.hasNext(); ) {
            CreateParticipant[] creates = ParticipantManager.loadCreateParticipants(status, processor, iter.next(), arguments, natures, shared);
            result.addAll(Arrays.asList(creates));
        }
    }
    if (fMove != null) {
        for (int i = 0; i < fMove.size(); i++) {
            Object element = fMove.get(i);
            MoveArguments arguments = fMoveArguments.get(i);
            MoveParticipant[] moves = ParticipantManager.loadMoveParticipants(status, processor, element, arguments, natures, shared);
            result.addAll(Arrays.asList(moves));
        }
    }
    if (fCopy != null) {
        for (int i = 0; i < fCopy.size(); i++) {
            Object element = fCopy.get(i);
            CopyArguments arguments = fCopyArguments.get(i);
            CopyParticipant[] copies = ParticipantManager.loadCopyParticipants(status, processor, element, arguments, natures, shared);
            result.addAll(Arrays.asList(copies));
        }
    }
    if (fRename != null) {
        for (int i = 0; i < fRename.size(); i++) {
            Object resource = fRename.get(i);
            RenameArguments arguments = fRenameArguments.get(i);
            RenameParticipant[] renames = ParticipantManager.loadRenameParticipants(status, processor, resource, arguments, natures, shared);
            result.addAll(Arrays.asList(renames));
        }
    }
    return result.toArray(new RefactoringParticipant[result.size()]);
}
Also used : RefactoringParticipant(org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) ArrayList(java.util.ArrayList) MoveParticipant(org.eclipse.ltk.core.refactoring.participants.MoveParticipant) DeleteParticipant(org.eclipse.ltk.core.refactoring.participants.DeleteParticipant) CreateArguments(org.eclipse.ltk.core.refactoring.participants.CreateArguments) DeleteArguments(org.eclipse.ltk.core.refactoring.participants.DeleteArguments) CopyArguments(org.eclipse.ltk.core.refactoring.participants.CopyArguments) CreateParticipant(org.eclipse.ltk.core.refactoring.participants.CreateParticipant) CopyParticipant(org.eclipse.ltk.core.refactoring.participants.CopyParticipant) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) RenameParticipant(org.eclipse.ltk.core.refactoring.participants.RenameParticipant) IResource(org.eclipse.core.resources.IResource)

Example 4 with RenameArguments

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

the class RenameNonPrivateFieldTest method helper2.

private void helper2(String fieldName, String newFieldName, boolean createDelegates) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IField field = classA.getField(fieldName);
    boolean isEnum = JdtFlags.isEnum(field);
    String id = isEnum ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(id);
    descriptor.setJavaElement(field);
    descriptor.setNewName(newFieldName);
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    if (!isEnum) {
        descriptor.setRenameGetters(fRenameGetter);
        descriptor.setRenameSetters(fRenameSetter);
        descriptor.setKeepOriginal(createDelegates);
        descriptor.setDeprecateDelegate(true);
    }
    RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
    RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
    List elements = new ArrayList();
    elements.add(field);
    List args = new ArrayList();
    args.add(new RenameArguments(newFieldName, fUpdateReferences));
    if (fRenameGetter) {
        elements.add(processor.getGetter());
        args.add(new RenameArguments(processor.getNewGetterName(), fUpdateReferences));
    }
    if (fRenameSetter) {
        elements.add(processor.getSetter());
        args.add(new RenameArguments(processor.getNewSetterName(), fUpdateReferences));
    }
    String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());
    RefactoringStatus result = performRefactoring(refactoring);
    assertEquals("was supposed to pass", null, result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    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) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameFieldProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) ArrayList(java.util.ArrayList) List(java.util.List) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 5 with RenameArguments

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

the class RenamePackageTest method testHierarchicalToSuperpackage.

@Test
@Ignore
public void testHierarchicalToSuperpackage() throws Exception {
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "a.b", "a.b.b", "a", "p" }, new String[][] { { "B" }, { "BB" }, {} }, "a", true);
    IPackageFragment thisPackage = rename.fPackages[0];
    IFolder src = (IFolder) getRoot().getResource();
    IFolder a = src.getFolder("a");
    IFolder ab = src.getFolder("a/b");
    IFolder abb = src.getFolder("a/b/b");
    ParticipantTesting.reset();
    String[] createHandles = {};
    String[] deleteHandles = {};
    String[] moveHandles = ParticipantTesting.createHandles(ab.getFile("B.java"), abb.getFile("BB.java"));
    String[] renameHandles = ParticipantTesting.createHandles(JavaElementUtil.getPackageAndSubpackages(thisPackage));
    rename.createAndPerform(RefactoringStatus.OK);
    rename.checkExpectedState();
    ParticipantTesting.testCreate(createHandles);
    ParticipantTesting.testDelete(deleteHandles);
    ParticipantTesting.testMove(moveHandles, new MoveArguments[] { new MoveArguments(a, true), new MoveArguments(ab, true) });
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments("a", true), new RenameArguments("a.b", true) });
    performUndo();
    rename.checkOriginalState();
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

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