use of org.eclipse.jdt.core.IPackageFragmentRoot 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.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class JavaSearchScope method encloses.
/* (non-Javadoc)
* @see IJavaSearchScope#encloses(IJavaElement)
*/
public boolean encloses(IJavaElement element) {
if (this.elements != null) {
for (int i = 0, length = this.elements.size(); i < length; i++) {
IJavaElement scopeElement = (IJavaElement) this.elements.get(i);
IJavaElement searchedElement = element;
while (searchedElement != null) {
if (searchedElement.equals(scopeElement))
return true;
searchedElement = searchedElement.getParent();
}
}
return false;
}
IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (root != null && root.isArchive()) {
// external or internal jar
IPath rootPath = root.getPath();
String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString();
IPath relativePath = getPath(element, true);
return indexOf(rootPathToString, relativePath.toString()) >= 0;
}
// resource in workspace
String fullResourcePathString = getPath(element, false).toString();
return indexOf(fullResourcePathString) >= 0;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class JavaModelManager method secondaryTypesSearching.
/*
* Perform search request to get all secondary types of a given project.
* If not waiting for indexes and indexing is running, will return types found in current built indexes...
*/
private Map secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException {
if (VERBOSE || BasicSearchEngine.VERBOSE) {
//$NON-NLS-1$
StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypesSearch(");
buffer.append(project.getElementName());
buffer.append(',');
buffer.append(waitForIndexes);
buffer.append(')');
Util.verbose(buffer.toString());
}
final Hashtable secondaryTypes = new Hashtable(3);
IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() {
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
//$NON-NLS-1$
String key = packageName == null ? "" : new String(packageName);
HashMap types = (HashMap) secondaryTypes.get(key);
if (types == null)
types = new HashMap(3);
types.put(new String(simpleTypeName), path);
secondaryTypes.put(key, types);
}
};
// Build scope using prereq projects but only source folders
IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots();
int length = allRoots.length, size = 0;
IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length];
for (int i = 0; i < length; i++) {
if (allRoots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
allSourceFolders[size++] = allRoots[i];
}
}
if (size < length) {
System.arraycopy(allSourceFolders, 0, allSourceFolders = new IPackageFragmentRoot[size], 0, size);
}
// Search all secondary types on scope
new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, waitForIndexes, monitor);
// Build types from paths
Iterator packages = secondaryTypes.values().iterator();
while (packages.hasNext()) {
HashMap types = (HashMap) packages.next();
HashMap tempTypes = new HashMap(types.size());
Iterator names = types.entrySet().iterator();
while (names.hasNext()) {
Map.Entry entry = (Map.Entry) names.next();
String typeName = (String) entry.getKey();
String path = (String) entry.getValue();
names.remove();
if (Util.isJavaLikeFileName(path)) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
ICompilationUnit unit = org.eclipse.jdt.internal.core.JavaModelManager.createCompilationUnitFrom(file, null);
IType type = unit.getType(typeName);
tempTypes.put(typeName, type);
}
}
types.putAll(tempTypes);
}
// Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...)
if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES) != null) {
projectInfo.secondaryTypes = secondaryTypes;
if (VERBOSE || BasicSearchEngine.VERBOSE) {
//$NON-NLS-1$
System.out.print(Thread.currentThread() + " -> secondary paths stored in cache: ");
System.out.println();
Iterator entries = secondaryTypes.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String qualifiedName = (String) entry.getKey();
//$NON-NLS-1$
Util.verbose(" - " + qualifiedName + '-' + entry.getValue());
}
}
}
return projectInfo.secondaryTypes;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class JavaProject method computePackageFragmentRoots.
/**
* Returns (local/all) the package fragment roots identified by the given project's classpath.
* Note: this follows project classpath references to find required project contributions,
* eliminating duplicates silently.
* Only works with resolved entries
*
* @param resolvedClasspath
* IClasspathEntry[]
* @param retrieveExportedRoots
* boolean
* @return IPackageFragmentRoot[]
* @throws JavaModelException
*/
public IPackageFragmentRoot[] computePackageFragmentRoots(IClasspathEntry[] resolvedClasspath, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {
ObjectVector accumulatedRoots = new ObjectVector();
computePackageFragmentRoots(resolvedClasspath, accumulatedRoots, // rootIDs
new HashSet(5), // inside original project
null, retrieveExportedRoots, rootToResolvedEntries);
IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[accumulatedRoots.size()];
accumulatedRoots.copyInto(rootArray);
return rootArray;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot 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));
}
}
Aggregations