use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class JSTypeExpression method evaluate.
/**
* Evaluates the type expression into a {@code JSType} object.
*/
public JSType evaluate(StaticTypedScope<JSType> scope, TypeIRegistry registry) {
if (registry instanceof JSTypeRegistry) {
JSType type = ((JSTypeRegistry) registry).createTypeFromCommentNode(root, sourceName, scope);
root.setJSType(type);
return type;
}
return null;
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class TypeValidatorTest method testFunctionMismatch2.
public void testFunctionMismatch2() throws Exception {
testWarning("/** \n" + " * @param {function(string): number} x \n" + " * @return {function(boolean): number} \n" + " */ function f(x) { return x; }", TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = getLastCompiler().getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(number, bool);
assertMismatches(ImmutableList.of(new TypeMismatch(firstFunction, secondFunction, null), fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class NodeTest method testCheckTreeTypeAwareEqualsSame.
public void testCheckTreeTypeAwareEqualsSame() {
TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
Node node1 = Node.newString(Token.NAME, "f");
node1.setJSType(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
Node node2 = Node.newString(Token.NAME, "f");
node2.setJSType(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
assertTrue(node1.isEquivalentToTyped(node2));
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class NodeTest method testCheckTreeTypeAwareEqualsDifferentNull.
public void testCheckTreeTypeAwareEqualsDifferentNull() {
TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
Node node1 = Node.newString(Token.NAME, "f");
node1.setJSType(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
Node node2 = Node.newString(Token.NAME, "f");
assertFalse(node1.isEquivalentToTyped(node2));
}
use of com.google.javascript.rhino.jstype.JSTypeRegistry in project closure-compiler by google.
the class BaseJSTypeTestCase method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
errorReporter = new TestErrorReporter(null, null);
registry = new JSTypeRegistry(errorReporter, ImmutableSet.of("forwardDeclared"));
initTypes();
}
Aggregations