Search in sources :

Example 16 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project kotlin by JetBrains.

the class KotlinCallTreeStructure method collectNodeDescriptors.

protected Object[] collectNodeDescriptors(HierarchyNodeDescriptor descriptor, Map<PsiReference, PsiElement> referencesToCalleeElements, PsiClass basePsiClass) {
    HashMap<PsiElement, HierarchyNodeDescriptor> declarationToDescriptorMap = new HashMap<PsiElement, HierarchyNodeDescriptor>();
    for (Map.Entry<PsiReference, PsiElement> refToCallee : referencesToCalleeElements.entrySet()) {
        PsiReference ref = refToCallee.getKey();
        PsiElement callee = refToCallee.getValue();
        if (basePsiClass != null && !isInScope(basePsiClass, callee, scopeType))
            continue;
        addNodeDescriptorForElement(ref, callee, declarationToDescriptorMap, descriptor, false);
    }
    return declarationToDescriptorMap.values().toArray(new Object[declarationToDescriptorMap.size()]);
}
Also used : HashMap(com.intellij.util.containers.HashMap) PsiReference(com.intellij.psi.PsiReference) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) CallHierarchyNodeDescriptor(com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement)

Example 17 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project kotlin by JetBrains.

the class KotlinCallerMethodsTreeStructure method buildChildren.

@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
    final PsiElement element = getTargetElement(descriptor);
    KtElement codeBlockForLocalDeclaration = getEnclosingElementForLocalDeclaration(element);
    if (codeBlockForLocalDeclaration != null) {
        BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
        final Map<PsiReference, PsiElement> referencesToElements = new HashMap<PsiReference, PsiElement>();
        codeBlockForLocalDeclaration.accept(new CalleeReferenceVisitorBase(bindingContext, true) {

            @Override
            protected void processDeclaration(KtSimpleNameExpression reference, PsiElement declaration) {
                if (!declaration.equals(element))
                    return;
                //noinspection unchecked
                PsiElement container = PsiTreeUtil.getParentOfType(reference, KtNamedFunction.class, KtPropertyAccessor.class, KtClassOrObject.class);
                if (container instanceof KtPropertyAccessor) {
                    container = PsiTreeUtil.getParentOfType(container, KtProperty.class);
                }
                if (container != null) {
                    referencesToElements.put(ReferenceUtilKt.getMainReference(reference), container);
                }
            }
        });
        return collectNodeDescriptors(descriptor, referencesToElements, null);
    }
    SearchScope searchScope = getSearchScope(scopeType, basePsiClass);
    Map<PsiElement, HierarchyNodeDescriptor> methodToDescriptorMap = Maps.newHashMap();
    Object[] javaCallers = null;
    if (element instanceof PsiMethod) {
        javaCallers = javaTreeStructure.getChildElements(getJavaNodeDescriptor(descriptor));
        processPsiMethodCallers(Collections.singleton((PsiMethod) element), descriptor, methodToDescriptorMap, searchScope, true);
    }
    if (element instanceof KtNamedFunction || element instanceof KtSecondaryConstructor) {
        Collection<PsiMethod> lightMethods = LightClassUtil.INSTANCE.getLightClassMethods((KtFunction) element);
        processPsiMethodCallers(lightMethods, descriptor, methodToDescriptorMap, searchScope, false);
    }
    if (element instanceof KtProperty) {
        LightClassUtil.PropertyAccessorsPsiMethods propertyMethods = LightClassUtil.INSTANCE.getLightClassPropertyMethods((KtProperty) element);
        processPsiMethodCallers(propertyMethods, descriptor, methodToDescriptorMap, searchScope, false);
    }
    if (element instanceof KtClassOrObject) {
        KtPrimaryConstructor constructor = ((KtClassOrObject) element).getPrimaryConstructor();
        if (constructor != null) {
            PsiMethod lightMethod = LightClassUtil.INSTANCE.getLightClassMethod(constructor);
            processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
        } else {
            processKtClassOrObjectCallers((KtClassOrObject) element, descriptor, methodToDescriptorMap, searchScope);
        }
    }
    Object[] callers = methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
    return (javaCallers != null) ? ArrayUtil.mergeArrays(javaCallers, callers) : callers;
}
Also used : HashMap(com.intellij.util.containers.HashMap) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) SearchScope(com.intellij.psi.search.SearchScope) LightClassUtil(org.jetbrains.kotlin.asJava.LightClassUtil) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-plugins by JetBrains.

