Search in sources :

Example 96 with JSTypeExpression

use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.

the class JSDocInfoPrinterTest method testInheritance.

@Test
public void testInheritance() {
    builder.recordImplementedInterface(new JSTypeExpression(JsDocInfoParser.parseTypeString("Foo"), "<testInheritance>"));
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo("/**\n * @implements {Foo}\n */\n");
    builder.recordImplementedInterface(new JSTypeExpression(JsDocInfoParser.parseTypeString("!Foo"), "<testInheritance>"));
    info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo("/**\n * @implements {Foo}\n */\n");
    builder.recordBaseType(new JSTypeExpression(JsDocInfoParser.parseTypeString("Foo"), "<testInheritance>"));
    info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo("/**\n * @extends {Foo}\n */\n");
    builder.recordBaseType(new JSTypeExpression(JsDocInfoParser.parseTypeString("!Foo"), "<testInheritance>"));
    builder.recordImplementedInterface(new JSTypeExpression(JsDocInfoParser.parseTypeString("Bar"), "<testInheritance>"));
    builder.recordImplementedInterface(new JSTypeExpression(JsDocInfoParser.parseTypeString("Bar.Baz"), "<testInheritance>"));
    info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo("/**\n * @extends {Foo}\n * @implements {Bar}\n * @implements {Bar.Baz}\n */\n");
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 97 with JSTypeExpression

use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.

the class JSDocInfoPrinterTest method testTemplatesBound_multiple.

@Test
public void testTemplatesBound_multiple() {
    builder.recordTemplateTypeName("T", new JSTypeExpression(JsDocInfoParser.parseTypeString("!Array<number>"), ""));
    builder.recordTemplateTypeName("U", new JSTypeExpression(JsDocInfoParser.parseTypeString("boolean"), ""));
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(lines(// 
    "/**", " * @template {!Array<number>} T", " * @template {boolean} U", " */", ""));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 98 with JSTypeExpression

use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.

the class JSDocInfoPrinterTest method testDefines.

@Test
public void testDefines() {
    builder.recordDefineType(new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testDefines>"));
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo("/** @define {string} */ ");
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 99 with JSTypeExpression

use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.

the class JSDocInfoPrinterTest method testParamDescriptions.

@Test
public void testParamDescriptions() {
    builder.recordParameter("foo", new JSTypeExpression(JsDocInfoParser.parseTypeString("number"), "<testParam>"));
    builder.recordParameter("bar", new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testParam>"));
    // The parser will retain leading whitespace for descriptions.
    builder.recordParameterDescription("foo", " A number for foo");
    builder.recordParameterDescription("bar", " A multline\n     description for bar");
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(LINE_JOINER.join("/**", " * @param {number} foo A number for foo", " * @param {string} bar A multline", " *     description for bar", " */", ""));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 100 with JSTypeExpression

use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.

the class JSDocInfoPrinterTest method testAuthorReferencePrintedWithOtherAnnotations.

@Test
public void testAuthorReferencePrintedWithOtherAnnotations() {
    builder.recordType(new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testAuthor>"));
    builder.recordAuthor("John Doe.");
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(LINE_JOINER.join("/**", " * @author John Doe.", " * @type {string}", " */", ""));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Aggregations

JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)101 Node (com.google.javascript.rhino.Node)67 JSDocInfo (com.google.javascript.rhino.JSDocInfo)58 Test (org.junit.Test)26 JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)18 MemberDefinition (com.google.javascript.jscomp.PolymerPass.MemberDefinition)9 JSType (com.google.javascript.rhino.jstype.JSType)9 ArrayList (java.util.ArrayList)8 TypeDeclarationNode (com.google.javascript.rhino.Node.TypeDeclarationNode)7 Map (java.util.Map)6 NodeSubject.assertNode (com.google.javascript.jscomp.testing.NodeSubject.assertNode)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Visibility (com.google.javascript.rhino.JSDocInfo.Visibility)3 LinkedHashMap (java.util.LinkedHashMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Name (com.google.javascript.jscomp.GlobalNamespace.Name)2 Ref (com.google.javascript.jscomp.GlobalNamespace.Ref)2