Search in sources :

Example 71 with PsiPackage

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

the class CyclicDependenciesTest method testT1.

public void testT1() {
    // com.a<->com.b
    final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, new AnalysisScope(myProject));
    builder.analyze();
    final HashMap<PsiPackage, Set<List<PsiPackage>>> cyclicDependencies = builder.getCyclicDependencies();
    HashMap<String, String[][]> expected = new HashMap<>();
    expected.put("com.b", new String[][] { { "com.a", "com.b" } });
    expected.put("com.a", new String[][] { { "com.b", "com.a" } });
    checkResult(expected, cyclicDependencies);
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) CyclicDependenciesBuilder(com.intellij.cyclicDependencies.CyclicDependenciesBuilder) PsiPackage(com.intellij.psi.PsiPackage)

Example 72 with PsiPackage

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

the class CyclicDependenciesTest method testPackageScope2.

public void testPackageScope2() {
    //com.b<->com.a  - find
    //com.c<->com.d  - not in scope
    final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, new JavaAnalysisScope(JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com.subscope1"), null));
    builder.analyze();
    final HashMap<PsiPackage, Set<List<PsiPackage>>> cyclicDependencies = builder.getCyclicDependencies();
    HashMap<String, String[][]> expected = new HashMap<>();
    expected.put("com.subscope1.b", new String[][] { { "com.subscope1.a", "com.subscope1.b" } });
    expected.put("com.subscope1.a", new String[][] { { "com.subscope1.b", "com.subscope1.a" } });
    checkResult(expected, cyclicDependencies);
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) CyclicDependenciesBuilder(com.intellij.cyclicDependencies.CyclicDependenciesBuilder) PsiPackage(com.intellij.psi.PsiPackage)

Example 73 with PsiPackage

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

the class CyclicDependenciesTest method testT3.

public void testT3() {
    //com.b<->com.d
    //com.b->com.a->com.c->com.b
    final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, new AnalysisScope(myProject));
    builder.analyze();
    final HashMap<PsiPackage, Set<List<PsiPackage>>> cyclicDependencies = builder.getCyclicDependencies();
    HashMap<String, String[][]> expected = new HashMap<>();
    expected.put("com.b", new String[][] { { "com.c", "com.a", "com.b" }, { "com.d", "com.b" } });
    expected.put("com.d", new String[][] { { "com.b", "com.d" } });
    expected.put("com.c", new String[][] { { "com.a", "com.b", "com.c" } });
    expected.put("com.a", new String[][] { { "com.b", "com.c", "com.a" } });
    checkResult(expected, cyclicDependencies, true);
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) AnalysisScope(com.intellij.analysis.AnalysisScope) CyclicDependenciesBuilder(com.intellij.cyclicDependencies.CyclicDependenciesBuilder) PsiPackage(com.intellij.psi.PsiPackage)

Example 74 with PsiPackage

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

the class CyclicDependenciesTest method checkResult.

private static void checkResult(HashMap<String, String[][]> expected, HashMap<PsiPackage, Set<List<PsiPackage>>> cycles, boolean forceContains) {
    assertEquals(expected.size(), cycles.size());
    for (final PsiPackage psiPackage : cycles.keySet()) {
        assertTrue(expected.containsKey(psiPackage.getQualifiedName()));
        final String packs = psiPackage.getQualifiedName();
        if (forceContains) {
            assertEquals(expected.get(packs).length, cycles.get(psiPackage).size());
        }
        for (final List<PsiPackage> cycle : cycles.get(psiPackage)) {
            final String[][] expectedCycles = expected.get(packs);
            final String[] string = new String[cycle.size()];
            int i = 0;
            for (final PsiPackage packageInCycle : cycle) {
                string[i++] = packageInCycle.getQualifiedName();
            }
            assertTrue(findInMatrix(expectedCycles, string) > -1);
        }
    }
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Example 75 with PsiPackage

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

the class CyclicDependenciesTest method testPackageScope1.

public void testPackageScope1() {
    // com.a<->com.b
    final CyclicDependenciesBuilder builder = new CyclicDependenciesBuilder(myProject, new JavaAnalysisScope(JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com"), null));
    builder.analyze();
    final HashMap<PsiPackage, Set<List<PsiPackage>>> cyclicDependencies = builder.getCyclicDependencies();
    HashMap<String, String[][]> expected = new HashMap<>();
    expected.put("com.b", new String[][] { { "com.a", "com.b" } });
    expected.put("com.a", new String[][] { { "com.b", "com.a" } });
    checkResult(expected, cyclicDependencies);
}
Also used : JavaAnalysisScope(com.intellij.analysis.JavaAnalysisScope) CyclicDependenciesBuilder(com.intellij.cyclicDependencies.CyclicDependenciesBuilder) PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)79 PsiDirectory (com.intellij.psi.PsiDirectory)17 Module (com.intellij.openapi.module.Module)16 PsiClass (com.intellij.psi.PsiClass)16 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 PsiFile (com.intellij.psi.PsiFile)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 PsiElement (com.intellij.psi.PsiElement)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)6 HashSet (java.util.HashSet)6 Nullable (org.jetbrains.annotations.Nullable)6 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)3 List (java.util.List)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2