Search in sources :

Example 21 with AnalysisScope

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

the class FindMethodDuplicatesBaseTest method doTest.

protected void doTest(final boolean shouldSucceed) throws Exception {
    final String filePath = getTestFilePath();
    configureByFile(filePath);
    final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue("<caret> is not on method name", targetElement instanceof PsiMember);
    final PsiMember psiMethod = (PsiMember) targetElement;
    try {
        MethodDuplicatesHandler.invokeOnScope(getProject(), psiMethod, new AnalysisScope(getFile()));
    } catch (RuntimeException e) {
        if (shouldSucceed) {
            fail("duplicates were not found");
        }
        return;
    }
    UIUtil.dispatchAllInvocationEvents();
    if (shouldSucceed) {
        checkResultByFile(filePath + ".after");
    } else {
        fail("duplicates found");
    }
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) PsiElement(com.intellij.psi.PsiElement) PsiMember(com.intellij.psi.PsiMember)

Example 22 with AnalysisScope

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

the class DependenciesPanelTest method testModuleGroups.

public void testModuleGroups() throws Exception {
    ModifiableModuleModel model = ModuleManager.getInstance(myProject).getModifiableModel();
    model.setModuleGroupPath(myModule, new String[] { "a", "b" });
    model.renameModule(myModule, "module");
    WriteAction.run(model::commit);
    // groups aren't shown for single-module projects so we need to add an empty second module
    createModule("util");
    DependencyUISettings settings = DependencyUISettings.getInstance();
    settings.UI_GROUP_BY_SCOPE_TYPE = false;
    settings.UI_SHOW_FILES = false;
    settings.SCOPE_TYPE = ProjectPatternProvider.FILE;
    doTestDependenciesTrees(new AnalysisScope(myModule), "-Root\n" + " -[a]\n" + "  -b\n" + "   -module\n" + "    -dependencies\n" + "     -src\n" + "      com/package1\n", "Root\n");
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) DependencyUISettings(com.intellij.packageDependencies.DependencyUISettings)

Example 23 with AnalysisScope

use of com.intellij.analysis.AnalysisScope 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 24 with AnalysisScope

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

the class AnalysisScopeTest method testGeneratedSourceRoot.

public void testGeneratedSourceRoot() throws Exception {
    VirtualFile genRoot = getVirtualFile(createTempDir("genSrcRoot"));
    VirtualFile srcRoot = getVirtualFile(createTempDir("srcRoot"));
    JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("", true);
    PsiTestUtil.addSourceRoot(myModule, genRoot, JavaSourceRootType.SOURCE, properties);
    PsiTestUtil.addSourceRoot(myModule, srcRoot);
    VirtualFile genClass = VfsTestUtil.createFile(genRoot, "Gen.java", "class Gen{}");
    VirtualFile srcClass = VfsTestUtil.createFile(srcRoot, "Src.java", "class Src{}");
    AnalysisScope scope = new AnalysisScope(myModule);
    assertTrue(scope.contains(srcClass));
    assertFalse(scope.contains(genClass));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisScope(com.intellij.analysis.AnalysisScope) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 25 with AnalysisScope

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

the class CyclicDependenciesTest method testT4.

public void testT4() {
    //com.a<->com.b
    //com.a->com.c->com.d->com.a
    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.d", new String[][] { { "com.c", "com.a", "com.d" } });
    expected.put("com.c", new String[][] { { "com.a", "com.d", "com.c" } });
    expected.put("com.a", new String[][] { { "com.d", "com.c", "com.a" }, { "com.b", "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)

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