Search in sources :

Example 6 with StaticTypedSlot

use of com.google.javascript.rhino.jstype.StaticTypedSlot in project closure-compiler by google.

the class ChainableReverseAbstractInterpreter method getTypeIfRefinable.

/**
 * Returns the type of a node in the given scope if the node corresponds to a
 * name whose type is capable of being refined.
 * @return The current type of the node if it can be refined, null otherwise.
 */
protected JSType getTypeIfRefinable(Node node, FlowScope scope) {
    switch(node.getToken()) {
        case NAME:
            StaticTypedSlot nameVar = scope.getSlot(node.getString());
            if (nameVar != null) {
                JSType nameVarType = nameVar.getType();
                if (nameVarType == null) {
                    nameVarType = node.getJSType();
                }
                return nameVarType;
            }
            return null;
        case GETPROP:
            String qualifiedName = node.getQualifiedName();
            if (qualifiedName == null) {
                return null;
            }
            StaticTypedSlot propVar = scope.getSlot(qualifiedName);
            JSType propVarType = null;
            if (propVar != null) {
                propVarType = propVar.getType();
            }
            if (propVarType == null) {
                propVarType = node.getJSType();
            }
            if (propVarType == null) {
                propVarType = getNativeType(UNKNOWN_TYPE);
            }
            return propVarType;
        default:
            break;
    }
    return null;
}
Also used : StaticTypedSlot(com.google.javascript.rhino.jstype.StaticTypedSlot) JSType(com.google.javascript.rhino.jstype.JSType)

Example 7 with StaticTypedSlot

use of com.google.javascript.rhino.jstype.StaticTypedSlot in project closure-compiler by google.

the class TypeInferenceTest method getParamNameNode.

/**
 * Returns the NAME node {@code name} from the PARAM_LIST of the top level of type inference.
 */
private Node getParamNameNode(String name) {
    StaticTypedScope staticScope = checkNotNull(returnScope.getDeclarationScope(), returnScope);
    StaticTypedSlot slot = checkNotNull(staticScope.getSlot(name), staticScope);
    StaticTypedRef declaration = checkNotNull(slot.getDeclaration(), slot);
    Node node = checkNotNull(declaration.getNode(), declaration);
    assertNode(node).hasType(Token.NAME);
    assertThat(stream(node.getAncestors()).filter(Node::isParamList).collect(toImmutableList())).isNotEmpty();
    return node;
}
Also used : StaticTypedSlot(com.google.javascript.rhino.jstype.StaticTypedSlot) StaticTypedScope(com.google.javascript.rhino.jstype.StaticTypedScope) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) StaticTypedRef(com.google.javascript.rhino.jstype.StaticTypedRef)

Example 8 with StaticTypedSlot

use of com.google.javascript.rhino.jstype.StaticTypedSlot in project closure-compiler by google.

the class TypeInferenceTest method getType.

private JSType getType(String name) {
    assertWithMessage("The return scope should not be null.").that(returnScope).isNotNull();
    StaticTypedSlot var = returnScope.getSlot(name);
    assertWithMessage("The variable " + name + " is missing from the scope.").that(var).isNotNull();
    return var.getType();
}
Also used : StaticTypedSlot(com.google.javascript.rhino.jstype.StaticTypedSlot)

Aggregations

StaticTypedSlot (com.google.javascript.rhino.jstype.StaticTypedSlot)8 JSType (com.google.javascript.rhino.jstype.JSType)6 Node (com.google.javascript.rhino.Node)2 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1 StaticTypedRef (com.google.javascript.rhino.jstype.StaticTypedRef)1 StaticTypedScope (com.google.javascript.rhino.jstype.StaticTypedScope)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 HashSet (java.util.HashSet)1