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));
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot 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();
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testImportToStar.
@Test
public void testImportToStar() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class List {\n");
buf.append("}\n");
pack2.createCompilationUnit("List.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.Set;\n");
buf.append("import java.util.Vector;\n");
buf.append("import java.util.Map;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 2, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations