Search in sources :

Example 1 with JSTypeRegistry

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;
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) JSType(com.google.javascript.rhino.jstype.JSType)

Example 2 with JSTypeRegistry

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)));
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) JSType(com.google.javascript.rhino.jstype.JSType)

Example 3 with JSTypeRegistry

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));
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry)

Example 4 with JSTypeRegistry

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));
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry)

Example 5 with JSTypeRegistry

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();
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry)

Aggregations

JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)9 JSType (com.google.javascript.rhino.jstype.JSType)3 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)3 Node (com.google.javascript.rhino.Node)2 NodeSubject.assertNode (com.google.javascript.jscomp.testing.NodeSubject.assertNode)1 SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 NominalTypeBuilderOti (com.google.javascript.rhino.jstype.NominalTypeBuilderOti)1