Search in sources :

Example 6 with Namespace

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

the class NTIScope method addFunNamespace.

void addFunNamespace(Node qnameNode) {
    if (qnameNode.isName()) {
        String varName = qnameNode.getString();
        checkArgument(isDefinedLocally(varName, false));
        checkState(!this.localNamespaces.containsKey(varName));
        NTIScope s = checkNotNull(this.localFunDefs.get(varName));
        this.localNamespaces.put(varName, new FunctionNamespace(this.commonTypes, varName, s, qnameNode));
    } else {
        checkArgument(!isNamespace(qnameNode));
        QualifiedName qname = QualifiedName.fromNode(qnameNode);
        Namespace ns = getNamespace(qname.getLeftmostName());
        NTIScope s = (NTIScope) ns.getDeclaration(qname).getFunctionScope();
        ns.addNamespace(qname.getAllButLeftmost(), new FunctionNamespace(this.commonTypes, qname.toString(), s, qnameNode));
    }
}
Also used : FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace) QualifiedName(com.google.javascript.jscomp.newtypes.QualifiedName) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 7 with Namespace

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

the class NTIScope method getNamespaceAfterFreezing.

private Namespace getNamespaceAfterFreezing(String typeName) {
    checkNotNull(preservedNamespaces, "Failed to preserve namespaces post-finalization");
    QualifiedName qname = QualifiedName.fromQualifiedString(typeName);
    Namespace ns = preservedNamespaces.get(qname.getLeftmostName());
    if (ns != null && !qname.isIdentifier()) {
        ns = ns.getSubnamespace(qname.getAllButLeftmost());
    }
    return ns;
}
Also used : QualifiedName(com.google.javascript.jscomp.newtypes.QualifiedName) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 8 with Namespace

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

the class NTIScope method addTypedef.

void addTypedef(Node qnameNode, Typedef td) {
    if (qnameNode.isName()) {
        checkState(!localTypedefs.containsKey(qnameNode.getString()));
        localTypedefs.put(qnameNode.getString(), td);
    } else {
        checkState(!isDefined(qnameNode));
        QualifiedName qname = QualifiedName.fromNode(qnameNode);
        Namespace ns = getNamespace(qname.getLeftmostName());
        ns.addTypedef(qname.getAllButLeftmost(), td);
        namespaceTypedefs.add(td);
    }
}
Also used : QualifiedName(com.google.javascript.jscomp.newtypes.QualifiedName) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 9 with Namespace

use of com.google.javascript.jscomp.newtypes.Namespace 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 10 with Namespace

use of com.google.javascript.jscomp.newtypes.Namespace 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)

Aggregations

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