Search in sources :

Example 31 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testTemplateBound_nullabilityIsPreserved.

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

Example 32 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testSeeReferencePrintedWithOtherAnnotations.

@Test
public void testSeeReferencePrintedWithOtherAnnotations() {
    builder.recordType(new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testSee>"));
    builder.recordReference("SomeClassName for more details");
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(LINE_JOINER.join("/**", " * @see SomeClassName for more details", " * @type {string}", " */", ""));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 33 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testInterfaceInheritance.

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

Example 34 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testAllDescriptions.

@Test
public void testAllDescriptions() {
    builder.recordBlockDescription("Description of the thing");
    builder.recordParameter("foo", new JSTypeExpression(JsDocInfoParser.parseTypeString("number"), "<testParam>"));
    builder.recordParameter("bar", new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testParam>"));
    builder.recordParameterDescription("foo", " A number for foo");
    builder.recordParameterDescription("bar", " A multline\n     description for bar");
    builder.recordReturnType(new JSTypeExpression(JsDocInfoParser.parseTypeString("boolean"), "<testReturn>"));
    builder.recordReturnDescription("The return value");
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(LINE_JOINER.join("/**", " * Description of the thing", " *", " * @param {number} foo A number for foo", " * @param {string} bar A multline", " *     description for bar", " * @return {boolean} The return value", " */", ""));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 35 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testTemplatesBound_mixedWithUnbounded.

@Test
public void testTemplatesBound_mixedWithUnbounded() {
    builder.recordTemplateTypeName("T", new JSTypeExpression(JsDocInfoParser.parseTypeString("!Object"), ""));
    builder.recordTemplateTypeName("S");
    builder.recordTemplateTypeName("R");
    builder.recordTemplateTypeName("U", new JSTypeExpression(JsDocInfoParser.parseTypeString("*"), ""));
    builder.recordTemplateTypeName("Q");
    JSDocInfo info = builder.buildAndReset();
    assertThat(jsDocInfoPrinter.print(info)).isEqualTo(lines("/**", " * @template {!Object} T", " * @template S", " * @template R", " * @template {*} U", " * @template Q", " */", ""));
}
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