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;
}
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;
}
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();
}
Aggregations