Search in sources :

Example 1 with DartClassResolveResult

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

the class DartParameterInfoHandler method showParameterInfo.

@Override
public void showParameterInfo(@NotNull PsiElement element, @NotNull CreateParameterInfoContext context) {
    DartFunctionDescription functionDescription = null;
    if (element instanceof DartCallExpression) {
        functionDescription = DartFunctionDescription.tryGetDescription((DartCallExpression) element);
    } else if (element instanceof DartNewExpression) {
        final DartNewExpression newExpression = (DartNewExpression) element;
        final DartType type = newExpression.getType();
        final DartClassResolveResult classResolveResult = DartResolveUtil.resolveClassByType(type);
        PsiElement psiElement = ((DartNewExpression) element).getReferenceExpression();
        psiElement = psiElement == null && type != null ? type.getReferenceExpression() : psiElement;
        final PsiElement target = psiElement != null ? ((DartReference) psiElement).resolve() : null;
        if (target instanceof DartComponentName) {
            functionDescription = DartFunctionDescription.createDescription((DartComponent) target.getParent(), classResolveResult);
        }
    } else if (element instanceof DartMetadata) {
        final DartReferenceExpression refExpression = ((DartMetadata) element).getReferenceExpression();
        final PsiElement target = refExpression.resolve();
        if (target instanceof DartComponentName) {
            functionDescription = DartFunctionDescription.createDescription((DartComponent) target.getParent(), refExpression.resolveDartClass());
        }
    }
    if (functionDescription != null) {
        context.setItemsToShow(new Object[] { functionDescription });
        context.showHint(element, element.getTextRange().getStartOffset(), this);
    }
}
Also used : DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 2 with DartClassResolveResult

use of com.jetbrains.lang.dart.util.DartClassResolveResult 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 3 with DartClassResolveResult

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

the class DartClassReferenceImpl method resolveDartClass.

@NotNull
@Override
public DartClassResolveResult resolveDartClass() {
    final DartReference childReference = PsiTreeUtil.getChildOfType(this, DartReference.class);
    if (this instanceof DartParenthesizedExpression) {
        return childReference == null ? DartClassResolveResult.EMPTY : childReference.resolveDartClass();
    }
    if (this instanceof DartArrayAccessExpression) {
        final DartReference reference = PsiTreeUtil.getChildOfType(this, DartReference.class);
        if (reference != null) {
            final DartClassResolveResult resolveResult = reference.resolveDartClass();
            final DartClass resolveResultDartClass = resolveResult.getDartClass();
            if (resolveResultDartClass == null) {
                return resolveResult;
            }
            return DartResolveUtil.getDartClassResolveResult(resolveResultDartClass.findOperator("[]", null), resolveResult.getSpecialization());
        }
    }
    if (this instanceof DartAsExpression) {
        return DartResolveUtil.resolveClassByType(((DartAsExpression) this).getType());
    }
    if (this instanceof DartStringLiteralExpression) {
        return DartResolveUtil.findCoreClass(this, "String");
    }
    if (this instanceof DartListLiteralExpression) {
        final DartClassResolveResult classResolveResult = DartResolveUtil.findCoreClass(this, "List");
        classResolveResult.specializeByParameters(((DartListLiteralExpression) this).getTypeArguments());
        return classResolveResult;
    }
    if (this instanceof DartMapLiteralExpression) {
        final DartClassResolveResult classResolveResult = DartResolveUtil.findCoreClass(this, "Map");
        classResolveResult.specializeByParameters(((DartMapLiteralExpression) this).getTypeArguments());
        return classResolveResult;
    }
    final PsiElement firstChild = getFirstChild();
    if (firstChild instanceof LeafPsiElement) {
        final String literalText = firstChild.getText();
        if ("true".equals(literalText) || "false".equals(literalText)) {
            return DartResolveUtil.findCoreClass(this, "bool");
        } else if ("null".equals(literalText)) {
            return DartClassResolveResult.EMPTY;
        } else {
            final boolean isFloat = literalText.indexOf('.') != -1 || literalText.indexOf('E') != -1 || literalText.indexOf('e') != -1;
            return DartResolveUtil.findCoreClass(this, isFloat ? "double" : "int");
        }
    }
    return DartClassResolveResult.EMPTY;
}
Also used : DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DartClassResolveResult

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

the class DartOperatorExpressionImpl method resolveDartClass.

@NotNull
@Override
public DartClassResolveResult resolveDartClass() {
    if (this instanceof DartSuffixExpression) {
        return DartResolveUtil.findCoreClass(this, "num");
    }
    final DartReference[] references = PsiTreeUtil.getChildrenOfType(this, DartReference.class);
    if (references == null || references.length == 0) {
        return DartClassResolveResult.EMPTY;
    }
    final DartClassResolveResult leftClassResolveResult = references[0].resolveDartClass();
    final DartClass dartClass = leftClassResolveResult.getDartClass();
    if (dartClass == null) {
        return DartClassResolveResult.EMPTY;
    }
    // ignore right class. it's a warning.
    final DartMethodDeclaration operator = dartClass.findOperator(getOperatorSign(), null);
    return DartResolveUtil.getDartClassResolveResult(operator, leftClassResolveResult.getSpecialization());
}
Also used : DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) NotNull(org.jetbrains.annotations.NotNull)

Example 5 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