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;
}
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();
}
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));
}
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);
}
}
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} */ ");
}
Aggregations