use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaModelOperation method deleteEmptyPackageFragment.
/**
* Convenience method to delete an empty package fragment
*/
protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, IResource rootResource) throws JavaModelException {
IContainer resource = (IContainer) ((JavaElement) fragment).resource();
try {
resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
while (resource instanceof IFolder) {
// deleting a package: delete the parent if it is empty (e.g. deleting x.y where folder x doesn't have resources but y)
// without deleting the package fragment root
resource = resource.getParent();
if (!resource.equals(rootResource) && resource.members().length == 0) {
resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
}
}
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaProject method computePackageFragmentRoots.
/**
* Returns the package fragment roots identified by the given entry. In case it refers to
* a project, it will follow its classpath so as to find exported roots as well.
* Only works with resolved entry
*
* @param resolvedEntry
* IClasspathEntry
* @param accumulatedRoots
* ObjectVector
* @param rootIDs
* HashSet
* @param referringEntry
* the CP entry (project) referring to this entry, or null if initial project
* @param retrieveExportedRoots
* boolean
* @throws JavaModelException
*/
public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {
String rootID = ((ClasspathEntry) resolvedEntry).rootID();
if (rootIDs.contains(rootID))
return;
IPath projectPath = this.project.getFullPath();
IPath entryPath = resolvedEntry.getPath();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPackageFragmentRoot root = null;
switch(resolvedEntry.getEntryKind()) {
// source folder
case IClasspathEntry.CPE_SOURCE:
if (projectPath.isPrefixOf(entryPath)) {
Object target = getTarget(entryPath, true);
if (target == null)
return;
if (target instanceof IFolder || target instanceof IProject) {
root = getPackageFragmentRoot((IResource) target);
}
}
break;
// internal/external JAR or folder
case IClasspathEntry.CPE_LIBRARY:
if (referringEntry != null && !resolvedEntry.isExported())
return;
Object target = getTarget(entryPath, true);
if (target == null)
return;
if (target instanceof IResource) {
// // internal target
root = getPackageFragmentRoot((IResource) target, entryPath);
} else if (target instanceof File) {
// external target
if (isFile(target)) {
root = new JarPackageFragmentRoot(entryPath, this);
} else if (((File) target).isDirectory()) {
// root = new ExternalPackageFragmentRoot(entryPath, this);
throw new UnsupportedOperationException();
}
}
break;
// recurse into required project
case IClasspathEntry.CPE_PROJECT:
if (!retrieveExportedRoots)
return;
if (referringEntry != null && !resolvedEntry.isExported())
return;
IResource member = workspaceRoot.findMember(entryPath);
if (member != null && member.getType() == IResource.PROJECT) {
// double check if bound to project (23977)
IProject requiredProjectRsc = (IProject) member;
if (org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(requiredProjectRsc)) {
// special builder binary output
rootIDs.add(rootID);
org.eclipse.jdt.internal.core.JavaProject requiredProject = (org.eclipse.jdt.internal.core.JavaProject) JavaCore.create(requiredProjectRsc);
requiredProject.computePackageFragmentRoots(requiredProject.getResolvedClasspath(), accumulatedRoots, rootIDs, rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map
retrieveExportedRoots, rootToResolvedEntries);
}
break;
}
}
if (root != null) {
accumulatedRoots.add(root);
rootIDs.add(rootID);
if (rootToResolvedEntries != null)
rootToResolvedEntries.put(root, ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry));
}
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class DeltaProcessor method updateRootIndex.
/*
* Updates the index of the given root (assuming it's an addition or a removal).
* This is done recusively, pkg being the current package.
*/
private void updateRootIndex(PackageFragmentRoot root, String[] pkgName, IResourceDelta delta) {
Openable pkg = root.getPackageFragment(pkgName);
updateIndex(pkg, delta);
IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
for (int i = 0, length = children.length; i < length; i++) {
IResourceDelta child = children[i];
IResource resource = child.getResource();
if (resource instanceof IFolder) {
String[] subpkgName = Util.arrayConcat(pkgName, resource.getName());
updateRootIndex(root, subpkgName, child);
}
}
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaElementResourceMapping method getPackageFragmentTraversals.
private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException {
ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
IContainer container = (IContainer) pack.getResource();
if (container != null) {
res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
if (pack.exists()) {
// folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167
Object[] nonJavaResources = pack.getNonJavaResources();
for (int i = 0; i < nonJavaResources.length; i++) {
Object resource = nonJavaResources[i];
if (resource instanceof IFolder) {
res.add(new ResourceTraversal(new IResource[] { (IResource) resource }, IResource.DEPTH_INFINITE, 0));
}
}
}
}
return res.toArray(new ResourceTraversal[res.size()]);
}
use of org.eclipse.core.resources.IFolder in project che by eclipse.
the class JavaElementResourceMapping method getRemotePackageFragmentTraversals.
private static ResourceTraversal[] getRemotePackageFragmentTraversals(IPackageFragment pack, RemoteResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
IContainer container = (IContainer) pack.getResource();
if (container != null) {
res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
IResource[] remoteMembers = context.fetchRemoteMembers(container, monitor);
if (remoteMembers == null) {
remoteMembers = context.fetchMembers(container, monitor);
}
if (remoteMembers != null) {
for (int i = 0; i < remoteMembers.length; i++) {
IResource member = remoteMembers[i];
if (member instanceof IFolder && JavaConventionsUtil.validatePackageName(member.getName(), pack).getSeverity() == IStatus.ERROR) {
res.add(new ResourceTraversal(new IResource[] { member }, IResource.DEPTH_INFINITE, 0));
}
}
}
}
return res.toArray(new ResourceTraversal[res.size()]);
}
Aggregations