Search in sources :

Example 16 with DartComponent

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

the class DartServerImplementationsMarkerProvider method createMarkerClass.

@NotNull
private static LineMarkerInfo createMarkerClass(@NotNull final DartComponentName name) {
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    final int nameOffset = name.getTextRange().getStartOffset();
    return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("class.is.subclassed.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
        if (items.isEmpty()) {
            return;
        }
        final List<DartComponent> components = DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), ""), "Subclasses of " + name.getName(), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.RIGHT);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartInheritorsSearcher(com.jetbrains.lang.dart.ide.actions.DartInheritorsSearcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Pass(com.intellij.codeHighlighting.Pass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) List(java.util.List) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) PsiElement(com.intellij.psi.PsiElement) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with DartComponent

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

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

the class DartServerResolverTest method getPresentableElementPosition.

@NotNull
private static String getPresentableElementPosition(@NotNull final CodeInsightTestFixture fixture, @Nullable final PsiElement element) {
    if (element == null)
        return "";
    final StringBuilder buf = new StringBuilder(element.getText());
    DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
    while (component != null) {
        final DartComponentName componentName = component.getComponentName();
        if (componentName != null && componentName != element) {
            buf.insert(0, component.getName() + " -> ");
        }
        component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
    }
    String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath();
    final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
    if (path.equals(contentRoot))
        path = "[content root]";
    final String contentRootWithSlash = contentRoot + "/";
    path = StringUtil.trimStart(path, contentRootWithSlash);
    final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
    if (sdk != null && path.startsWith(sdk.getHomePath()))
        path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());
    if (buf.length() > 0)
        buf.insert(0, " -> ");
    buf.insert(0, path);
    return buf.toString();
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiDirectoryImpl(com.intellij.psi.impl.file.PsiDirectoryImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with DartComponent

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

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

the class CreateNamedConstructorFix method buildFunctionsText.

protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    //noinspection ConstantConditions
    template.addTextSegment(myDartClass.getName());
    template.addTextSegment(".");
    template.addVariable(new TextExpression("name"), true);
    template.addTextSegment("(");
    for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
        DartComponent component = iterator.next();
        template.addTextSegment("this.");
        //noinspection ConstantConditions
        template.addTextSegment(component.getName());
        if (iterator.hasNext()) {
            template.addTextSegment(",");
        }
    }
    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) TextExpression(com.intellij.codeInsight.template.impl.TextExpression) Template(com.intellij.codeInsight.template.Template)

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