Search in sources :

Example 6 with DartClassResolveResult

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

the class DartReferenceImpl method resolveDartClass.

@NotNull
@Override
public DartClassResolveResult resolveDartClass() {
    if (this instanceof DartSuperExpression) {
        final DartClass dartClass = PsiTreeUtil.getParentOfType(this, DartClass.class);
        return dartClass == null ? DartClassResolveResult.EMPTY : dartClass.getSuperClassResolvedOrObjectClass();
    }
    if (this instanceof DartNewExpression) {
        final DartClassResolveResult result = DartResolveUtil.resolveClassByType(PsiTreeUtil.getChildOfType(this, DartType.class));
        result.specialize(this);
        return result;
    }
    if (this instanceof DartCallExpression) {
        final DartExpression expression = ((DartCallExpression) this).getExpression();
        final DartClassResolveResult leftResult = tryGetLeftResolveResult(expression);
        if (expression instanceof DartReference) {
            final DartClassResolveResult result = DartResolveUtil.getDartClassResolveResult(((DartReference) expression).resolve(), leftResult.getSpecialization());
            result.specialize(this);
            return result;
        }
    }
    if (this instanceof DartCascadeReferenceExpression) {
        PsiElement parent = this.getParent();
        if (parent instanceof DartValueExpression) {
            final List<DartExpression> expressionList = ((DartValueExpression) parent).getExpressionList();
            final DartExpression firstExpression = expressionList.isEmpty() ? null : expressionList.get(0);
            if (firstExpression instanceof DartReference) {
                return ((DartReference) firstExpression).resolveDartClass();
            }
        }
    }
    if (this instanceof DartAwaitExpression) {
        final DartExpression expression = ((DartAwaitExpression) this).getExpression();
        if (expression instanceof DartReference) {
            final DartClassResolveResult result = ((DartReference) expression).resolveDartClass();
            final DartClass resolvedClass = result.getDartClass();
            if (resolvedClass != null && "Future".equals(resolvedClass.getName())) {
                final DartClassResolveResult unwrappedFuture = result.getSpecialization().get(resolvedClass, "T");
                return unwrappedFuture == null ? DartClassResolveResult.EMPTY : unwrappedFuture;
            } else {
                return result;
            }
        }
    }
    return DartResolveUtil.getDartClassResolveResult(resolve(), tryGetLeftResolveResult(this).getSpecialization());
}
Also used : DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DartClassResolveResult (com.jetbrains.lang.dart.util.DartClassResolveResult)6 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)3 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 DartClass (com.jetbrains.lang.dart.psi.DartClass)1 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)1 Nullable (org.jetbrains.annotations.Nullable)1