Search in sources :

Example 1 with DartClass

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

the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.

@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
    if (superclassComponent == null && interfaceComponents.isEmpty()) {
        return null;
    }
    final String name = componentName.getName();
    final boolean overrides;
    final DartComponent superComponent;
    if (superclassComponent != null) {
        overrides = true;
        superComponent = superclassComponent;
    } else {
        overrides = false;
        superComponent = interfaceComponents.iterator().next();
    }
    final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
    return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
        final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
        if (superClass == null)
            return "null";
        if (overrides) {
            return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
        }
        return DartBundle.message("implements.method.in", name, superClass.getName());
    }, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        List<DartComponent> superComponents = Lists.newArrayList();
        if (superclassComponent != null) {
            superComponents.add(superclassComponent);
        }
        superComponents.addAll(interfaceComponents);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.LEFT);
}
Also used : DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) DartClass(com.jetbrains.lang.dart.psi.DartClass) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Lists(com.google.common.collect.Lists) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartHierarchyUtil(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) OverriddenMember(org.dartlang.analysis.server.protocol.OverriddenMember) Collection(java.util.Collection) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartBundle(com.jetbrains.lang.dart.DartBundle) 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) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DartClass

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

the class DartNameSuggesterUtil method getSuggestedNames.

public static Collection<String> getSuggestedNames(final DartExpression expression, @Nullable Collection<String> additionalUsedNames) {
    Collection<String> candidates = new LinkedHashSet<>();
    String text = expression.getText();
    if (expression instanceof DartReference) {
        DartClass dartClass = ((DartReference) expression).resolveDartClass().getDartClass();
        String dartClassName = dartClass == null ? null : dartClass.getName();
        if (dartClassName != null && !dartClassName.equals(StringUtil.decapitalize(dartClassName))) {
            candidates.add(StringUtil.decapitalize(dartClassName));
        }
    }
    if (expression instanceof DartCallExpression) {
        final DartExpression callee = ((DartCallExpression) expression).getExpression();
        text = callee.getText();
    }
    if (text != null) {
        candidates.addAll(generateNames(text));
    }
    final Set<String> usedNames = DartRefactoringUtil.collectUsedNames(expression);
    if (additionalUsedNames != null && !additionalUsedNames.isEmpty()) {
        usedNames.addAll(additionalUsedNames);
    }
    final Collection<String> result = new ArrayList<>();
    for (String candidate : candidates) {
        int index = 0;
        String suffix = "";
        while (usedNames.contains(candidate + suffix)) {
            suffix = Integer.toString(++index);
        }
        result.add(candidate + suffix);
    }
    if (result.isEmpty()) {
        // never empty
        result.add("o");
    }
    return result;
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartReference(com.jetbrains.lang.dart.psi.DartReference) DartCallExpression(com.jetbrains.lang.dart.psi.DartCallExpression) DartExpression(com.jetbrains.lang.dart.psi.DartExpression)

Example 3 with DartClass

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

the class DartGotoImplementationTest method testIterableSubclasses.

public void testIterableSubclasses() throws Throwable {
    myFixture.configureByText("foo.dart", "");
    myFixture.doHighlighting();
    final DartSdk sdk = DartSdk.getDartSdk(getProject());
    assertNotNull(sdk);
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "set.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "string.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "list.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
    final DartClass iterableClass = PsiTreeUtil.findChildOfType(getFile(), DartClass.class);
    assertNotNull(iterableClass);
    assertEquals("Iterable", iterableClass.getName());
    getEditor().getCaretModel().moveToOffset(iterableClass.getTextOffset());
    final GotoTargetHandler.GotoData data = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), myFixture.getFile());
    final List<String> actual = ContainerUtil.map(data.targets, psiElement -> psiElement instanceof PsiNamedElement ? ((PsiNamedElement) psiElement).getName() : psiElement.toString());
    // only subclasses from dart:core are known to analyzer at this point
    assertSameElements(actual, "List", "Set", "Runes");
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartClass(com.jetbrains.lang.dart.psi.DartClass) GotoTargetHandler(com.intellij.codeInsight.navigation.GotoTargetHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 4 with DartClass

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

the class BaseDartGenerateHandler method invoke.

public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, final int offset) {
    final DartClass dartClass = PsiTreeUtil.getParentOfType(file.findElementAt(offset), DartClassDefinition.class);
    if (dartClass == null)
        return;
    final List<DartComponent> candidates = new ArrayList<>();
    collectCandidates(dartClass, candidates);
    List<DartNamedElementNode> selectedElements = Collections.emptyList();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        selectedElements = ContainerUtil.map(candidates, DartNamedElementNode::new);
    } else if (!candidates.isEmpty()) {
        final MemberChooser<DartNamedElementNode> chooser = createMemberChooserDialog(project, dartClass, candidates, getTitle());
        chooser.show();
        if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
            return;
        selectedElements = chooser.getSelectedElements();
    }
    doInvoke(project, editor, file, selectedElements, createFix(dartClass));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartNamedElementNode(com.jetbrains.lang.dart.ide.DartNamedElementNode) MemberChooser(com.intellij.ide.util.MemberChooser)

Example 5 with DartClass

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

the class DartHierarchyNodeDescriptor method update.

@Override
public boolean update() {
    boolean changes = super.update();
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
    if (element == null) {
        return invalidElement();
    }
    final ItemPresentation presentation = element.getPresentation();
    if (presentation != null) {
        if (element instanceof DartMethodDeclaration) {
            if (DartComponentType.typeOf(element) != DartComponentType.CONSTRUCTOR) {
                // Do not print constructors as Class.Class.Class(args) Class
                final DartClass cls = PsiTreeUtil.getParentOfType(element, DartClass.class);
                if (cls != null) {
                    myHighlightedText.getEnding().addText(cls.getName() + ".");
                }
            }
        }
        myHighlightedText.getEnding().addText(presentation.getPresentableText());
        PsiFile file = element.getContainingFile();
        if (file != null) {
            myHighlightedText.getEnding().addText(" (" + file.getName() + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
        }
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartMethodDeclaration(com.jetbrains.lang.dart.psi.DartMethodDeclaration) ItemPresentation(com.intellij.navigation.ItemPresentation) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) PsiFile(com.intellij.psi.PsiFile) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

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