Search in sources :

Example 1 with DependenciesBuilder

use of com.intellij.packageDependencies.DependenciesBuilder 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 DependenciesBuilder

use of com.intellij.packageDependencies.DependenciesBuilder 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 DependenciesBuilder

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

the class UsagesInAnalyzingDependenciesTest method testBackwardPackageScope.

@SuppressWarnings("ConstantConditions")
public void testBackwardPackageScope() {
    PsiPackage bPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com.a");
    DependenciesBuilder builder = new BackwardDependenciesBuilder(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.a.C", GlobalSearchScope.allScope(myProject));
    searchFor.add(cClass.getContainingFile());
    UsageInfo[] usagesInfos = FindDependencyUtil.findBackwardDependencies(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[] { "4 A myA = new A();", "4 A myA = new A();", "5 C myC = new C();", "5 C myC = new C();", "7 myA.aa();", "8 myC.cc();" }, 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) BackwardDependenciesBuilder(com.intellij.packageDependencies.BackwardDependenciesBuilder) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(java.util.HashSet)

Example 4 with DependenciesBuilder

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

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

the class DependenciesHandlerBase method analyze.

public void analyze() {
    final List<DependenciesBuilder> builders = new ArrayList<>();
    final Task task;
    if (canStartInBackground()) {
        task = new Task.Backgroundable(myProject, getProgressTitle(), true, new PerformAnalysisInBackgroundOption(myProject)) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                perform(builders);
            }

            @Override
            public void onSuccess() {
                DependenciesHandlerBase.this.onSuccess(builders);
            }
        };
    } else {
        task = new Task.Modal(myProject, getProgressTitle(), true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                perform(builders);
            }

            @Override
            public void onSuccess() {
                DependenciesHandlerBase.this.onSuccess(builders);
            }
        };
    }
    ProgressManager.getInstance().run(task);
}
Also used : DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption)

Aggregations

DependenciesBuilder (com.intellij.packageDependencies.DependenciesBuilder)8 BackwardDependenciesBuilder (com.intellij.packageDependencies.BackwardDependenciesBuilder)5 ForwardDependenciesBuilder (com.intellij.packageDependencies.ForwardDependenciesBuilder)5 PsiFile (com.intellij.psi.PsiFile)5 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)4 PsiClass (com.intellij.psi.PsiClass)4 UsageInfo (com.intellij.usageView.UsageInfo)4 UsageInfo2UsageAdapter (com.intellij.usages.UsageInfo2UsageAdapter)4 HashSet (java.util.HashSet)4 AnalysisScope (com.intellij.analysis.AnalysisScope)3 PsiPackage (com.intellij.psi.PsiPackage)2 PerformAnalysisInBackgroundOption (com.intellij.analysis.PerformAnalysisInBackgroundOption)1 PerformanceWatcher (com.intellij.diagnostic.PerformanceWatcher)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 DependenciesPanel (com.intellij.packageDependencies.ui.DependenciesPanel)1 ArrayList (java.util.ArrayList)1