use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.
the class DartServerTypeHierarchyTreeStructure method buildHierarchyElement.
@NotNull
private static HierarchyNodeDescriptor buildHierarchyElement(@NotNull final Project project, @NotNull final DartClass dartClass) {
if (DartResolveUtil.OBJECT.equals(dartClass.getName())) {
return new DartTypeHierarchyNodeDescriptor(project, null, dartClass, true);
}
final List<TypeHierarchyItem> items = getTypeHierarchyItems(dartClass);
final HierarchyNodeDescriptor superDescriptor = buildSuperClassHierarchy(project, items);
final HierarchyNodeDescriptor baseDescriptor = new DartTypeHierarchyNodeDescriptor(project, superDescriptor, dartClass, true);
if (superDescriptor != null) {
superDescriptor.setCachedChildren(new HierarchyNodeDescriptor[] { baseDescriptor });
}
if (!items.isEmpty()) {
addSubClassHierarchy(Sets.newHashSet(), project, items, items.get(0), baseDescriptor);
}
return baseDescriptor;
}
use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.
the class DartServerGotoSuperHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
return;
}
final boolean isInClass = inComponent instanceof DartClass;
// ask for the super type hierarchy
final VirtualFile virtualFile = file.getVirtualFile();
final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
// build list of DartComponent(s)
final List<DartComponent> supers = Lists.newArrayList();
if (!items.isEmpty()) {
TypeHierarchyItem seed = items.get(0);
{
final Integer superIndex = seed.getSuperclass();
if (superIndex != null) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
for (int superIndex : seed.getMixins()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
for (int superIndex : seed.getInterfaces()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
// prepare the title
final String title;
if (isInClass) {
title = DartBundle.message("goto.super.class.chooser.title");
} else {
title = CodeInsightBundle.message("goto.super.method.chooser.title");
}
// open DartComponent(s)
final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
final Ref<VirtualFile> fileRef = Ref.create();
final Ref<Integer> offsetRef = Ref.create();
final Ref<DartComponentType> componentTypeRef = Ref.create();
prepare(parameters, fileRef, offsetRef, componentTypeRef);
if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
return;
ApplicationManager.getApplication().runReadAction(() -> {
final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
});
final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
for (DartComponent component : components) {
consumer.process(component);
}
});
}
use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method addSubClasses.
private static void addSubClasses(@NotNull final Project project, @NotNull final SearchScope scope, @NotNull final Set<TypeHierarchyItem> visited, @NotNull final List<TypeHierarchyItem> hierarchyItems, @NotNull final List<DartComponent> components, @NotNull final TypeHierarchyItem currentItem, final boolean addItem) {
if (!visited.add(currentItem)) {
return;
}
if (addItem) {
final Element element = currentItem.getClassElement();
final Location location = element.getLocation();
final DartComponent component = DartHierarchyUtil.findDartComponent(project, location);
if (component != null && isInScope(scope, component)) {
components.add(component);
}
}
for (int subIndex : currentItem.getSubclasses()) {
final TypeHierarchyItem subItem = hierarchyItems.get(subIndex);
addSubClasses(project, scope, visited, hierarchyItems, components, subItem, true);
}
}
use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.
the class CreateEqualsAndHashcodeFix method doesSuperclassOverrideEqualEqualAndHashCode.
private static boolean doesSuperclassOverrideEqualEqualAndHashCode(@NotNull final DartClass dartClass) {
final Project project = dartClass.getProject();
final VirtualFile file = dartClass.getContainingFile().getVirtualFile();
final DartComponentName name = dartClass.getComponentName();
if (name == null) {
return false;
}
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(dartClass.getProject()).search_getTypeHierarchy(file, name.getTextRange().getStartOffset(), true);
for (DartClass superClass : DartServerTypeHierarchyTreeStructure.filterSuperClasses(project, items)) {
if (superClass != null && superClass.getName() != null && !superClass.getName().equals("Object")) {
if (DartGenerateEqualsAndHashcodeAction.doesClassContainEqualsAndHashCode(superClass)) {
return true;
}
}
}
return false;
}
Aggregations