Search in sources :

Example 1 with NodeUtil

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

the class JsDocInfoParserTest method parse.

private JSDocInfo parse(String comment, JsDocParsing parseDocumentation, boolean parseFileOverview, String... warnings) {
    TestErrorReporter errorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(parseDocumentation).setSuppressionNames(extraSuppressions).setClosurePrimitiveNames(extraPrimitives).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(Config.StrictMode.SLOPPY).build();
    StaticSourceFile file = new SimpleSourceFile("testcode", SourceKind.STRONG);
    Node templateNode = IR.script();
    templateNode.setStaticSourceFile(file);
    JsDocInfoParser jsdocParser = new JsDocInfoParser(stream(comment), comment, 0, templateNode, config, errorReporter);
    jsdocParser.parse();
    this.prevLicense = jsdocParser.getLicenseText();
    errorReporter.verifyHasEncounteredAllWarningsAndErrors();
    final JSDocInfo result;
    if (parseFileOverview) {
        result = jsdocParser.getFileOverviewJSDocInfo();
    } else {
        result = jsdocParser.retrieveAndResetParsedJSDocInfo();
    }
    if (result != null) {
        assertThat(result.getTypeNodes()).comparingElementsUsing(transforming(NodeUtil::getSourceName, "has source name that")).doesNotContain(null);
    }
    return result;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) JSDocInfo(com.google.javascript.rhino.JSDocInfo) NodeUtil(com.google.javascript.jscomp.NodeUtil)

Aggregations

NodeUtil (com.google.javascript.jscomp.NodeUtil)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 Node (com.google.javascript.rhino.Node)1 SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)1 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)1