Search in sources :

Example 6 with DartClass

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

the class DartMethodHierarchyNodeDescriptor method update.

public final boolean update() {
    boolean changes = super.update();
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    DartClass dartClass = getType();
    if (dartClass == null) {
        if (!myHighlightedText.getText().startsWith(INVALID_PREFIX)) {
            myHighlightedText.getBeginning().addText(INVALID_PREFIX, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    final ItemPresentation presentation = dartClass.getPresentation();
    Icon baseIcon = null;
    Icon stateIcon = null;
    if (presentation != null) {
        myHighlightedText.getEnding().addText(presentation.getPresentableText());
        PsiFile file = dartClass.getContainingFile();
        if (file != null) {
            myHighlightedText.getEnding().addText(" (" + file.getName() + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
        }
        baseIcon = presentation.getIcon(false);
        stateIcon = calculateStateIcon(dartClass);
    }
    if (changes || baseIcon != myRawIcon || stateIcon != myStateIcon) {
        changes = true;
        Icon newIcon = myRawIcon = baseIcon;
        myStateIcon = stateIcon;
        if (myIsBase) {
            final LayeredIcon icon = new LayeredIcon(2);
            icon.setIcon(newIcon, 0);
            newIcon = icon;
            icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
        }
        if (myStateIcon != null) {
            newIcon = new RowIcon(myStateIcon, newIcon);
        }
        setIcon(newIcon);
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) DartClass(com.jetbrains.lang.dart.psi.DartClass) ItemPresentation(com.intellij.navigation.ItemPresentation) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) PsiFile(com.intellij.psi.PsiFile) RowIcon(com.intellij.ui.RowIcon) LayeredIcon(com.intellij.ui.LayeredIcon) RowIcon(com.intellij.ui.RowIcon)

Example 7 with DartClass

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

the class DartTypeHierarchyNodeDescriptor method update.

public final boolean update() {
    boolean changes = super.update();
    final DartClass dartClass = getDartClass();
    if (dartClass == null) {
        final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
        if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
            myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    if (changes && myIsBase) {
        final LayeredIcon icon = new LayeredIcon(2);
        icon.setIcon(getIcon(), 0);
        icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
        setIcon(icon);
    }
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    TextAttributes classNameAttributes = null;
    if (myColor != null) {
        classNameAttributes = new TextAttributes(myColor, null, null, null, Font.PLAIN);
    }
    final String libraryName = DartResolveUtil.getLibraryName(dartClass.getContainingFile());
    myHighlightedText.getEnding().addText(dartClass.getName(), classNameAttributes);
    myHighlightedText.getEnding().addText(" (" + libraryName + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) DartClass(com.jetbrains.lang.dart.psi.DartClass) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 8 with DartClass

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

the class DartFilterByClassMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
    final PsiElement at = context.getPsiElementAtStartOffset();
    final Set<DartComponentName> variables = DartRefactoringUtil.collectUsedComponents(at);
    final List<DartComponentName> filtered = ContainerUtil.filter(variables, name -> {
        final PsiElement nameParent = name.getParent();
        if (nameParent instanceof DartClass) {
            return false;
        }
        final DartClassResolveResult result = DartResolveUtil.getDartClassResolveResult(nameParent);
        final DartClass dartClass = result.getDartClass();
        return dartClass != null && filter(dartClass);
    });
    return filtered.isEmpty() ? null : new PsiElementResult(filtered.iterator().next());
}
Also used : DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 9 with DartClass

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

the class DartServerGotoSuperHandler method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
    final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
    final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
    if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
        return;
    }
    final boolean isInClass = inComponent instanceof DartClass;
    // ask for the super type hierarchy
    final VirtualFile virtualFile = file.getVirtualFile();
    final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
    final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
    // build list of DartComponent(s)
    final List<DartComponent> supers = Lists.newArrayList();
    if (!items.isEmpty()) {
        TypeHierarchyItem seed = items.get(0);
        {
            final Integer superIndex = seed.getSuperclass();
            if (superIndex != null) {
                final TypeHierarchyItem superItem = items.get(superIndex);
                addSuperComponent(project, supers, isInClass, superItem);
            }
        }
        for (int superIndex : seed.getMixins()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
        for (int superIndex : seed.getInterfaces()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
    }
    // prepare the title
    final String title;
    if (isInClass) {
        title = DartBundle.message("goto.super.class.chooser.title");
    } else {
        title = CodeInsightBundle.message("goto.super.method.chooser.title");
    }
    // open DartComponent(s)
    final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
    PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 10 with DartClass

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

the class DartNamedElementNode method buildPresentationText.

@Nullable
private static String buildPresentationText(DartComponent dartComponent) {
    final ItemPresentation presentation = dartComponent.getPresentation();
    if (presentation == null) {
        return dartComponent.getName();
    }
    final StringBuilder result = new StringBuilder();
    if (dartComponent instanceof DartClass) {
        result.append(dartComponent.getName());
        final String location = presentation.getLocationString();
        if (location != null && !location.isEmpty()) {
            result.append(" ").append(location);
        }
    } else {
        result.append(presentation.getPresentableText());
    }
    return result.toString();
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) ItemPresentation(com.intellij.navigation.ItemPresentation) Nullable(org.jetbrains.annotations.Nullable)

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