Search in sources :

Example 1 with AccessRestriction

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AccessRestriction(org.eclipse.jdt.internal.compiler.env.AccessRestriction) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Hashtable(java.util.Hashtable) IRestrictedAccessTypeRequestor(org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor) BasicSearchEngine(org.eclipse.jdt.internal.core.search.BasicSearchEngine) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IType(org.eclipse.jdt.core.IType) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Aggregations

HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 IType (org.eclipse.jdt.core.IType)1 AccessRestriction (org.eclipse.jdt.internal.compiler.env.AccessRestriction)1 BasicSearchEngine (org.eclipse.jdt.internal.core.search.BasicSearchEngine)1 IRestrictedAccessTypeRequestor (org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor)1