use of com.intellij.analysis.JavaAnalysisScope in project intellij-community by JetBrains.
the class CyclicDependenciesAction method getInspectionScopeImpl.
@Nullable
private static AnalysisScope getInspectionScopeImpl(DataContext dataContext) {
//Possible scopes: package, project, module.
Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
if (projectContext != null) {
return null;
}
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
if (moduleContext != null) {
return null;
}
final Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
if (modulesArray != null && modulesArray.length > 0) {
return new AnalysisScope(modulesArray);
}
PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (psiTarget instanceof PsiDirectory) {
PsiDirectory psiDirectory = (PsiDirectory) psiTarget;
if (!psiDirectory.getManager().isInProject(psiDirectory))
return null;
return new AnalysisScope(psiDirectory);
} else if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage) psiTarget;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject()));
if (dirs.length == 0)
return null;
return new JavaAnalysisScope(pack, LangDataKeys.MODULE.getData(dataContext));
}
return null;
}
use of com.intellij.analysis.JavaAnalysisScope 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);
}
use of com.intellij.analysis.JavaAnalysisScope 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);
}
use of com.intellij.analysis.JavaAnalysisScope 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);
}
use of com.intellij.analysis.JavaAnalysisScope 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);
}
Aggregations