Search in sources :

Example 6 with EverythingGlobalScope

use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.

the class PsiPackageImpl method getCachedClassesByName.

@NotNull
private PsiClass[] getCachedClassesByName(@NotNull String name, GlobalSearchScope scope) {
    if (DumbService.getInstance(getProject()).isDumb()) {
        return getCachedClassInDumbMode(name, scope);
    }
    Map<String, PsiClass[]> map = SoftReference.dereference(myClassCache);
    if (map == null) {
        myClassCache = new SoftReference<>(map = ContainerUtil.createConcurrentSoftValueMap());
    }
    PsiClass[] classes = map.get(name);
    if (classes != null) {
        return classes;
    }
    final String qName = getQualifiedName();
    final String classQName = !qName.isEmpty() ? qName + "." + name : name;
    map.put(name, classes = getFacade().findClasses(classQName, new EverythingGlobalScope(getProject())));
    return classes;
}
Also used : EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with EverythingGlobalScope

use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.

the class JavaDocInfoGenerator method generatePackageJavaDoc.

private void generatePackageJavaDoc(final StringBuilder buffer, final PsiPackage psiPackage, boolean generatePrologueAndEpilogue) {
    for (PsiDirectory directory : psiPackage.getDirectories(new EverythingGlobalScope(myProject))) {
        final PsiFile packageInfoFile = directory.findFile(PsiPackage.PACKAGE_INFO_FILE);
        if (packageInfoFile != null) {
            final ASTNode node = packageInfoFile.getNode();
            if (node != null) {
                final ASTNode docCommentNode = findRelevantCommentNode(node);
                if (docCommentNode != null) {
                    if (generatePrologueAndEpilogue)
                        generatePrologue(buffer);
                    generateCommonSection(buffer, (PsiDocComment) docCommentNode.getPsi());
                    if (generatePrologueAndEpilogue)
                        generateEpilogue(buffer);
                    break;
                }
            }
        }
        PsiFile packageHtmlFile = directory.findFile("package.html");
        if (packageHtmlFile != null) {
            generatePackageHtmlJavaDoc(buffer, packageHtmlFile, generatePrologueAndEpilogue);
            break;
        }
    }
}
Also used : EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope) ASTNode(com.intellij.lang.ASTNode)

Example 8 with EverythingGlobalScope

use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.

the class LineBreakpoint method isInScopeOf.

private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
    final SourcePosition position = getSourcePosition();
    if (position != null) {
        final VirtualFile breakpointFile = position.getFile().getVirtualFile();
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
        if (breakpointFile != null && fileIndex.isUnderSourceRootOfType(breakpointFile, JavaModuleSourceRootTypes.SOURCES)) {
            if (debugProcess.getSearchScope().contains(breakpointFile)) {
                return true;
            }
            // apply filtering to breakpoints from content sources only, not for sources attached to libraries
            final Collection<VirtualFile> candidates = findClassCandidatesInSourceContent(className, debugProcess.getSearchScope(), fileIndex);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found " + (candidates == null ? "null" : candidates.size()) + " candidate containing files for class " + className);
            }
            if (candidates == null) {
                // If no candidates are found in scope then assume that class is loaded dynamically and allow breakpoint
                return true;
            }
            //}
            if (LOG.isDebugEnabled()) {
                final GlobalSearchScope scope = debugProcess.getSearchScope();
                final boolean contains = scope.contains(breakpointFile);
                List<VirtualFile> files = ContainerUtil.map(JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, scope), aClass -> aClass.getContainingFile().getVirtualFile());
                List<VirtualFile> allFiles = ContainerUtil.map(JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, new EverythingGlobalScope(myProject)), aClass -> aClass.getContainingFile().getVirtualFile());
                final VirtualFile contentRoot = fileIndex.getContentRootForFile(breakpointFile);
                final Module module = fileIndex.getModuleForFile(breakpointFile);
                LOG.debug("Did not find '" + className + "' in " + scope + "; contains=" + contains + "; contentRoot=" + contentRoot + "; module = " + module + "; all files in index are: " + files + "; all possible files are: " + allFiles);
            }
            return false;
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope) Module(com.intellij.openapi.module.Module)

Example 9 with EverythingGlobalScope

use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.

the class GradleClassFinder method findClass.

@Override
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
    PsiClass aClass = super.findClass(qualifiedName, scope);
    if (aClass == null || scope instanceof ExternalModuleBuildGlobalSearchScope || scope instanceof EverythingGlobalScope) {
        return aClass;
    }
    PsiFile containingFile = aClass.getContainingFile();
    VirtualFile file = containingFile != null ? containingFile.getVirtualFile() : null;
    return (file != null && !ProjectFileIndex.SERVICE.getInstance(myProject).isInContent(file) && !ProjectFileIndex.SERVICE.getInstance(myProject).isInLibraryClasses(file) && !ProjectFileIndex.SERVICE.getInstance(myProject).isInLibrarySource(file)) ? aClass : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClass(com.intellij.psi.PsiClass) EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope) PsiFile(com.intellij.psi.PsiFile) ExternalModuleBuildGlobalSearchScope(com.intellij.openapi.externalSystem.psi.search.ExternalModuleBuildGlobalSearchScope)

Aggregations

EverythingGlobalScope (com.intellij.psi.search.EverythingGlobalScope)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Module (com.intellij.openapi.module.Module)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 NotNull (org.jetbrains.annotations.NotNull)2 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)1 XmlTagInsertHandler (com.intellij.codeInsight.completion.XmlTagInsertHandler)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 SourcePosition (com.intellij.debugger.SourcePosition)1 ASTNode (com.intellij.lang.ASTNode)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 ExternalModuleBuildGlobalSearchScope (com.intellij.openapi.externalSystem.psi.search.ExternalModuleBuildGlobalSearchScope)1 Project (com.intellij.openapi.project.Project)1 PsiClass (com.intellij.psi.PsiClass)1 PsiFile (com.intellij.psi.PsiFile)1