Search in sources :

Example 11 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class GlobalJavaInspectionContextImpl method processSearchRequests.

private void processSearchRequests(final GlobalInspectionContext context) {
    final RefManager refManager = context.getRefManager();
    final AnalysisScope scope = refManager.getScope();
    final SearchScope searchScope = new GlobalSearchScope(refManager.getProject()) {

        @Override
        public boolean contains(@NotNull VirtualFile file) {
            return scope != null && !scope.contains(file) || file.getFileType() != StdFileTypes.JAVA;
        }

        @Override
        public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
            return 0;
        }

        @Override
        public boolean isSearchInModuleContent(@NotNull Module aModule) {
            return true;
        }

        @Override
        public boolean isSearchInLibraries() {
            return false;
        }
    };
    if (myDerivedClassesRequests != null) {
        final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myDerivedClassesRequests);
        for (SmartPsiElementPointer sortedID : sortedIDs) {
            final PsiClass psiClass = (PsiClass) dereferenceInReadAction(sortedID);
            if (psiClass == null)
                continue;
            context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, getClassPresentableName(psiClass));
            final List<DerivedClassesProcessor> processors = myDerivedClassesRequests.get(sortedID);
            LOG.assertTrue(processors != null, psiClass.getClass().getName());
            ClassInheritorsSearch.search(psiClass, searchScope, false).forEach(createMembersProcessor(processors, scope));
        }
        myDerivedClassesRequests = null;
    }
    if (myDerivedMethodsRequests != null) {
        final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myDerivedMethodsRequests);
        for (SmartPsiElementPointer sortedID : sortedIDs) {
            final PsiMethod psiMethod = (PsiMethod) dereferenceInReadAction(sortedID);
            if (psiMethod == null)
                continue;
            final RefMethod refMethod = (RefMethod) refManager.getReference(psiMethod);
            context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refMethod));
            final List<DerivedMethodsProcessor> processors = myDerivedMethodsRequests.get(sortedID);
            LOG.assertTrue(processors != null, psiMethod.getClass().getName());
            OverridingMethodsSearch.search(psiMethod, searchScope, true).forEach(createMembersProcessor(processors, scope));
        }
        myDerivedMethodsRequests = null;
    }
    if (myFieldUsagesRequests != null) {
        final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myFieldUsagesRequests);
        for (SmartPsiElementPointer sortedID : sortedIDs) {
            final PsiField psiField = (PsiField) dereferenceInReadAction(sortedID);
            if (psiField == null)
                continue;
            final List<UsagesProcessor> processors = myFieldUsagesRequests.get(sortedID);
            LOG.assertTrue(processors != null, psiField.getClass().getName());
            context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refManager.getReference(psiField)));
            ReferencesSearch.search(psiField, searchScope, false).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
        }
        myFieldUsagesRequests = null;
    }
    if (myClassUsagesRequests != null) {
        final List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myClassUsagesRequests);
        for (SmartPsiElementPointer sortedID : sortedIDs) {
            final PsiClass psiClass = (PsiClass) dereferenceInReadAction(sortedID);
            if (psiClass == null)
                continue;
            final List<UsagesProcessor> processors = myClassUsagesRequests.get(sortedID);
            LOG.assertTrue(processors != null, psiClass.getClass().getName());
            context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, getClassPresentableName(psiClass));
            ReferencesSearch.search(psiClass, searchScope, false).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
        }
        myClassUsagesRequests = null;
    }
    if (myMethodUsagesRequests != null) {
        List<SmartPsiElementPointer> sortedIDs = getSortedIDs(myMethodUsagesRequests);
        for (SmartPsiElementPointer sortedID : sortedIDs) {
            final PsiMethod psiMethod = (PsiMethod) dereferenceInReadAction(sortedID);
            if (psiMethod == null)
                continue;
            final List<UsagesProcessor> processors = myMethodUsagesRequests.get(sortedID);
            LOG.assertTrue(processors != null, psiMethod.getClass().getName());
            context.incrementJobDoneAmount(context.getStdJobDescriptors().FIND_EXTERNAL_USAGES, refManager.getQualifiedName(refManager.getReference(psiMethod)));
            MethodReferencesSearch.search(psiMethod, searchScope, true).forEach(new PsiReferenceProcessorAdapter(createReferenceProcessor(processors, context)));
        }
        myMethodUsagesRequests = null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) AnalysisScope(com.intellij.analysis.AnalysisScope) Module(com.intellij.openapi.module.Module)

