Search in sources :

Example 11 with MoveArguments

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

the class RenamePackageTest method testHierarchicalToSuperpackage2.

@Test
@Ignore
public void testHierarchicalToSuperpackage2() throws Exception {
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "a.b", "a.b.c", "a.c", "p" }, new String[][] { { "B" }, { "BC" }, {} }, "a", true);
    IPackageFragment thisPackage = rename.fPackages[0];
    IFolder src = (IFolder) getRoot().getResource();
    IFolder a = src.getFolder("a");
    IFolder ab = src.getFolder("a/b");
    IFolder ac = src.getFolder("a/c");
    IFolder abc = src.getFolder("a/b/c");
    ParticipantTesting.reset();
    String[] createHandles = {};
    String[] deleteHandles = ParticipantTesting.createHandles(ab);
    String[] moveHandles = ParticipantTesting.createHandles(ab.getFile("B.java"), abc.getFile("BC.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(ac, true) });
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments("a", true), new RenameArguments("a.c", true) });
    performUndo();
    // empty package is not recreated, but that's OK
    rename.fPackageNames = new String[] { "a.b", "a.b.c", "a", "p" };
    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)

Example 12 with MoveArguments

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

the class RenamePackageTest method testHierarchical02.

@Test
@Ignore
public void testHierarchical02() throws Exception {
    if (BUG_PACKAGE_CANT_BE_RENAMED_TO_A_PACKAGE_THAT_ALREADY_EXISTS) {
        printTestDisabledMessage("package can't be renamed to a package that already exists.");
        return;
    }
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "my", "my.a", "my.b", "your" }, new String[][] { { "MyA" }, { "ATest" }, { "B" }, { "Y" } }, "your");
    IPackageFragment thisPackage = rename.fPackages[0];
    IPath srcPath = thisPackage.getParent().getPath();
    IFolder target = ResourcesPlugin.getWorkspace().getRoot().getFolder(srcPath.append("your"));
    ParticipantTesting.reset();
    String[] createHandles = ParticipantTesting.createHandles(target.getFolder("a"), target.getFolder("b"));
    String[] deleteHandles = ParticipantTesting.createHandles(thisPackage.getResource());
    String[] moveHandles = ParticipantTesting.createHandles(new Object[] { rename.fCus[0][0].getResource(), rename.fCus[1][0].getResource(), rename.fCus[2][0].getResource() });
    String[] renameHandles = ParticipantTesting.createHandles(JavaElementUtil.getPackageAndSubpackages(thisPackage));
    rename.execute();
    ParticipantTesting.testCreate(createHandles);
    ParticipantTesting.testDelete(deleteHandles);
    ParticipantTesting.testMove(moveHandles, new MoveArguments[] { new MoveArguments(target, true), new MoveArguments(target.getFolder("a"), true), new MoveArguments(target.getFolder("b"), true) });
    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) });
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) 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)

Example 13 with MoveArguments

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

the class RenameModifications method addResourceModifications.

private IFolder addResourceModifications(IPackageFragment rootPackage, RenameArguments args, IPackageFragment pack, boolean renameSubPackages) throws CoreException {
    IContainer container = (IContainer) pack.getResource();
    if (container == null)
        return null;
    IFolder target = computeTargetFolder(rootPackage, args, pack);
    createIncludingParents(target);
    MoveArguments arguments = new MoveArguments(target, args.getUpdateReferences());
    IResource[] resourcesToMove = collectResourcesOfInterest(pack);
    Set<IResource> allMembers = new HashSet<IResource>(Arrays.asList(container.members()));
    for (int i = 0; i < resourcesToMove.length; i++) {
        IResource toMove = resourcesToMove[i];
        getResourceModifications().addMove(toMove, arguments);
        allMembers.remove(toMove);
    }
    for (Iterator<IResource> iter = allMembers.iterator(); iter.hasNext(); ) {
        IResource element = iter.next();
        if (element instanceof IFile) {
            getResourceModifications().addDelete(element);
            iter.remove();
        }
    }
    if (!renameSubPackages && allMembers.isEmpty()) {
        getResourceModifications().addDelete(container);
    }
    return target;
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) HashSet(java.util.HashSet)

Example 14 with MoveArguments

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

the class ResourceModifications method addMove.

/**
	 * Adds the given resource to the list of resources
	 * to be moved.
	 *
	 * @param move the resource to be moved
	 * @param arguments the move arguments
	 */
public void addMove(IResource move, MoveArguments arguments) {
    if (fMove == null) {
        fMove = new ArrayList<IResource>(2);
        fMoveArguments = new ArrayList<MoveArguments>(2);
    }
    fMove.add(move);
    fMoveArguments.add(arguments);
    if (fIgnoreCount == 0) {
        IPath destination = ((IResource) arguments.getDestination()).getFullPath().append(move.getName());
        internalAdd(new MoveDescription(move, destination));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IResource(org.eclipse.core.resources.IResource)

Example 15 with MoveArguments

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

the class ResourceModifications method getParticipants.

public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, String[] natures, SharableParticipants shared) {
    List result = new ArrayList(5);
    if (fDelete != null) {
        DeleteArguments arguments = new DeleteArguments();
        for (Iterator 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 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 = (MoveArguments) 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 = (CopyArguments) 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 = (RenameArguments) fRenameArguments.get(i);
            RenameParticipant[] renames = ParticipantManager.loadRenameParticipants(status, processor, resource, arguments, natures, shared);
            result.addAll(Arrays.asList(renames));
        }
    }
    return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]);
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RefactoringParticipant(org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant) 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) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RenameParticipant(org.eclipse.ltk.core.refactoring.participants.RenameParticipant)

Aggregations

MoveArguments (org.eclipse.ltk.core.refactoring.participants.MoveArguments)16 IResource (org.eclipse.core.resources.IResource)9 IFolder (org.eclipse.core.resources.IFolder)7 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)6 IFile (org.eclipse.core.resources.IFile)4 Ignore (org.junit.Ignore)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IContainer (org.eclipse.core.resources.IContainer)3 IPath (org.eclipse.core.runtime.IPath)3 HashSet (java.util.HashSet)2 List (java.util.List)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 CopyArguments (org.eclipse.ltk.core.refactoring.participants.CopyArguments)2 CopyParticipant (org.eclipse.ltk.core.refactoring.participants.CopyParticipant)2 CreateArguments (org.eclipse.ltk.core.refactoring.participants.CreateArguments)2 CreateParticipant (org.eclipse.ltk.core.refactoring.participants.CreateParticipant)2 DeleteArguments (org.eclipse.ltk.core.refactoring.participants.DeleteArguments)2 DeleteParticipant (org.eclipse.ltk.core.refactoring.participants.DeleteParticipant)2