use of org.eclipse.jdt.internal.compiler.env.AccessRestriction 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;
}
Aggregations