Search in sources :

Example 1 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<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 2 with MoveArguments

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

the class MoveModifications method move.

public void move(IPackageFragment pack, MoveArguments args) throws CoreException {
    add(pack, args, null);
    if (pack.getResource() == null)
        return;
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) args.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    if (!pack.hasSubpackages() && !newPack.exists()) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addMove(pack.getResource(), new MoveArguments(resourceDestination, args.getUpdateReferences()));
    } else {
        IContainer resourceSource = (IContainer) pack.getResource();
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        MoveArguments arguments = new MoveArguments(resourceDestination, args.getUpdateReferences());
        IResource[] resourcesToMove = collectResourcesOfInterest(pack);
        Set<IResource> allMembers = new HashSet<IResource>(Arrays.asList(resourceSource.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 (allMembers.isEmpty()) {
            getResourceModifications().addDelete(resourceSource);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) 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) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) HashSet(java.util.HashSet)

Example 3 with MoveArguments

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

the class MoveModifications method move.

public void move(IPackageFragmentRoot sourceFolder, MoveArguments arguments) {
    add(sourceFolder, arguments, null);
    IResource sourceResource = sourceFolder.getResource();
    if (sourceResource != null) {
        getResourceModifications().addMove(sourceResource, new MoveArguments(getResourceDestination(arguments), arguments.getUpdateReferences()));
        IFile classpath = getClasspathFile(sourceResource);
        if (classpath != null) {
            getResourceModifications().addChanged(classpath);
        }
        classpath = getClasspathFile(getResourceDestination(arguments));
        if (classpath != null) {
            getResourceModifications().addChanged(classpath);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IResource(org.eclipse.core.resources.IResource)

Example 4 with MoveArguments

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

the class MoveResourcesProcessor method checkFinalConditions.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
	 */
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        RefactoringStatus status = validateDestination(fDestination);
        if (status.hasFatalError()) {
            return status;
        }
        fMoveArguments = new MoveArguments(fDestination, isUpdateReferences());
        ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
        IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
        for (int i = 0; i < fResourcesToMove.length; i++) {
            IResource resource = fResourcesToMove[i];
            IResource newResource = fDestination.findMember(resource.getName());
            if (newResource != null) {
                status.addWarning(Messages.format(RefactoringCoreMessages.MoveResourcesProcessor_warning_destination_already_exists, BasicElementLabels.getPathLabel(newResource.getFullPath(), false)));
                deltaFactory.delete(newResource);
            }
            ResourceModifications.buildMoveDelta(deltaFactory, fResourcesToMove[i], fMoveArguments);
        }
        return status;
    } finally {
        pm.done();
    }
}
Also used : MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResourceChangeDescriptionFactory(org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory) IResource(org.eclipse.core.resources.IResource) ResourceChangeChecker(org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker)

Example 5 with MoveArguments

use of org.eclipse.ltk.core.refactoring.participants.MoveArguments 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

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