use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.
the class JSTypeCreatorFromJSDoc method fillInReturnType.
private void fillInReturnType(JSDocInfo jsdoc, Node funNode, Node parent, ImmutableList<String> typeParameters, DeclaredTypeRegistry registry, FunctionTypeBuilder builder, boolean ignoreJsdoc) /* for when the jsdoc is malformed */
{
JSDocInfo inlineRetJsdoc = ignoreJsdoc || !funNode.isFunction() ? null : funNode.getFirstChild().getJSDocInfo();
JSTypeExpression retTypeExp = jsdoc == null ? null : jsdoc.getReturnType();
if (parent.isSetterDef() && retTypeExp == null) {
// inline returns for getters/setters are not parsed
builder.addRetType(this.commonTypes.UNDEFINED);
} else if (inlineRetJsdoc != null) {
builder.addRetType(getDeclaredTypeOfNode(inlineRetJsdoc, registry, typeParameters));
if (retTypeExp != null) {
warnings.add(JSError.make(funNode, TWO_JSDOCS, "the return type"));
}
} else {
builder.addRetType(getTypeFromJSTypeExpression(retTypeExp, registry, typeParameters));
}
}
use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.
the class JSTypeCreatorFromJSDoc method isRestArg.
// /** @param {...?} var_args */ function f(var_args) { ... }
// var_args shouldn't be used in the body of f
public static boolean isRestArg(JSDocInfo funJsdoc, String formalParamName) {
if (funJsdoc == null) {
return false;
}
JSTypeExpression texp = funJsdoc.getParameterType(formalParamName);
Node jsdocNode = texp == null ? null : texp.getRoot();
return jsdocNode != null && jsdocNode.getToken() == Token.ELLIPSIS;
}
use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.
the class JSTypeCreatorFromJSDoc method resolveEnum.
public void resolveEnum(EnumType e, DeclaredTypeRegistry registry) {
checkState(e != null, "getEnum should only be called when we know that the enum is defined");
if (e.isResolved()) {
return;
}
JSTypeExpression texp = e.getTypeExpr();
JSType enumeratedType;
if (texp == null) {
warnings.add(JSError.make(e.getTypeExprForErrorReporting().getRoot(), CIRCULAR_TYPEDEF_ENUM));
enumeratedType = this.commonTypes.UNKNOWN;
} else {
int numTypeVars = howmanyTypeVars;
enumeratedType = getTypeFromJSTypeExpression(texp, registry, null);
if (howmanyTypeVars > numTypeVars) {
warnings.add(JSError.make(texp.getRoot(), ENUM_WITH_TYPEVARS));
enumeratedType = this.commonTypes.UNKNOWN;
howmanyTypeVars = numTypeVars;
} else if (enumeratedType.isTop()) {
warnings.add(JSError.make(texp.getRoot(), ENUM_IS_TOP));
enumeratedType = this.commonTypes.UNKNOWN;
} else if (enumeratedType.isUnion()) {
warnings.add(JSError.make(texp.getRoot(), ENUM_IS_UNION));
enumeratedType = this.commonTypes.UNKNOWN;
}
}
e.resolveEnum(enumeratedType);
}
use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.
the class CheckJSDoc method validateDefaultValue.
/**
* Check that an arrow function is not annotated with {@constructor}.
*/
private void validateDefaultValue(Node n, JSDocInfo info) {
if (n.isDefaultValue() && n.getParent().isParamList() && info != null) {
JSTypeExpression typeExpr = info.getType();
if (typeExpr == null) {
return;
}
Node typeNode = typeExpr.getRoot();
if (typeNode.getToken() != Token.EQUALS) {
report(typeNode, DEFAULT_PARAM_MUST_BE_MARKED_OPTIONAL);
}
}
}
use of com.google.javascript.rhino.JSTypeExpression in project closure-compiler by google.
the class Es6RewriteClass method updateClassJsDoc.
/**
* @param ctorInfo the JSDocInfo from the constructor method of the ES6 class.
* @param newInfo the JSDocInfo that will be added to the constructor function in the ES3 output
*/
private void updateClassJsDoc(@Nullable JSDocInfo ctorInfo, JSDocInfoBuilder newInfo) {
// Classes are @struct by default.
if (!newInfo.isUnrestrictedRecorded() && !newInfo.isDictRecorded() && !newInfo.isStructRecorded()) {
newInfo.recordStruct();
}
if (ctorInfo != null) {
if (!ctorInfo.getSuppressions().isEmpty()) {
newInfo.recordSuppressions(ctorInfo.getSuppressions());
}
for (String param : ctorInfo.getParameterNames()) {
newInfo.recordParameter(param, ctorInfo.getParameterType(param));
newInfo.recordParameterDescription(param, ctorInfo.getDescriptionForParameter(param));
}
for (JSTypeExpression thrown : ctorInfo.getThrownTypes()) {
newInfo.recordThrowType(thrown);
newInfo.recordThrowDescription(thrown, ctorInfo.getThrowsDescriptionForType(thrown));
}
JSDocInfo.Visibility visibility = ctorInfo.getVisibility();
if (visibility != null && visibility != JSDocInfo.Visibility.INHERITED) {
newInfo.recordVisibility(visibility);
}
if (ctorInfo.isDeprecated()) {
newInfo.recordDeprecated();
}
if (ctorInfo.getDeprecationReason() != null && !newInfo.isDeprecationReasonRecorded()) {
newInfo.recordDeprecationReason(ctorInfo.getDeprecationReason());
}
newInfo.mergePropertyBitfieldFrom(ctorInfo);
for (String templateType : ctorInfo.getTemplateTypeNames()) {
newInfo.recordTemplateTypeName(templateType);
}
}
}
Aggregations