Search in sources :

Example 21 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartMethodHierarchyTest method doMethodHierarchyTest.

private void doMethodHierarchyTest(final String className, final String methodName, final boolean shouldHide, 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 && className.equals(dartClass.getName())) {
                PsiElement member = dartClass.findMemberByName(methodName);
                if (member == null) {
                    member = findReference(dartClass, methodName);
                }
                if (member == null) {
                    fail("Method not found");
                }
                if (shouldHide) {
                    HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
                    assert state != null;
                    state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = true;
                }
                return new DartMethodHierarchyTreeStructure(project, (DartComponent) member);
            }
        }
        return null;
    }, fileNames);
}
Also used : Project(com.intellij.openapi.project.Project) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) DartMethodHierarchyTreeStructure(com.jetbrains.lang.dart.ide.hierarchy.method.DartMethodHierarchyTreeStructure) HierarchyBrowserManager(com.intellij.ide.hierarchy.HierarchyBrowserManager) PsiElement(com.intellij.psi.PsiElement)

Example 22 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartGenericSpecialization method getGenericKey.

public static String getGenericKey(@Nullable PsiElement element, @NotNull String genericName) {
    final StringBuilder result = new StringBuilder();
    final DartComponent dartComponent = PsiTreeUtil.getParentOfType(element, DartComponent.class, false);
    if (dartComponent instanceof DartClass) {
        result.append(dartComponent.getName());
    } else if (dartComponent != null) {
        DartClass dartClass = PsiTreeUtil.getParentOfType(dartComponent, DartClass.class);
        if (dartClass != null) {
            result.append(dartClass.getName());
        }
        if (PsiTreeUtil.getChildOfType(dartComponent, DartTypeArguments.class) != null) {
            // generic method
            result.append(":");
            result.append(dartComponent.getName());
        }
    }
    if (result.length() > 0) {
        result.append("-");
    }
    result.append(genericName);
    return result.toString();
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass)

Example 23 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass 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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem)

Example 24 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartImplementMethodHandler method collectCandidates.

@Override
protected void collectCandidates(@NotNull final DartClass dartClass, @NotNull final List<DartComponent> candidates) {
    Map<Pair<String, Boolean>, DartComponent> result = new THashMap<>(computeSuperInterfacesMembersMap(dartClass));
    Map<Pair<String, Boolean>, DartComponent> superClassesMemberMap = new THashMap<>(computeSuperClassesMemberMap(dartClass));
    result.keySet().removeAll(superClassesMemberMap.keySet());
    for (Map.Entry<Pair<String, Boolean>, DartComponent> entry : superClassesMemberMap.entrySet()) {
        final DartComponent component = entry.getValue();
        if (component.isAbstract() && !result.containsKey(entry.getKey())) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    result.keySet().removeAll(computeClassMembersMap(dartClass, false).keySet());
    candidates.addAll(ContainerUtil.findAll(result.values(), component -> component.isPublic() || DartResolveUtil.sameLibrary(dartClass, component)));
}
Also used : DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) DartClass(com.jetbrains.lang.dart.psi.DartClass) List(java.util.List) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull) DartBundle(com.jetbrains.lang.dart.DartBundle) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) THashMap(gnu.trove.THashMap) Map(java.util.Map) THashMap(gnu.trove.THashMap) Pair(com.intellij.openapi.util.Pair)

Example 25 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class BaseDartGenerateHandler method computeSuperClassesMemberMap.

@NotNull
protected final Map<Pair<String, Boolean>, DartComponent> computeSuperClassesMemberMap(@NotNull final DartClass dartClass) {
    final List<DartClass> superClasses = new ArrayList<>();
    final List<DartClass> superInterfaces = new ArrayList<>();
    DartResolveUtil.collectSupers(superClasses, superInterfaces, dartClass);
    List<DartComponent> superClassesMembers = new ArrayList<>();
    for (DartClass superClass : superClasses) {
        superClassesMembers.addAll(DartResolveUtil.getNamedSubComponents(superClass));
    }
    superClassesMembers = ContainerUtil.filter(superClassesMembers, NOT_CONSTRUCTOR_CONDITION);
    superClassesMembers = ContainerUtil.filter(superClassesMembers, NOT_STATIC_CONDITION);
    return DartResolveUtil.namedComponentToMap(superClassesMembers);
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DartClass (com.jetbrains.lang.dart.psi.DartClass)26 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)8 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)8 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)8 NotNull (org.jetbrains.annotations.NotNull)7 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)6 PsiElement (com.intellij.psi.PsiElement)5 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)4 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ItemPresentation (com.intellij.navigation.ItemPresentation)3 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)3 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)3 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)2 LayeredIcon (com.intellij.ui.LayeredIcon)2 DartBundle (com.jetbrains.lang.dart.DartBundle)2 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)2