Search in sources :

Example 86 with GlobalSearchScope

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

the class CouplingVisitor method addDependency.

private void addDependency(PsiType type) {
    if (type == null) {
        return;
    }
    final PsiType baseType = type.getDeepComponentType();
    if (ClassUtils.isPrimitive(type)) {
        return;
    }
    final String qualifiedName = m_class.getQualifiedName();
    if (qualifiedName == null) {
        return;
    }
    if (baseType.equalsToText(qualifiedName)) {
        return;
    }
    final String baseTypeName = baseType.getCanonicalText();
    @NonNls final String javaPrefix = "java.";
    @NonNls final String javaxPrefix = "javax.";
    if (!m_includeJavaClasses && (baseTypeName.startsWith(javaPrefix) || baseTypeName.startsWith(javaxPrefix))) {
        return;
    }
    if (!m_includeLibraryClasses) {
        final Project project = m_class.getProject();
        final GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
        final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(baseTypeName, searchScope);
        if (aClass == null) {
            return;
        }
        if (LibraryUtil.classIsInLibrary(aClass)) {
            return;
        }
    }
    if (StringUtil.startsWithConcatenation(baseTypeName, qualifiedName, ".")) {
        return;
    }
    m_dependencies.add(baseTypeName);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 87 with GlobalSearchScope

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

the class JavaCoverageViewExtension method createTopLevelNodes.

@Override
public List<AbstractTreeNode> createTopLevelNodes() {
    final List<AbstractTreeNode> topLevelNodes = new ArrayList<>();
    final LinkedHashSet<PsiPackage> packages = new LinkedHashSet<>();
    final LinkedHashSet<PsiClass> classes = new LinkedHashSet<>();
    for (CoverageSuite suite : mySuitesBundle.getSuites()) {
        packages.addAll(((JavaCoverageSuite) suite).getCurrentSuitePackages(myProject));
        classes.addAll(((JavaCoverageSuite) suite).getCurrentSuiteClasses(myProject));
    }
    final Set<PsiPackage> packs = new HashSet<>();
    for (PsiPackage aPackage : packages) {
        final String qualifiedName = aPackage.getQualifiedName();
        for (PsiPackage psiPackage : packages) {
            if (psiPackage.getQualifiedName().startsWith(qualifiedName + ".")) {
                packs.add(psiPackage);
                break;
            }
        }
    }
    packages.removeAll(packs);
    for (PsiPackage aPackage : packages) {
        final GlobalSearchScope searchScope = mySuitesBundle.getSearchScope(myProject);
        if (aPackage.getClasses(searchScope).length != 0) {
            final CoverageListNode node = new CoverageListNode(myProject, aPackage, mySuitesBundle, myStateBean);
            topLevelNodes.add(node);
        }
        collectSubPackages(topLevelNodes, aPackage);
    }
    for (PsiClass aClass : classes) {
        topLevelNodes.add(new CoverageListNode(myProject, aClass, mySuitesBundle, myStateBean));
    }
    return topLevelNodes;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 88 with GlobalSearchScope

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

the class CoverageProjectViewClassNodeDecorator method decorate.

public void decorate(ProjectViewNode node, PresentationData data) {
    final CoverageDataManager coverageDataManager = getCoverageDataManager();
    final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
    final Project project = node.getProject();
    final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
    // This decorator is applicable only to JavaCoverageAnnotator
    if (javaCovAnnotator == null) {
        return;
    }
    final Object value = node.getValue();
    PsiElement element = null;
    if (value instanceof PsiElement) {
        element = (PsiElement) value;
    } else if (value instanceof SmartPsiElementPointer) {
        element = ((SmartPsiElementPointer) value).getElement();
    } else if (value instanceof PackageElement) {
        PackageElement packageElement = (PackageElement) value;
        final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(), packageElement.getModule(), coverageDataManager);
        data.setLocationString(coverageString);
    }
    if (element instanceof PsiClass) {
        final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
        final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
        if (vFile != null && searchScope.contains(vFile)) {
            final String qName = ((PsiClass) element).getQualifiedName();
            if (qName != null) {
                data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiClass(com.intellij.psi.PsiClass) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) PsiElement(com.intellij.psi.PsiElement)

Example 89 with GlobalSearchScope

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

the class JavaCoverageEngine method findTestsByNames.

@NotNull
public List<PsiElement> findTestsByNames(@NotNull String[] testNames, @NotNull Project project) {
    final List<PsiElement> elements = new ArrayList<>();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
    for (String testName : testNames) {
        PsiClass psiClass = facade.findClass(StringUtil.getPackageName(testName, '_').replaceAll("\\_", "\\."), projectScope);
        int lastIdx = testName.lastIndexOf("_");
        if (psiClass != null) {
            collectTestsByName(elements, testName, psiClass, lastIdx);
        } else {
            String className = testName;
            while (lastIdx > 0) {
                className = className.substring(0, lastIdx - 1);
                psiClass = facade.findClass(StringUtil.getPackageName(className, '_').replaceAll("\\_", "\\."), projectScope);
                lastIdx = className.lastIndexOf("_");
                if (psiClass != null) {
                    collectTestsByName(elements, testName, psiClass, lastIdx);
                    break;
                }
            }
        }
    }
    return elements;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with GlobalSearchScope

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

the class LanguageResolvingUtil method collectLanguageDefinitions.

private static List<LanguageDefinition> collectLanguageDefinitions(final ConvertContext context) {
    final Project project = context.getProject();
    final Collection<PsiClass> allLanguages = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
        final PsiClass languageClass = JavaPsiFacade.getInstance(project).findClass(Language.class.getName(), GlobalSearchScope.allScope(project));
        if (languageClass == null) {
            return Result.create(Collections.emptyList(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
        }
        final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project);
        GlobalSearchScope allScope = projectProductionScope.union(ProjectScope.getLibrariesScope(project));
        final Collection<PsiClass> allInheritors = ClassInheritorsSearch.search(languageClass, allScope, true).findAll();
        return Result.create(allInheritors, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    });
    if (allLanguages.isEmpty()) {
        return Collections.emptyList();
    }
    final List<LanguageDefinition> libraryDefinitions = collectLibraryLanguages(context, allLanguages);
    final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project);
    final Collection<PsiClass> projectLanguages = ContainerUtil.filter(allLanguages, aClass -> PsiSearchScopeUtil.isInScope(projectProductionScope, aClass));
    final List<LanguageDefinition> projectDefinitions = collectProjectLanguages(projectLanguages, libraryDefinitions);
    final List<LanguageDefinition> all = ContainerUtil.newArrayList(libraryDefinitions);
    all.addAll(projectDefinitions);
    return all;
}
Also used : Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) DependentLanguage(com.intellij.lang.DependentLanguage) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)485 Project (com.intellij.openapi.project.Project)145 NotNull (org.jetbrains.annotations.NotNull)134 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 Module (com.intellij.openapi.module.Module)101 Nullable (org.jetbrains.annotations.Nullable)78 PsiClass (com.intellij.psi.PsiClass)53 ArrayList (java.util.ArrayList)37 PsiFile (com.intellij.psi.PsiFile)32 PsiElement (com.intellij.psi.PsiElement)31 THashSet (gnu.trove.THashSet)22 SearchScope (com.intellij.psi.search.SearchScope)19 PsiDirectory (com.intellij.psi.PsiDirectory)18 ContainerUtil (com.intellij.util.containers.ContainerUtil)18 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)17 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)17 com.intellij.psi (com.intellij.psi)17 List (java.util.List)17 StringUtil (com.intellij.openapi.util.text.StringUtil)15 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)15