Search in sources :

Example 1 with Declaration

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

the class NTIScope method isFunctionNamespace.

boolean isFunctionNamespace(String name) {
    checkArgument(!name.contains("."));
    checkState(isFrozen);
    Declaration d = getDeclaration(name, false);
    if (d == null || d.getFunctionScope() == null || d.getTypeOfSimpleDecl() == null) {
        return false;
    }
    return d.getTypeOfSimpleDecl().isNamespace();
}
Also used : Declaration(com.google.javascript.jscomp.newtypes.Declaration)

Example 2 with Declaration

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

the class NTIScope method isNamespace.

boolean isNamespace(String name) {
    checkArgument(!name.contains("."));
    Declaration decl = getDeclaration(name, false);
    if (decl == null) {
        return false;
    }
    JSType simpleType = decl.getTypeOfSimpleDecl();
    return decl.getNamespace() != null || (simpleType != null && simpleType.isNamespace());
}
Also used : JSType(com.google.javascript.jscomp.newtypes.JSType) Declaration(com.google.javascript.jscomp.newtypes.Declaration)

Example 3 with Declaration

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

the class NTIScope method isConstVar.

boolean isConstVar(String name) {
    checkArgument(!name.contains("."));
    Declaration decl = getDeclaration(name, false);
    return decl != null && decl.isConstant();
}
Also used : Declaration(com.google.javascript.jscomp.newtypes.Declaration)

Example 4 with Declaration

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

the class NTIScope method getTypedef.

Typedef getTypedef(QualifiedName qname) {
    Declaration decl;
    if (qname.isIdentifier()) {
        decl = getDeclaration(qname, true);
    } else {
        Namespace ns = getNamespace(qname.getLeftmostName());
        decl = ns == null ? null : ns.getDeclaration(qname.getAllButLeftmost());
    }
    return decl == null ? null : decl.getTypedef();
}
Also used : Declaration(com.google.javascript.jscomp.newtypes.Declaration) Namespace(com.google.javascript.jscomp.newtypes.Namespace) FunctionNamespace(com.google.javascript.jscomp.newtypes.FunctionNamespace)

Example 5 with Declaration

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

the class NTIScope method getDeclaredTypeOf.

@Override
public JSType getDeclaredTypeOf(String name) {
    checkArgument(!name.contains("."));
    if ("this".equals(name)) {
        if (!hasThis()) {
            return null;
        }
        return getDeclaredTypeForOwnBody().getThisType();
    }
    Declaration decl = getLocalDeclaration(name, false);
    if (decl != null) {
        if (decl.getTypeOfSimpleDecl() != null) {
            Preconditions.checkState(!decl.getTypeOfSimpleDecl().isBottom(), "%s was bottom", name);
            return decl.getTypeOfSimpleDecl();
        }
        NTIScope funScope = (NTIScope) decl.getFunctionScope();
        if (funScope != null) {
            Preconditions.checkNotNull(funScope.getDeclaredFunctionType(), "decl=%s, funScope=%s", decl, funScope);
            return this.commonTypes.fromFunctionType(funScope.getDeclaredFunctionType().toFunctionType());
        }
        checkState(decl.getNamespace() == null);
        return null;
    }
    // When a function is a namespace, the parent scope has a better type.
    if (name.equals(this.name) && !parent.isFunctionNamespace(name)) {
        return this.commonTypes.fromFunctionType(getDeclaredFunctionType().toFunctionType());
    }
    return parent == null ? null : parent.getDeclaredTypeOf(name);
}
Also used : Declaration(com.google.javascript.jscomp.newtypes.Declaration)

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