use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartServerSupertypesHierarchyTreeStructure method addSuperClassNode.
private static void addSuperClassNode(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final HierarchyNodeDescriptor parentNode, @NotNull final List<HierarchyNodeDescriptor> descriptors, final int index) {
final TypeHierarchyItem superItem = items.get(index);
if (DartResolveUtil.OBJECT.equals(superItem.getClassElement().getName())) {
return;
}
final DartClass superClass = findDartClass(project, superItem);
final HierarchyNodeDescriptor superDescriptor = new DartTypeHierarchyNodeDescriptor(project, parentNode, superClass, false);
descriptors.add(superDescriptor);
addSuperClassHierarchy(stackItems, project, items, superItem, superDescriptor);
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartServerTypeHierarchyTreeStructure method buildSuperClassHierarchy.
@Nullable
private static HierarchyNodeDescriptor buildSuperClassHierarchy(@NotNull final Project project, @NotNull final List<TypeHierarchyItem> items) {
HierarchyNodeDescriptor descriptor = null;
final DartClass[] superClasses = filterSuperClasses(project, items);
for (int i = superClasses.length - 1; i >= 0; i--) {
final DartClass superClass = superClasses[i];
final HierarchyNodeDescriptor newDescriptor = new DartTypeHierarchyNodeDescriptor(project, descriptor, superClass, false);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
descriptor = newDescriptor;
}
return descriptor;
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartServerTypeHierarchyTreeStructure method filterSuperClasses.
@NotNull
public static DartClass[] filterSuperClasses(@NotNull final Project project, @NotNull final List<TypeHierarchyItem> items) {
if (items.isEmpty())
return new DartClass[] {};
final Set<TypeHierarchyItem> seenItems = Sets.newHashSet();
final List<DartClass> superClasses = Lists.newArrayList();
Integer superIndex = items.get(0).getSuperclass();
while (superIndex != null) {
TypeHierarchyItem superItem = items.get(superIndex);
if (!seenItems.add(superItem)) {
break;
}
final DartClass superClass = findDartClass(project, superItem);
if (superClass != null) {
superClasses.add(superClass);
}
superIndex = superItem.getSuperclass();
}
return superClasses.toArray(new DartClass[superClasses.size()]);
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartClassIndex method getItemsByName.
public static List<DartComponentName> getItemsByName(String name, Project project, GlobalSearchScope searchScope) {
final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(DART_CLASS_INDEX, name, searchScope);
final Set<DartComponentName> result = new THashSet<>();
for (VirtualFile vFile : files) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
for (PsiElement root : DartResolveUtil.findDartRoots(psiFile)) {
for (DartClass component : DartResolveUtil.getClassDeclarations(root)) {
if (name.equals(component.getName())) {
result.add(component.getComponentName());
}
}
}
}
return new ArrayList<>(result);
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartTypeHierarchyTest method doDartTypeHierarchyTest.
private void doDartTypeHierarchyTest(final String className, final boolean subtype, final String... fileNames) throws Exception {
doHierarchyTest(() -> {
final Project project = getProject();
final List<DartComponentName> dartComponentNames = DartClassIndex.getItemsByName(className, project, GlobalSearchScope.projectScope(project));
for (DartComponentName name : dartComponentNames) {
DartClass dartClass = PsiTreeUtil.getParentOfType(name, DartClass.class);
if (dartClass != null && dartClass.getName().equals(className)) {
if (subtype) {
return new DartServerTypeHierarchyTreeStructure(project, dartClass, HierarchyBrowserBaseEx.SCOPE_PROJECT);
} else {
return new DartServerSupertypesHierarchyTreeStructure(project, dartClass);
}
}
}
return null;
}, fileNames);
}
Aggregations