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()]);
}
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);
}
}
}
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);
}
}
}
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();
}
}
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();
}
Aggregations