Search in sources :

Example 11 with DartComponentType

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

the class DartUsageTypeProvider method getUsageType.

@Override
public UsageType getUsageType(PsiElement element) {
    if (!(element instanceof DartReference)) {
        return null;
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof DartType) {
        return getUsageTypeByType((DartType) parent);
    }
    if (DartResolveUtil.isLValue(element)) {
        return UsageType.WRITE;
    }
    if (!(parent instanceof DartReference)) {
        return UsageType.READ;
    }
    final PsiElement target = ((DartReference) element).resolve();
    final DartComponentType targetType = DartComponentType.typeOf(target == null ? null : target.getParent());
    final DartReference[] references = PsiTreeUtil.getChildrenOfType(parent, DartReference.class);
    final boolean isFirstChild = references != null && references.length > 0 && references[0] == element;
    if (isFirstChild && references.length == 2 && targetType == DartComponentType.CLASS) {
        return UsageType.CLASS_STATIC_MEMBER_ACCESS;
    }
    if (isFirstChild) {
        return UsageType.READ;
    }
    if (!(parent.getParent() instanceof DartCallExpression)) {
        return UsageType.READ;
    }
    return null;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement)

Example 12 with DartComponentType

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

the class DartUsageTypeProvider method getUsageTypeByType.

@Nullable
private static UsageType getUsageTypeByType(DartType type) {
    final PsiElement typeParent = type.getParent();
    final DartComponentType typeParentType = DartComponentType.typeOf(typeParent);
    if (typeParent instanceof DartSuperclass) {
        return UsageType.CLASS_EXTENDS_IMPLEMENTS_LIST;
    }
    if (typeParent instanceof DartNewExpression) {
        return UsageType.CLASS_NEW_OPERATOR;
    }
    if (typeParent instanceof DartTypeList && typeParent.getParent() instanceof DartInterfaces) {
        return UsageType.CLASS_EXTENDS_IMPLEMENTS_LIST;
    }
    if (typeParent instanceof DartTypeList && typeParent.getParent() instanceof DartTypeArguments) {
        return UsageType.TYPE_PARAMETER;
    }
    if (typeParent instanceof DartReturnType) {
        return UsageType.CLASS_METHOD_RETURN_TYPE;
    }
    if (typeParent instanceof DartVarAccessDeclaration && typeParentType != null) {
        switch(typeParentType) {
            case PARAMETER:
                return UsageType.CLASS_METHOD_PARAMETER_DECLARATION;
            case FIELD:
                return UsageType.CLASS_FIELD_DECLARATION;
            case METHOD:
                return UsageType.CLASS_METHOD_RETURN_TYPE;
            default:
                return null;
        }
    }
    return null;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

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