Search in sources :

Example 1 with ForwardDependenciesBuilder

use of com.intellij.packageDependencies.ForwardDependenciesBuilder in project intellij-community by JetBrains.

the class DependenciesPanelTest method doTestDependenciesTrees.

private void doTestDependenciesTrees(AnalysisScope scope, String expectedLeftTree, String expectedRightTree) {
    DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, scope);
    builder.analyze();
    DependenciesPanel dependenciesPanel = new DependenciesPanel(myProject, builder);
    try {
        JTree leftTree = dependenciesPanel.getLeftTree();
        TreeUtil.expandAll(leftTree);
        PlatformTestUtil.assertTreeEqual(leftTree, expectedLeftTree, true);
        JTree rightTree = dependenciesPanel.getRightTree();
        TreeUtil.expandAll(rightTree);
        PlatformTestUtil.assertTreeEqual(rightTree, expectedRightTree, true);
    } finally {
        Disposer.dispose(dependenciesPanel);
    }
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) DependenciesPanel(com.intellij.packageDependencies.ui.DependenciesPanel) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder)

Example 2 with ForwardDependenciesBuilder

use of com.intellij.packageDependencies.ForwardDependenciesBuilder in project intellij-community by JetBrains.

the class UsagesInAnalyzingDependenciesTest method testForwardPackageScope.

@SuppressWarnings("ConstantConditions")
public void testForwardPackageScope() {
    PsiPackage bPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com.b");
    DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, new JavaAnalysisScope(bPackage, null));
    builder.analyze();
    Set<PsiFile> searchFor = new HashSet<>();
    searchFor.add(myJavaFacade.findClass("com.a.A", GlobalSearchScope.allScope(myProject)).getContainingFile());
    Set<PsiFile> searchIn = new HashSet<>();
    PsiClass bClass = myJavaFacade.findClass("com.b.B", GlobalSearchScope.allScope(myProject));
    searchIn.add(bClass.getContainingFile());
    PsiClass cClass = myJavaFacade.findClass("com.b.C", GlobalSearchScope.allScope(myProject));
    searchIn.add(cClass.getContainingFile());
    UsageInfo[] usagesInfos = FindDependencyUtil.findDependencies(builder, searchIn, searchFor);
    UsageInfo2UsageAdapter[] usages = UsageInfo2UsageAdapter.convert(usagesInfos);
    String[] psiUsages = new String[usagesInfos.length];
    for (int i = 0; i < usagesInfos.length; i++) {
        psiUsages[i] = toString(usages[i]);
    }
    checkResult(new String[] { "2 import com.a.A;", "4 A myA = new A();", "4 A myA = new A();", "6 myA.aa();", "2 import com.a.A;", "4 A myA = new A();", "4 A myA = new A();", "6 myA.aa();" }, psiUsages);
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) BackwardDependenciesBuilder(com.intellij.packageDependencies.BackwardDependenciesBuilder) JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) PsiFile(com.intellij.psi.PsiFile) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(java.util.HashSet)

Example 3 with ForwardDependenciesBuilder

use of com.intellij.packageDependencies.ForwardDependenciesBuilder in project intellij-community by JetBrains.

the class UsagesInAnalyzingDependenciesTest method testForwardJdkClasses.

@SuppressWarnings("ConstantConditions")
public void testForwardJdkClasses() {
    DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, new AnalysisScope(myProject));
    builder.analyze();
    Set<PsiFile> searchIn = new HashSet<>();
    PsiClass aClass = myJavaFacade.findClass("A", GlobalSearchScope.allScope(myProject));
    searchIn.add(aClass.getContainingFile());
    Set<PsiFile> searchFor = new HashSet<>();
    PsiClass stringClass = myJavaFacade.findClass("java.lang.String", GlobalSearchScope.allScope(myProject));
    searchFor.add((PsiFile) stringClass.getContainingFile().getNavigationElement());
    UsageInfo[] usagesInfos = FindDependencyUtil.findDependencies(builder, searchIn, searchFor);
    UsageInfo2UsageAdapter[] usages = UsageInfo2UsageAdapter.convert(usagesInfos);
    String[] psiUsages = new String[usagesInfos.length];
    for (int i = 0; i < usagesInfos.length; i++) {
        psiUsages[i] = toString(usages[i]);
    }
    checkResult(new String[] { "2 String myName;" }, psiUsages);
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) BackwardDependenciesBuilder(com.intellij.packageDependencies.BackwardDependenciesBuilder) PsiClass(com.intellij.psi.PsiClass) JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) PsiFile(com.intellij.psi.PsiFile) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(java.util.HashSet)

Example 4 with ForwardDependenciesBuilder

use of com.intellij.packageDependencies.ForwardDependenciesBuilder 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 5 with ForwardDependenciesBuilder

use of com.intellij.packageDependencies.ForwardDependenciesBuilder in project intellij-community by JetBrains.

the class UsagesInAnalyzingDependenciesTest method testForwardSimple.

@SuppressWarnings("ConstantConditions")
public void testForwardSimple() {
    DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, new AnalysisScope(myProject));
    builder.analyze();
    Set<PsiFile> searchIn = new HashSet<>();
    PsiClass aClass = myJavaFacade.findClass("A", GlobalSearchScope.allScope(myProject));
    searchIn.add(aClass.getContainingFile());
    Set<PsiFile> searchFor = new HashSet<>();
    PsiClass bClass = myJavaFacade.findClass("B", GlobalSearchScope.allScope(myProject));
    searchFor.add(bClass.getContainingFile());
    UsageInfo[] usagesInfos = FindDependencyUtil.findDependencies(builder, searchIn, searchFor);
    UsageInfo2UsageAdapter[] usages = UsageInfo2UsageAdapter.convert(usagesInfos);
    String[] psiUsages = new String[usagesInfos.length];
    for (int i = 0; i < usagesInfos.length; i++) {
        psiUsages[i] = toString(usages[i]);
    }
    checkResult(new String[] { "2 B myB = new B();", "2 B myB = new B();", "4 myB.bb();" }, psiUsages);
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) BackwardDependenciesBuilder(com.intellij.packageDependencies.BackwardDependenciesBuilder) PsiClass(com.intellij.psi.PsiClass) JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) PsiFile(com.intellij.psi.PsiFile) ForwardDependenciesBuilder(com.intellij.packageDependencies.ForwardDependenciesBuilder) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(java.util.HashSet)

Aggregations

ForwardDependenciesBuilder (com.intellij.packageDependencies.ForwardDependenciesBuilder)5 DependenciesBuilder (com.intellij.packageDependencies.DependenciesBuilder)4 AnalysisScope (com.intellij.analysis.AnalysisScope)3 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)3 BackwardDependenciesBuilder (com.intellij.packageDependencies.BackwardDependenciesBuilder)3 PsiClass (com.intellij.psi.PsiClass)3 PsiFile (com.intellij.psi.PsiFile)3 UsageInfo (com.intellij.usageView.UsageInfo)3 UsageInfo2UsageAdapter (com.intellij.usages.UsageInfo2UsageAdapter)3 HashSet (java.util.HashSet)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 DependenciesPanel (com.intellij.packageDependencies.ui.DependenciesPanel)1 PsiPackage (com.intellij.psi.PsiPackage)1