Search in sources :

Example 21 with DartComponent

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

the class CreateToStringFix method buildFunctionsText.

protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    if (CodeStyleSettingsManager.getSettings(myDartClass.getProject()).INSERT_OVERRIDE_ANNOTATION) {
        template.addTextSegment("@override\n");
    }
    template.addTextSegment("String toString() {");
    template.addTextSegment(DartTokenTypes.RETURN.toString());
    template.addTextSegment(" ");
    template.addTextSegment("'");
    //noinspection ConstantConditions
    template.addTextSegment(myDartClass.getName());
    template.addTextSegment("{");
    for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
        DartComponent component = iterator.next();
        //noinspection ConstantConditions
        template.addTextSegment(component.getName());
        template.addTextSegment(": $");
        //noinspection ConstantConditions
        template.addTextSegment(component.getName());
        if (iterator.hasNext()) {
            template.addTextSegment(", ");
        }
    }
    template.addTextSegment("}';\n");
    template.addTextSegment("}");
    template.addEndVariable();
    // trailing space is removed when auto-reformatting, but it helps to enter line break if needed
    template.addTextSegment(" ");
    return template;
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Template(com.intellij.codeInsight.template.Template)

Example 22 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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 23 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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)

Example 24 with DartComponent

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

the class BaseDartGenerateHandler method computeSuperInterfacesMembersMap.

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

Aggregations

DartComponent (com.jetbrains.lang.dart.psi.DartComponent)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiElement (com.intellij.psi.PsiElement)8 DartClass (com.jetbrains.lang.dart.psi.DartClass)8 NotNull (org.jetbrains.annotations.NotNull)8 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)7 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)6 Template (com.intellij.codeInsight.template.Template)4 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)4 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)4 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)4 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)4 List (java.util.List)4 Nullable (org.jetbrains.annotations.Nullable)4 Pass (com.intellij.codeHighlighting.Pass)3 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)3 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3