use of com.intellij.usages.UsageInfo2UsageAdapter 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.usages.UsageInfo2UsageAdapter 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.usages.UsageInfo2UsageAdapter in project intellij-community by JetBrains.
the class ReplaceUsageViewContext method doReplace.
private void doReplace() {
List<Usage> infos = myUsageView.getSortedUsages();
List<ReplacementInfo> results = new ArrayList<>(infos.size());
for (final Usage info : infos) {
UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) info;
if (isValid(usage)) {
results.add(usage2ReplacementInfo.get(usage));
}
}
getReplacer().replaceAll(results);
}
use of com.intellij.usages.UsageInfo2UsageAdapter 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);
}
use of com.intellij.usages.UsageInfo2UsageAdapter in project intellij-community by JetBrains.
the class UsageFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
final Usage[] usages = UsageView.USAGES_KEY.getData(context);
if (usages != null) {
final List<AbstractTreeNode> result = new SmartList<>();
final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
final List<Usage> nonMapped = new ArrayList<>();
for (Usage usage : usages) {
if (usage instanceof UsageInFile) {
map.putValue(((UsageInFile) usage).getFile(), usage);
} else if (usage instanceof UsageInFiles) {
final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
for (VirtualFile file : files) {
map.putValue(file, usage);
}
} else {
nonMapped.add(usage);
}
}
final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
keys.addAll(map.keySet());
for (VirtualFile key : keys) {
final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
result.add(grouping);
final Collection<Usage> subUsages = map.get(key);
for (Usage usage : subUsages) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
grouping.addChild(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
}
for (Usage usage : nonMapped) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
result.add(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
return result;
}
return null;
}
Aggregations