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);
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations