use of org.eclipse.core.resources.IResource in project che by eclipse.
the class JavaSearchScope method packageFragmentRoot.
/**
* @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
*/
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
int index = -1;
boolean isJarFile = jarSeparatorIndex != -1;
if (isJarFile) {
// internal or external jar (case 3, 4, or 5)
String relativePath = resourcePathString.substring(jarSeparatorIndex + 1);
index = indexOf(jarPath, relativePath);
} else {
// resource in workspace (case 1 or 2)
index = indexOf(resourcePathString);
}
if (index >= 0) {
int idx = this.projectIndexes[index];
String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx);
if (projectPath != null) {
IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath));
if (isJarFile) {
IResource resource = JavaModel.getWorkspaceTarget(new Path(jarPath));
if (resource != null)
return project.getPackageFragmentRoot(resource);
return project.getPackageFragmentRoot(jarPath);
}
Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index] + '/' + this.relativePaths[index]));
if (target != null) {
if (target instanceof IProject) {
return project.getPackageFragmentRoot((IProject) target);
}
IJavaElement element = JavaModelManager.create((IResource) target, project);
return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
}
}
}
return null;
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class JavaSearchScope method add.
/**
* Add an element to the java search scope.
* @param element The element we want to add to current java search scope
* @throws JavaModelException May happen if some Java Model info are not available
*/
public void add(IJavaElement element) throws JavaModelException {
IPath containerPath = null;
String containerPathToString = null;
PackageFragmentRoot root = null;
int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
switch(element.getElementType()) {
case IJavaElement.JAVA_MODEL:
// a workspace sope should be used
break;
case IJavaElement.JAVA_PROJECT:
add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
root = (PackageFragmentRoot) element;
IPath rootPath = root.internalPath();
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
IResource rootResource = root.resource();
String projectPath = root.getJavaProject().getPath().toString();
if (rootResource != null && rootResource.isAccessible()) {
String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
add(projectPath, relativePath, containerPathToString, false, /*not a package*/
null);
} else {
//$NON-NLS-1$
add(projectPath, "", containerPathToString, false, /*not a package*/
null);
}
break;
case IJavaElement.PACKAGE_FRAGMENT:
root = (PackageFragmentRoot) element.getParent();
projectPath = root.getJavaProject().getPath().toString();
if (root.isArchive()) {
String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
containerPath = root.getPath();
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, true, /*package*/
null);
} else {
IResource resource = ((JavaElement) element).resource();
if (resource != null) {
if (resource.isAccessible()) {
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
} else {
// for working copies, get resource container full path
containerPath = resource.getParent().getFullPath();
}
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
add(projectPath, relativePath, containerPathToString, true, /*package*/
null);
}
}
break;
default:
// remember sub-cu (or sub-class file) java elements
if (element instanceof IMember) {
if (this.elements == null) {
this.elements = new ArrayList();
}
this.elements.add(element);
}
root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
projectPath = root.getJavaProject().getPath().toString();
String relativePath;
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
containerPath = root.getParent().getPath();
relativePath = Util.relativePath(getPath(element, false), root.getJavaProject().getPath().segmentCount());
} else {
containerPath = root.internalPath();
relativePath = getPath(element, true).toString();
}
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, false, /*not a package*/
null);
}
if (root != null)
addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class JavaModelManager method resolveVariableEntry.
public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) {
if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
return entry;
IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession);
if (resolvedPath == null)
return null;
// By passing a null reference path, we keep it relative to workspace root.
resolvedPath = ClasspathEntry.resolveDotDot(null, resolvedPath);
Object target = org.eclipse.jdt.internal.core.JavaModel.getTarget(resolvedPath, false);
if (target == null)
return null;
// inside the workspace
if (target instanceof IResource) {
IResource resolvedResource = (IResource) target;
switch(resolvedResource.getType()) {
case IResource.PROJECT:
// internal project
return JavaCore.newProjectEntry(resolvedPath, entry.getAccessRules(), entry.combineAccessRules(), entry.getExtraAttributes(), entry.isExported());
case IResource.FILE:
// internal binary archive
return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
case IResource.FOLDER:
// internal binary folder
return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
}
}
if (target instanceof File) {
File externalFile = JavaModel.getFile(target);
if (externalFile != null) {
// external binary archive
return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
} else {
// non-existing file
if (resolvedPath.isAbsolute()) {
return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
}
}
}
return null;
}
use of org.eclipse.core.resources.IResource 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.IResource in project che by eclipse.
the class DeltaProcessor method popUntilPrefixOf.
private void popUntilPrefixOf(IPath path) {
while (this.currentElement != null) {
IPath currentElementPath = null;
if (this.currentElement instanceof IPackageFragmentRoot) {
currentElementPath = ((IPackageFragmentRoot) this.currentElement).getPath();
} else {
IResource currentElementResource = this.currentElement.resource();
if (currentElementResource != null) {
currentElementPath = currentElementResource.getFullPath();
}
}
if (currentElementPath != null) {
if (this.currentElement instanceof IPackageFragment && ((IPackageFragment) this.currentElement).isDefaultPackage() && currentElementPath.segmentCount() != path.segmentCount() - 1) {
// default package and path is not a direct child
this.currentElement = (Openable) this.currentElement.getParent();
}
if (currentElementPath.isPrefixOf(path)) {
return;
}
}
this.currentElement = (Openable) this.currentElement.getParent();
}
}
Aggregations