the class DartMethodHierarchyTreeStructure method addAllVisibleSubclasses.

private void addAllVisibleSubclasses(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final TypeHierarchyItem item, @NotNull final DartMethodHierarchyNodeDescriptor descriptor) {
    if (!stackItems.add(item)) {
        descriptor.setCachedChildren(ArrayUtil.EMPTY_OBJECT_ARRAY);
        return;
    }
    HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
    if (state == null)
        throw new NullPointerException();
    List<DartMethodHierarchyNodeDescriptor> subDescriptors = Lists.newArrayList();
    try {
        for (int index : item.getSubclasses()) {
            final TypeHierarchyItem subItem = items.get(index);
            final DartClass subclass = findDartClass(project, subItem);
            if (subclass != null) {
                final DartMethodHierarchyNodeDescriptor subDescriptor = new DartMethodHierarchyNodeDescriptor(project, descriptor, subclass, false, this);
                subDescriptors.add(subDescriptor);
                addAllVisibleSubclasses(stackItems, project, items, subItem, subDescriptor);
            }
        }
        DartClass dartClass = findDartClass(project, item);
        assert dartClass != null;
        String methodName = getBaseMethod().getName();
        if (methodName != null) {
            DartComponent method = dartClass.findMethodByName(methodName);
            if (method != null) {
                DartClass definingClass = PsiTreeUtil.getParentOfType(method, DartClass.class);
                if (definingClass == dartClass) {
                    descriptor.myIsImplementor = true;
                } else {
                    descriptor.myShouldImplement = method.isAbstract() && !dartClass.isAbstract();
                }
            }
        }
        for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
            if (subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor) {
                descriptor.myIsSuperclassOfImplementor = true;
                break;
            }
        }
        if (state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED) {
            List<DartMethodHierarchyNodeDescriptor> toRemove = Lists.newArrayList();
            for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
                if (!(subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor)) {
                    toRemove.add(subDescriptor);
                }
            }
            subDescriptors.removeAll(toRemove);
        }
    } finally {
        stackItems.remove(item);
    }
    descriptor.setCachedChildren(subDescriptors.toArray(new HierarchyNodeDescriptor[subDescriptors.size()]));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) HierarchyBrowserManager(com.intellij.ide.hierarchy.HierarchyBrowserManager)

Example 19 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-plugins by JetBrains.

the class DartServerSubtypesHierarchyTreeStructure method addSubClassHierarchy.

public static void addSubClassHierarchy(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final TypeHierarchyItem item, @NotNull final HierarchyNodeDescriptor descriptor) {
    if (!stackItems.add(item)) {
        descriptor.setCachedChildren(ArrayUtil.EMPTY_OBJECT_ARRAY);
        return;
    }
    List<HierarchyNodeDescriptor> subDescriptors = Lists.newArrayList();
    try {
        for (int index : item.getSubclasses()) {
            final TypeHierarchyItem subItem = items.get(index);
            final DartClass subClass = findDartClass(project, subItem);
            if (subClass != null) {
                final HierarchyNodeDescriptor subDescriptor = new DartTypeHierarchyNodeDescriptor(project, descriptor, subClass, false);
                subDescriptors.add(subDescriptor);
                addSubClassHierarchy(stackItems, project, items, subItem, subDescriptor);
            }
        }
    } finally {
        stackItems.remove(item);
    }
    descriptor.setCachedChildren(subDescriptors.toArray(new HierarchyNodeDescriptor[subDescriptors.size()]));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 20 with HierarchyNodeDescriptor

use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor 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);
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Aggregations

HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)21 NotNull (org.jetbrains.annotations.NotNull)6 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)4 DartClass (com.jetbrains.lang.dart.psi.DartClass)4 ArrayList (java.util.ArrayList)4 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)4 PsiElement (com.intellij.psi.PsiElement)3 SearchScope (com.intellij.psi.search.SearchScope)3 HashMap (com.intellij.util.containers.HashMap)3 CallHierarchyNodeDescriptor (com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor)2 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 HashMap (java.util.HashMap)2 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiAnonymousClass (com.intellij.psi.PsiAnonymousClass)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)1