Search in sources :

Example 1 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class TypeCheckNoTranspileTest method testClosureTypesMultipleWarnings.

private void testClosureTypesMultipleWarnings(String js, List<String> descriptions) {
    compiler.initOptions(compiler.getOptions());
    Node n = compiler.parseTestCode(js);
    Node externs = IR.root();
    IR.root(externs, n);
    assertEquals("parsing error: " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
    // For processing goog.addDependency for forward typedefs.
    new ProcessClosurePrimitives(compiler, null, CheckLevel.ERROR, false).process(externs, n);
    new TypeCheck(compiler, new ClosureReverseAbstractInterpreter(registry).append(new SemanticReverseAbstractInterpreter(registry)).getFirst(), registry).processForTesting(null, n);
    assertEquals("unexpected error(s) : " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
    if (descriptions == null) {
        assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), 0, compiler.getWarningCount());
    } else {
        assertEquals("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings()), descriptions.size(), compiler.getWarningCount());
        Set<String> actualWarningDescriptions = new HashSet<>();
        for (int i = 0; i < descriptions.size(); i++) {
            actualWarningDescriptions.add(compiler.getWarnings()[i].description);
        }
        assertEquals(new HashSet<>(descriptions), actualWarningDescriptions);
    }
}
Also used : SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) Node(com.google.javascript.rhino.Node) ClosureReverseAbstractInterpreter(com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter) HashSet(java.util.HashSet)

Example 2 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class TypeCheckTest method testClosureTypesMultipleWarnings.

private void testClosureTypesMultipleWarnings(String js, List<String> descriptions) {
    compiler.initOptions(compiler.getOptions());
    Node jsRoot = IR.root(compiler.parseTestCode(js));
    Node externs = IR.root(compiler.parseTestCode(new TestExternsBuilder().addString().addClosureExterns().addExtra(CLOSURE_DEFS).build()));
    IR.root(externs, jsRoot);
    assertWithMessage("parsing error: " + Joiner.on(", ").join(compiler.getErrors())).that(compiler.getErrorCount()).isEqualTo(0);
    new GatherModuleMetadata(compiler, false, ResolutionMode.BROWSER).process(externs, jsRoot);
    // For processing goog.forwardDeclare for forward typedefs.
    new ProcessClosurePrimitives(compiler).process(externs, jsRoot);
    new TypeCheck(compiler, new ClosureReverseAbstractInterpreter(registry).append(new SemanticReverseAbstractInterpreter(registry)).getFirst(), registry).processForTesting(externs, jsRoot);
    assertWithMessage("unexpected error(s) : " + Joiner.on(", ").join(compiler.getErrors())).that(compiler.getErrorCount()).isEqualTo(0);
    if (descriptions == null) {
        assertWithMessage("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings())).that(compiler.getWarningCount()).isEqualTo(0);
    } else {
        assertWithMessage("unexpected warning(s) : " + Joiner.on(", ").join(compiler.getWarnings())).that(compiler.getWarningCount()).isEqualTo(descriptions.size());
        Set<String> actualWarningDescriptions = new HashSet<>();
        for (int i = 0; i < descriptions.size(); i++) {
            actualWarningDescriptions.add(compiler.getWarnings().get(i).getDescription());
        }
        assertThat(actualWarningDescriptions).isEqualTo(new HashSet<>(descriptions));
    }
}
Also used : SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) TestExternsBuilder(com.google.javascript.jscomp.testing.TestExternsBuilder) ClosureReverseAbstractInterpreter(com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter) HashSet(java.util.HashSet)

Example 3 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class Compiler method getReverseAbstractInterpreter.

@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
    if (abstractInterpreter == null) {
        ChainableReverseAbstractInterpreter interpreter = new SemanticReverseAbstractInterpreter(getTypeRegistry());
        if (options.closurePass) {
            interpreter = new ClosureReverseAbstractInterpreter(getTypeRegistry()).append(interpreter).getFirst();
        }
        abstractInterpreter = interpreter;
    }
    return abstractInterpreter;
}
Also used : ChainableReverseAbstractInterpreter(com.google.javascript.jscomp.type.ChainableReverseAbstractInterpreter) SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) ClosureReverseAbstractInterpreter(com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)

Example 4 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class ExpressionDecomposerTest method processForTypecheck.

private void processForTypecheck(AbstractCompiler compiler, Node jsRoot) {
    Node root = IR.root(IR.root(), IR.root(jsRoot));
    JSTypeRegistry registry = compiler.getTypeRegistry();
    (new TypeCheck(compiler, new SemanticReverseAbstractInterpreter(registry), registry)).processForTesting(root.getFirstChild(), root.getSecondChild());
    compiler.setTypeCheckingHasRun(true);
}
Also used : JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node)

Example 5 with SemanticReverseAbstractInterpreter

use of com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    interpreter = new SemanticReverseAbstractInterpreter(registry);
}
Also used : SemanticReverseAbstractInterpreter(com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter) Before(org.junit.Before)

Aggregations

SemanticReverseAbstractInterpreter (com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter)7 Node (com.google.javascript.rhino.Node)4 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)3 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)3 HashSet (java.util.HashSet)2 TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)1 ChainableReverseAbstractInterpreter (com.google.javascript.jscomp.type.ChainableReverseAbstractInterpreter)1 ReverseAbstractInterpreter (com.google.javascript.jscomp.type.ReverseAbstractInterpreter)1 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)1 Before (org.junit.Before)1 Test (org.junit.Test)1