use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class Util method getPackageFragment.
public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
if (jarSeparator != -1) {
String jarMemento = new String(fileName, 0, jarSeparator);
PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
if (pkgEnd == jarSeparator)
return root.getPackageFragment(CharOperation.NO_STRINGS);
char[] pkgName = CharOperation.subarray(fileName, jarSeparator + 1, pkgEnd);
char[][] compoundName = CharOperation.splitOn('/', pkgName);
return root.getPackageFragment(CharOperation.toStrings(compoundName));
} else {
Path path = new Path(new String(fileName, 0, pkgEnd));
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
IJavaElement element = JavaCore.create(folder);
if (element == null)
return null;
switch(element.getElementType()) {
case IJavaElement.PACKAGE_FRAGMENT:
return (IPackageFragment) element;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
case IJavaElement.JAVA_PROJECT:
PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
if (root == null)
return null;
return root.getPackageFragment(CharOperation.NO_STRINGS);
}
return null;
}
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class RenamePackageProcessor method getRefactoredResource.
//---- IResourceMapper ----------------------------------
public IResource getRefactoredResource(IResource element) {
IFolder packageFolder = (IFolder) fPackage.getResource();
if (packageFolder == null)
return element;
IContainer newPackageFolder = (IContainer) getNewPackage().getResource();
if (packageFolder.equals(element))
return newPackageFolder;
IPath packagePath = packageFolder.getProjectRelativePath();
IPath elementPath = element.getProjectRelativePath();
if (packagePath.isPrefixOf(elementPath)) {
if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) {
IPath pathInPackage = elementPath.removeFirstSegments(packagePath.segmentCount());
if (element instanceof IFile)
return newPackageFolder.getFile(pathInPackage);
else
return newPackageFolder.getFolder(pathInPackage);
}
}
return element;
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class RenameModifications method addAllResourceModifications.
private void addAllResourceModifications(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages, IPackageFragment[] allSubPackages) throws CoreException {
IFolder target = addResourceModifications(rootPackage, args, rootPackage, renameSubPackages);
if (renameSubPackages) {
IContainer container = (IContainer) rootPackage.getResource();
if (container == null)
return;
boolean removeContainer = !container.contains(target);
for (int i = 0; i < allSubPackages.length; i++) {
IPackageFragment pack = allSubPackages[i];
IFolder subTarget = addResourceModifications(rootPackage, args, pack, renameSubPackages);
if (container.contains(subTarget))
removeContainer = false;
}
if (removeContainer) {
getResourceModifications().addDelete(container);
}
}
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class ImportOperation method createFromRoot.
/**
* Creates the folders that appear in the specified resource path
* assuming that the destinationContainer begins at the root. Do not create projects.
*
* @param path the relative path of the resource
* @return the container resource coresponding to the given path
* @exception CoreException if this method failed
*/
private IContainer createFromRoot(IPath path) throws CoreException {
int segmentCount = path.segmentCount();
//Assume the project exists
IContainer currentFolder = ((IWorkspaceRoot) destinationContainer).getProject(path.segment(0));
for (int i = 1; i < segmentCount; i++) {
currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
if (!currentFolder.exists()) {
((IFolder) currentFolder).create(false, true, null);
}
}
return currentFolder;
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class AbstractResourceDescription method verifyExistence.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.ide.undo.ResourceDescription#verifyExistence(boolean)
*/
public boolean verifyExistence(boolean checkMembers) {
IContainer p = parent;
if (p == null) {
p = getWorkspace().getRoot();
}
IResource handle = p.findMember(getName());
return handle != null;
}
Aggregations