use of org.eclipse.core.resources.IResource in project che by eclipse.
the class CopyModifications method copy.
public void copy(IPackageFragment pack, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
add(pack, javaArgs, null);
ResourceMapping mapping = JavaElementResourceMapping.create(pack);
if (mapping != null) {
add(mapping, resourceArgs, null);
}
IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) javaArgs.getDestination();
if (javaDestination.getResource() == null)
return;
IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
// the new name yet, so we use the current package name.
if (!pack.hasSubpackages() && (!newPack.exists() || pack.equals(newPack))) {
// we can do a simple move
IContainer resourceDestination = newPack.getResource().getParent();
createIncludingParents(resourceDestination);
getResourceModifications().addCopyDelta(pack.getResource(), resourceArgs);
} else {
IContainer resourceDestination = (IContainer) newPack.getResource();
createIncludingParents(resourceDestination);
CopyArguments arguments = new CopyArguments(resourceDestination, resourceArgs.getExecutionLog());
IResource[] resourcesToCopy = collectResourcesOfInterest(pack);
for (int i = 0; i < resourcesToCopy.length; i++) {
IResource toCopy = resourcesToCopy[i];
getResourceModifications().addCopyDelta(toCopy, arguments);
}
}
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class CreateCopyOfCompilationUnitChange method setEncoding.
private void setEncoding(ICompilationUnit unit) {
IResource resource = unit.getResource();
// no file so the encoding is taken from the target
if (!(resource instanceof IFile))
return;
IFile file = (IFile) resource;
try {
String encoding = file.getCharset(false);
if (encoding != null) {
setEncoding(encoding, true);
} else {
encoding = file.getCharset(true);
if (encoding != null) {
setEncoding(encoding, false);
}
}
} catch (CoreException e) {
// Take encoding from target
}
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class DeleteChangeCreator method createPackageFragmentRootDeleteChange.
private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root) throws JavaModelException {
IResource resource = root.getResource();
if (resource != null && resource.isLinked()) {
//XXX using this code is a workaround for jcore bug 31998
//jcore cannot handle linked stuff
//normally, we should always create DeletePackageFragmentRootChange
CompositeChange composite = new DynamicValidationStateChange(RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root);
ClasspathChange change = ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry());
if (change != null) {
composite.add(change);
}
//checked in preconditions
Assert.isTrue(!Checks.isClasspathDelete(root));
composite.add(createDeleteChange(resource));
return composite;
} else {
Assert.isTrue(!root.isExternal());
// TODO remove the query argument
return new DeletePackageFragmentRootChange(root, true, null);
}
}
use of org.eclipse.core.resources.IResource 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.core.resources.IResource 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);
}
}
}
Aggregations