Search in sources :

Example 6 with DartComponentType

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

the class DartComponentInfoListExternalizer method save.

@Override
public void save(@NotNull final DataOutput out, @NotNull final List<DartComponentInfo> infos) throws IOException {
    DataInputOutputUtil.writeINT(out, infos.size());
    for (DartComponentInfo componentInfo : infos) {
        final DartComponentType dartComponentType = componentInfo.getComponentType();
        final int key = dartComponentType == null ? -1 : dartComponentType.getKey();
        DataInputOutputUtil.writeINT(out, key);
        final String libraryName = componentInfo.getLibraryName();
        out.writeBoolean(libraryName != null);
        if (libraryName != null) {
            IOUtil.writeUTF(out, libraryName);
        }
    }
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType)

Example 7 with DartComponentType

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

the class DartIntroduceHandler method getOccurrences.

protected List<PsiElement> getOccurrences(PsiElement element, @NotNull final DartExpression expression) {
    PsiElement context = element;
    DartComponentType type;
    do {
        context = PsiTreeUtil.getParentOfType(context, DartComponent.class, true);
        type = DartComponentType.typeOf(context);
    } while (type != null && notFunctionMethodClass(type));
    if (context == null) {
        context = expression.getContainingFile();
    }
    return DartRefactoringUtil.getOccurrences(expression, context);
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType)

Example 8 with DartComponentType

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

the class DartElementDescriptionProvider method getElementDescription.

@Nullable
@Override
public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
    if (!(location instanceof HighlightUsagesDescriptionLocation))
        return null;
    if (element instanceof DartLibraryNameElement)
        return "library " + ((DartLibraryNameElement) element).getName();
    if (element instanceof DartNamedElement) {
        final String name = ((DartNamedElement) element).getName();
        final DartComponentType type = DartComponentType.typeOf(element);
        if (type != null) {
            final String typeText = type.toString().toLowerCase(Locale.US);
            return name != null ? typeText + " " + name : typeText;
        }
    }
    return null;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) HighlightUsagesDescriptionLocation(com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with DartComponentType

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

the class AbstractDartComponentImpl method getIcon.

@Override
public Icon getIcon(int flags) {
    final DartComponentType type = DartComponentType.typeOf(this);
    Icon icon = type == null ? super.getIcon(flags) : type.getIcon(this);
    icon = doOverlays(icon);
    RowIcon baseIcon = new RowIcon(2);
    baseIcon.setIcon(icon, 0);
    Icon visibility = isPublic() ? PlatformIcons.PUBLIC_ICON : PlatformIcons.PRIVATE_ICON;
    baseIcon.setIcon(visibility, 1);
    return baseIcon;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) RowIcon(com.intellij.ui.RowIcon) RowIcon(com.intellij.ui.RowIcon)

Example 10 with DartComponentType

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

the class AbstractDartComponentImpl method getPresentation.

@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {

        @Override
        public String getPresentableText() {
            final StringBuilder result = new StringBuilder();
            result.append(getComponentName());
            final DartComponentType type = DartComponentType.typeOf(AbstractDartComponentImpl.this);
            if ((type == DartComponentType.METHOD || type == DartComponentType.FUNCTION || type == DartComponentType.CONSTRUCTOR || type == DartComponentType.OPERATOR) && !(isGetter() || isSetter())) {
                final String parameterList = DartPresentableUtil.getPresentableParameterList(AbstractDartComponentImpl.this);
                result.append("(").append(parameterList).append(")");
            }
            if (type == DartComponentType.METHOD || type == DartComponentType.FIELD || type == DartComponentType.FUNCTION || type == DartComponentType.OPERATOR) {
                final DartReturnType returnType = PsiTreeUtil.getChildOfType(AbstractDartComponentImpl.this, DartReturnType.class);
                final DartType dartType = PsiTreeUtil.getChildOfType(AbstractDartComponentImpl.this, DartType.class);
                if (returnType != null) {
                    result.append(" ").append(DartPresentableUtil.RIGHT_ARROW).append(" ");
                    result.append(DartPresentableUtil.buildTypeText(AbstractDartComponentImpl.this, returnType, null));
                } else if (dartType != null) {
                    result.append(" ").append(DartPresentableUtil.RIGHT_ARROW).append(" ");
                    result.append(DartPresentableUtil.buildTypeText(AbstractDartComponentImpl.this, dartType, null));
                }
            }
            return result.toString();
        }

        @Nullable
        private String getComponentName() {
            String name = getName();
            if (DartComponentType.typeOf(AbstractDartComponentImpl.this) == DartComponentType.CONSTRUCTOR) {
                DartClass dartClass = PsiTreeUtil.getParentOfType(AbstractDartComponentImpl.this, DartClass.class);
                if (dartClass == null) {
                    return name;
                }
                return StringUtil.isEmpty(name) ? dartClass.getName() : dartClass.getName() + "." + name;
            }
            return name;
        }

        @Override
        public String getLocationString() {
            if (!isValid()) {
                return "";
            }
            if (!(AbstractDartComponentImpl.this instanceof DartClass)) {
                final DartClass dartClass = PsiTreeUtil.getParentOfType(AbstractDartComponentImpl.this, DartClass.class);
                if (dartClass != null) {
                    return dartClass.getName();
                }
            }
            DartExecutionScope root = PsiTreeUtil.getTopmostParentOfType(AbstractDartComponentImpl.this, DartExecutionScope.class);
            DartPartOfStatement partOfStatement = PsiTreeUtil.getChildOfType(root, DartPartOfStatement.class);
            return partOfStatement == null ? null : partOfStatement.getLibraryName();
        }

        @Override
        public Icon getIcon(boolean open) {
            return AbstractDartComponentImpl.this.getIcon(0);
        }
    };
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) ItemPresentation(com.intellij.navigation.ItemPresentation)

Aggregations

DartComponentType (com.jetbrains.lang.dart.DartComponentType)12 PsiElement (com.intellij.psi.PsiElement)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)2 Nullable (org.jetbrains.annotations.Nullable)2 HighlightUsagesDescriptionLocation (com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 RowIcon (com.intellij.ui.RowIcon)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)1 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)1