Search in sources :

Example 91 with JSTypeExpression

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

the class JsdocUtil method makeBuilderWithType.

private static JSDocInfo.Builder makeBuilderWithType(@Nullable JSDocInfo oldJSDoc, Node typeAst) {
    JSDocInfo.Builder builder = JSDocInfo.Builder.maybeCopyFrom(oldJSDoc);
    builder.recordType(new JSTypeExpression(typeAst.srcrefTree(SYNTETIC_SRCINFO_NODE), SYNTHETIC_FILE_NAME));
    return builder;
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Example 92 with JSTypeExpression

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

the class ParserTest method assertNodeHasJSDocInfoWithNoJSType.

private void assertNodeHasJSDocInfoWithNoJSType(Node node) {
    JSDocInfo info = node.getJSDocInfo();
    assertWithMessage("Node has no JSDocInfo: %s", node).that(info).isNotNull();
    JSTypeExpression type = info.getType();
    assertWithMessage("JSDoc unexpectedly has type").that(type).isNull();
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Example 93 with JSTypeExpression

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

the class JsDocInfoParserTest method testInterfaceMultiExtends2.

@Test
public void testInterfaceMultiExtends2() {
    JSDocInfo jsdoc = parse(" * @extends {Extended1} \n" + " * @interface \n" + " * @extends {Extended2} \n" + " * @extends {Extended3} */");
    assertThat(jsdoc.isInterface()).isTrue();
    assertThat(jsdoc.getBaseType()).isNull();
    assertThat(jsdoc.getExtendedInterfacesCount()).isEqualTo(3);
    List<JSTypeExpression> types = jsdoc.getExtendedInterfaces();
    assertTypeEquals(createNamedType("Extended1"), types.get(0));
    assertTypeEquals(createNamedType("Extended2"), types.get(1));
    assertTypeEquals(createNamedType("Extended3"), types.get(2));
}
Also used : JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 94 with JSTypeExpression

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

the class CheckEnums method checkEnumTypeAndInitializerValues.

private static void checkEnumTypeAndInitializerValues(NodeTraversal t, Node n, JSDocInfo jsDocInfo) {
    checkArgument(n.isObjectLit(), n);
    JSTypeExpression enumTypeExpr = jsDocInfo.getEnumParameterType();
    Node enumType = enumTypeExpr.getRoot();
    boolean isStringEnum = enumType.isStringLit() && enumType.getString().equals("string");
    boolean isNumberEnum = enumType.isStringLit() && enumType.getString().equals("number");
    if (!isStringEnum && !isNumberEnum) {
        // warn on `@enum {?}`, `@enum {boolean}`, `@enum {Some|Another}`, `@enum {SomeName}` etc`
        t.report(n, ENUM_TYPE_NOT_STRING_OR_NUMBER);
    }
    if (isStringEnum) {
        checkStringEnumInitializerValues(t, n);
    }
}
Also used : Node(com.google.javascript.rhino.Node) JSTypeExpression(com.google.javascript.rhino.JSTypeExpression)

Example 95 with JSTypeExpression

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

the class JSDocInfoPrinterTest method testConstDefines.

@Test
public void testConstDefines() {
    builder.recordDefineType(new JSTypeExpression(JsDocInfoParser.parseTypeString("string"), "<testDefines>"));
    builder.recordConstancy();
    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)

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