Example 12 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class CyclicDependenciesAction method getInspectionScope.

@Nullable
private static AnalysisScope getInspectionScope(final DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return null;
    AnalysisScope scope = getInspectionScopeImpl(dataContext);
    return scope != null && scope.getScopeType() != AnalysisScope.INVALID ? scope : null;
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class CyclicDependenciesAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    if (project != null) {
        AnalysisScope scope = getInspectionScope(dataContext);
        if (scope == null || scope.getScopeType() != AnalysisScope.MODULES) {
            ProjectModuleOrPackageDialog dlg = null;
            if (module != null) {
                dlg = new ProjectModuleOrPackageDialog(ModuleManager.getInstance(project).getModules().length == 1 ? null : ModuleUtilCore.getModuleNameInReadAction(module), scope);
                if (!dlg.showAndGet()) {
                    return;
                }
            }
            if (dlg == null || dlg.isProjectScopeSelected()) {
                scope = getProjectScope(dataContext);
            } else {
                if (dlg.isModuleScopeSelected()) {
                    scope = getModuleScope(dataContext);
                }
            }
            if (scope != null) {
                scope.setIncludeTestSource(dlg != null && dlg.isIncludeTestSources());
            }
        }
        FileDocumentManager.getInstance().saveAllDocuments();
        new CyclicDependenciesHandler(project, scope).analyze();
    }
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Example 14 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class CyclicDependenciesAction method getInspectionScopeImpl.

@Nullable
private static AnalysisScope getInspectionScopeImpl(DataContext dataContext) {
    //Possible scopes: package, project, module.
    Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
    if (projectContext != null) {
        return null;
    }
    Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    if (moduleContext != null) {
        return null;
    }
    final Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    if (modulesArray != null && modulesArray.length > 0) {
        return new AnalysisScope(modulesArray);
    }
    PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (psiTarget instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) psiTarget;
        if (!psiDirectory.getManager().isInProject(psiDirectory))
            return null;
        return new AnalysisScope(psiDirectory);
    } else if (psiTarget instanceof PsiPackage) {
        PsiPackage pack = (PsiPackage) psiTarget;
        PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject()));
        if (dirs.length == 0)
            return null;
        return new JavaAnalysisScope(pack, LangDataKeys.MODULE.getData(dataContext));
    }
    return null;
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) Project(com.intellij.openapi.project.Project) JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with AnalysisScope

use of com.intellij.analysis.AnalysisScope in project intellij-community by JetBrains.

the class UsageContextDataflowToPanel method createParams.

@NotNull
private static SliceAnalysisParams createParams(PsiElement element, boolean dataFlowToThis) {
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.scope = new AnalysisScope(element.getProject());
    params.dataFlowToThis = dataFlowToThis;
    params.showInstanceDereferences = true;
    return params;
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AnalysisScope (com.intellij.analysis.AnalysisScope)56 Module (com.intellij.openapi.module.Module)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 Project (com.intellij.openapi.project.Project)12 NotNull (org.jetbrains.annotations.NotNull)10 PsiPackage (com.intellij.psi.PsiPackage)8 File (java.io.File)8 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)7 PsiElement (com.intellij.psi.PsiElement)6 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)6 Nullable (org.jetbrains.annotations.Nullable)6 AnalysisUIOptions (com.intellij.analysis.AnalysisUIOptions)5 BaseAnalysisActionDialog (com.intellij.analysis.BaseAnalysisActionDialog)5 PsiFile (com.intellij.psi.PsiFile)4 SearchScope (com.intellij.psi.search.SearchScope)4 HashMap (com.intellij.util.containers.HashMap)4 LintDriver (com.android.tools.lint.client.api.LintDriver)3 LintRequest (com.android.tools.lint.client.api.LintRequest)3 Issue (com.android.tools.lint.detector.api.Issue)3