Search in sources :

Example 11 with Declaration

use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.

the class NTIScope method getLocalDeclaration.

private Declaration getLocalDeclaration(String name, boolean includeTypes) {
    checkArgument(!name.contains("."));
    if (!isDefinedLocally(name, includeTypes)) {
        return null;
    }
    DeclaredFunctionType declaredType = getDeclaredTypeForOwnBody();
    JSType type = null;
    boolean isTypeVar = false;
    if ("this".equals(name)) {
        type = getDeclaredTypeOf("this");
    } else if (locals.containsKey(name)) {
        type = locals.get(name).getDeclaredType();
    } else if (formals.contains(name)) {
        int formalIndex = formals.indexOf(name);
        if (declaredType != null && formalIndex != -1) {
            JSType formalType = declaredType.getFormalType(formalIndex);
            if (formalType != null && !formalType.isBottom()) {
                type = formalType;
            }
        }
    } else if (localFunDefs.containsKey(name)) {
        // external function namespaces, don't rely on localFunDefs
        if (isFrozen && externs.containsKey(name)) {
            type = externs.get(name);
        }
    } else if (localTypedefs.containsKey(name) || localNamespaces.containsKey(name)) {
    // Any further declarations are shadowed
    } else if (declaredType != null && declaredType.isTypeVariableDefinedLocally(name)) {
        isTypeVar = true;
        type = JSType.fromTypeVar(this.commonTypes, declaredType.getTypeVariableDefinedLocally(name));
    } else if (externs.containsKey(name)) {
        type = externs.get(name);
    }
    Namespace ns = null;
    if (localNamespaces.containsKey(name)) {
        ns = localNamespaces.get(name);
    } else if (preservedNamespaces != null) {
        ns = preservedNamespaces.get(name);
    }
    return new Declaration(type, localTypedefs.get(name), ns, localFunDefs.get(name), isTypeVar, constVars.contains(name));
}
Also used : JSType(com.google.javascript.jscomp.newtypes.JSType) DeclaredFunctionType(com.google.javascript.jscomp.newtypes.DeclaredFunctionType) Declaration(com.google.javascript.jscomp.newtypes.Declaration) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 12 with Declaration

use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.

the class NTIScope method getDeclaration.

@Override
public Declaration getDeclaration(QualifiedName qname, boolean includeTypes) {
    if (qname.isIdentifier()) {
        return getDeclaration(qname.getLeftmostName(), includeTypes);
    }
    Namespace ns = getNamespace(qname.getLeftmostName());
    if (ns == null) {
        return maybeGetForwardDeclaration(qname.toString());
    }
    Declaration decl = ns.getDeclaration(qname.getAllButLeftmost());
    return decl != null ? decl : maybeGetForwardDeclaration(qname.toString());
}
Also used : Declaration(com.google.javascript.jscomp.newtypes.Declaration) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 13 with Declaration

use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.

the class SimpleInference method inferPrototypeProperty.

private JSType inferPrototypeProperty(Node recv, String pname, NTIScope scope) {
    QualifiedName recvQname = QualifiedName.fromNode(recv);
    Declaration decl = scope.getDeclaration(recvQname, false);
    if (decl != null) {
        Namespace ns = decl.getNamespace();
        if (ns instanceof RawNominalType) {
            return ((RawNominalType) ns).getProtoPropDeclaredType(pname);
        }
    }
    return null;
}
Also used : QualifiedName(com.google.javascript.jscomp.newtypes.QualifiedName) RawNominalType(com.google.javascript.jscomp.newtypes.RawNominalType) Declaration(com.google.javascript.jscomp.newtypes.Declaration) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace) Namespace(com.google.javascript.jscomp.newtypes.Namespace)

Aggregations

Declaration (com.google.javascript.jscomp.newtypes.Declaration)13 FunctionNamespace (com.google.javascript.jscomp.newtypes.FunctionNamespace)6 Namespace (com.google.javascript.jscomp.newtypes.Namespace)6 JSType (com.google.javascript.jscomp.newtypes.JSType)5 QualifiedName (com.google.javascript.jscomp.newtypes.QualifiedName)3 DeclaredFunctionType (com.google.javascript.jscomp.newtypes.DeclaredFunctionType)2 RawNominalType (com.google.javascript.jscomp.newtypes.RawNominalType)2 Node (com.google.javascript.rhino.Node)2 ImmutableList (com.google.common.collect.ImmutableList)1 AbstractShallowCallback (com.google.javascript.jscomp.NodeTraversal.AbstractShallowCallback)1 EnumType (com.google.javascript.jscomp.newtypes.EnumType)1 FunctionType (com.google.javascript.jscomp.newtypes.FunctionType)1 FunctionTypeBuilder (com.google.javascript.jscomp.newtypes.FunctionTypeBuilder)1 NamespaceLit (com.google.javascript.jscomp.newtypes.NamespaceLit)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1