Search in sources :

Example 51 with AnalysisScope

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

the class CyclicDependenciesBuilder method analyze.

public void analyze() {
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
    getScope().accept(new PsiRecursiveElementVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            if (file instanceof PsiJavaFile) {
                PsiJavaFile psiJavaFile = (PsiJavaFile) file;
                if (getScope().contains(psiJavaFile)) {
                    final PsiPackage aPackage = findPackage(psiJavaFile.getPackageName());
                    if (aPackage != null) {
                        myPackages.put(psiJavaFile.getPackageName(), aPackage);
                    }
                }
                final Set<PsiPackage> packs = getPackageHierarhy(psiJavaFile.getPackageName());
                final ForwardDependenciesBuilder builder = new ForwardDependenciesBuilder(getProject(), new AnalysisScope(psiJavaFile));
                builder.setTotalFileCount(getScope().getFileCount());
                builder.setInitialFileCount(++myFileCount);
                builder.analyze();
                final Set<PsiFile> psiFiles = builder.getDependencies().get(psiJavaFile);
                if (psiFiles == null)
                    return;
                for (PsiPackage pack : packs) {
                    Set<PsiPackage> pack2Packages = myPackageDependencies.get(pack);
                    if (pack2Packages == null) {
                        pack2Packages = new HashSet<>();
                        myPackageDependencies.put(pack, pack2Packages);
                    }
                    for (PsiFile psiFile : psiFiles) {
                        if (!(psiFile instanceof PsiJavaFile) || !projectFileIndex.isInSourceContent(psiFile.getVirtualFile()) || !getScope().contains(psiFile)) {
                            continue;
                        }
                        // construct dependent packages
                        final String packageName = ((PsiJavaFile) psiFile).getPackageName();
                        //do not depend on parent packages
                        if (packageName.startsWith(pack.getQualifiedName())) {
                            continue;
                        }
                        final PsiPackage depPackage = findPackage(packageName);
                        if (depPackage == null) {
                            //not from analyze scope
                            continue;
                        }
                        pack2Packages.add(depPackage);
                        constractFilesInDependenciesPackagesMap(pack, depPackage, psiFile, myFilesInDependentPackages);
                        constractFilesInDependenciesPackagesMap(depPackage, pack, psiJavaFile, myBackwardFilesInDependentPackages);
                        constractWholeDependenciesMap(psiJavaFile, psiFile);
                    }
                }
            }
        }
    });
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        if (indicator.isCanceled()) {
            throw new ProcessCanceledException();
        }
        indicator.setText(AnalysisScopeBundle.message("cyclic.dependencies.progress.text"));
        indicator.setText2("");
        indicator.setIndeterminate(true);
    }
    myCyclicDependencies = getCycles(myPackages.values());
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 52 with AnalysisScope

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

the class SliceForwardTest method dotest.

private void dotest() throws Exception {
    configureByFile("/codeInsight/slice/forward/" + getTestName(false) + ".java");
    Map<String, RangeMarker> sliceUsageName2Offset = SliceTestUtil.extractSliceOffsetsFromDocument(getEditor().getDocument());
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiElement element = new SliceForwardHandler().getExpressionAtCaret(getEditor(), getFile());
    assertNotNull(element);
    SliceTestUtil.calcRealOffsets(element, sliceUsageName2Offset, myFlownOffsets);
    Collection<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.scope = new AnalysisScope(getProject());
    params.dataFlowToThis = false;
    SliceUsage usage = LanguageSlicing.getProvider(element).createRootUsage(element, params);
    SliceTestUtil.checkUsages(usage, myFlownOffsets);
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) RangeMarker(com.intellij.openapi.editor.RangeMarker) PsiElement(com.intellij.psi.PsiElement)

Example 53 with AnalysisScope

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

the class AnalyzeDependenciesOnSpecifiedTargetAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Module module = e.getData(LangDataKeys.MODULE_CONTEXT);
    final GlobalSearchScope targetScope = e.getData(TARGET_SCOPE_KEY);
    if (module == null || targetScope == null)
        return;
    new AnalyzeDependenciesOnSpecifiedTargetHandler(module.getProject(), new AnalysisScope(module), targetScope).analyze();
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 54 with AnalysisScope

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

the class BackwardDependenciesAction method analyze.

@Override
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
    //find library usages in project
    scope.setSearchInLibraries(true);
    final SearchScope selectedScope = myPanel.myCombo.getSelectedScope();
    new BackwardDependenciesHandler(project, scope, selectedScope != null ? new AnalysisScope(selectedScope, project) : new AnalysisScope(project)).analyze();
    dispose();
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 55 with AnalysisScope

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

the class DependenciesHandlerBase method perform.

private void perform(List<DependenciesBuilder> builders) {
    try {
        PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
        for (AnalysisScope scope : myScopes) {
            builders.add(createDependenciesBuilder(scope));
        }
        for (DependenciesBuilder builder : builders) {
            builder.analyze();
        }
        snapshot.logResponsivenessSinceCreation("Dependency analysis");
    } catch (IndexNotReadyException e) {
        DumbService.getInstance(myProject).showDumbModeNotification("Analyze dependencies is not available until indices are ready");
        throw new ProcessCanceledException();
    }
}
Also used : PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) AnalysisScope(com.intellij.analysis.AnalysisScope) DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

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