Search in sources :

Example 1 with AngularJSRepeatExpression

use of org.angularjs.lang.psi.AngularJSRepeatExpression in project intellij-plugins by JetBrains.

the class AngularJSIndexingHandler method addTypeFromResolveResult.

@Override
public boolean addTypeFromResolveResult(JSTypeEvaluator evaluator, PsiElement resolveResult, boolean hasSomeType) {
    if (!AngularIndexUtil.hasAngularJS(resolveResult.getProject()))
        return false;
    if (resolveResult instanceof JSDefinitionExpression && resolveResult.getLanguage() instanceof AngularJSLanguage) {
        final PsiElement resolveParent = resolveResult.getParent();
        if (resolveParent instanceof AngularJSAsExpression) {
            final String name = resolveParent.getFirstChild().getText();
            final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult);
            final JSType type = JSNamedType.createType(name, source, JSContext.INSTANCE);
            evaluator.addType(type, resolveResult);
            return true;
        }
    }
    if (resolveResult instanceof JSVariable && resolveResult.getLanguage() instanceof AngularJSLanguage) {
        PsiElement resolveParent = resolveResult.getParent().getParent();
        if (resolveParent instanceof AngularJSRepeatExpression) {
            if (calculateRepeatParameterType(evaluator, (AngularJSRepeatExpression) resolveParent)) {
                return true;
            }
        }
    }
    if (resolveResult instanceof JSParameter && evaluator.isFromCurrentFile(resolveResult) && isInjectable(resolveResult)) {
        final String name = ((JSParameter) resolveResult).getName();
        final JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult);
        final JSType type = JSNamedType.createType(name, source, JSContext.UNKNOWN);
        evaluator.addType(type, resolveResult);
    }
    return false;
}
Also used : JSTypeSource(com.intellij.lang.javascript.psi.types.JSTypeSource) AngularJSRepeatExpression(org.angularjs.lang.psi.AngularJSRepeatExpression) AngularJSLanguage(org.angularjs.lang.AngularJSLanguage) PsiElement(com.intellij.psi.PsiElement) AngularJSAsExpression(org.angularjs.lang.psi.AngularJSAsExpression)

Example 2 with AngularJSRepeatExpression

use of org.angularjs.lang.psi.AngularJSRepeatExpression in project intellij-plugins by JetBrains.

the class AngularJSReferenceExpressionResolver method resolve.

@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    if (myReferencedName == null)
        return ResolveResult.EMPTY_ARRAY;
    if (myRef.getParent() instanceof JSDefinitionExpression) {
        final PsiElement sibling = PsiTreeUtil.prevVisibleLeaf(myRef);
        if (sibling != null && sibling.getNode().getElementType() == JSTokenTypes.LET_KEYWORD) {
            return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        final AngularJSRepeatExpression repeat = PsiTreeUtil.getParentOfType(myRef, AngularJSRepeatExpression.class);
        if (repeat != null) {
            for (JSDefinitionExpression def : repeat.getDefinitions()) {
                if (PsiTreeUtil.isAncestor(def, myRef, true))
                    return new JSResolveResult[] { new JSResolveResult(myRef) };
            }
        }
        final AngularJSAsExpression as = PsiTreeUtil.getParentOfType(myRef, AngularJSAsExpression.class);
        if (as != null) {
            if (PsiTreeUtil.isAncestor(as.getDefinition(), myRef, true))
                return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        JSClass clazz = myRef.getQualifier() == null ? AngularJS2IndexingHandler.findDirectiveClass(myRef) : null;
        if (clazz != null && DialectDetector.isTypeScript(clazz)) {
            final TypeScriptResolveProcessor localProcessor = new TypeScriptResolveProcessor(myReferencedName, myContainingFile, myRef, incompleteCode);
            localProcessor.setToProcessHierarchy(true);
            JSReferenceExpressionImpl.doProcessLocalDeclarations(clazz, myQualifier, localProcessor, false, false, null);
            return localProcessor.getResultsAsResolveResults();
        }
    }
    if (AngularJSAsExpression.isAsControllerRef(myRef, myRef.getParent())) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularControllerIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (AngularJSFilterExpression.isFilterNameRef(myRef, myParent)) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularFilterIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (myQualifier == null) {
        final Collection<JSPsiElementBase> localVariables = getItemsByName(myReferencedName, myRef);
        if (!localVariables.isEmpty()) {
            return ContainerUtil.map2Array(localVariables, JSResolveResult.class, item -> new JSResolveResult(item));
        }
    }
    return super.resolve(expression, incompleteCode);
}
Also used : JSPsiElementBase(com.intellij.lang.javascript.psi.JSPsiElementBase) AngularJSRepeatExpression(org.angularjs.lang.psi.AngularJSRepeatExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) TypeScriptResolveProcessor(com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) AngularJSAsExpression(org.angularjs.lang.psi.AngularJSAsExpression) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 AngularJSAsExpression (org.angularjs.lang.psi.AngularJSAsExpression)2 AngularJSRepeatExpression (org.angularjs.lang.psi.AngularJSRepeatExpression)2 TypeScriptResolveProcessor (com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor)1 JSDefinitionExpression (com.intellij.lang.javascript.psi.JSDefinitionExpression)1 JSPsiElementBase (com.intellij.lang.javascript.psi.JSPsiElementBase)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSResolveResult (com.intellij.lang.javascript.psi.resolve.JSResolveResult)1 JSTypeSource (com.intellij.lang.javascript.psi.types.JSTypeSource)1 AngularJSLanguage (org.angularjs.lang.AngularJSLanguage)1 NotNull (org.jetbrains.annotations.NotNull)1