/** * Infer the return type from JSDocInfo. * @param fromInlineDoc Indicates whether return type is inferred from inline * doc attached to function name */ FunctionTypeBuilder inferReturnType( @Nullable JSDocInfo info, boolean fromInlineDoc) { if (info != null) { JSTypeExpression returnTypeExpr = fromInlineDoc ? info.getType() : info.getReturnType(); if (returnTypeExpr != null) { returnType = returnTypeExpr.evaluate(templateScope, typeRegistry); returnTypeInferred = false; } } return this; }
/** * Infer the return type from JSDocInfo. * @param fromInlineDoc Indicates whether return type is inferred from inline * doc attached to function name */ FunctionTypeBuilder inferReturnType( @Nullable JSDocInfo info, boolean fromInlineDoc) { if (info != null) { JSTypeExpression returnTypeExpr = fromInlineDoc ? info.getType() : info.getReturnType(); if (returnTypeExpr != null) { returnType = returnTypeExpr.evaluate(scope, typeRegistry); returnTypeInferred = false; } } return this; }
/** * Records a return type. * * @return {@code true} if the return type was recorded and {@code false} if * it is invalid or was already defined */ public boolean recordReturnType(JSTypeExpression jsType) { if (jsType != null && currentInfo.getReturnType() == null && !hasAnySingletonTypeTags()) { currentInfo.setReturnType(jsType); populated = true; return true; } else { return false; } }
/** * Records a return type. * * @return {@code true} if the return type was recorded and {@code false} if * it is invalid or was already defined */ public boolean recordReturnType(JSTypeExpression jsType) { if (jsType != null && currentInfo.getReturnType() == null && !hasAnySingletonTypeTags()) { currentInfo.setReturnType(jsType); populated = true; return true; } else { return false; } }
public static String toReturnTypeString(BaseReference reference) { JSTypeExpression expression = reference.getComment().getReturnType(); if (expression == null) return "void"; String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
/** * @param node A getter or setter node. */ @Nullable private JSTypeExpression getTypeFromGetterOrSetter(Node node) { JSDocInfo info = node.getJSDocInfo(); if (info != null) { boolean getter = node.isGetterDef() || node.getBooleanProp(Node.COMPUTED_PROP_GETTER); if (getter && info.getReturnType() != null) { return info.getReturnType(); } else { Set<String> paramNames = info.getParameterNames(); if (paramNames.size() == 1) { JSTypeExpression paramType = info.getParameterType(Iterables.getOnlyElement(info.getParameterNames())); if (paramType != null) { return paramType; } } } } return null; }
public static String toReturnTypeString(BaseReference reference) { JSTypeExpression expression = reference.getComment().getReturnType(); if (expression == null) return "void"; String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
public static String toReturnTypeString(BaseReference reference) { JSTypeExpression expression = reference.getComment().getReturnType(); if (expression == null) return "void"; String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
public String toReturnTypeAnnotationString() { JSType jsType = getModel().evaluate(getComment().getReturnType()); return jsType.toAnnotationString(Nullability.EXPLICIT); }
public String toReturnTypeAnnotationString() { JSType jsType = getModel().evaluate(getComment().getReturnType()); return jsType.toAnnotationString(); }
public String toReturnTypeAnnotationString() { JSType jsType = getModel().evaluate(getComment().getReturnType()); return jsType.toAnnotationString(); }
protected void emitReturns(StringBuilder sb) { if (getComment().hasReturnType()) { JSTypeExpression returnType = getComment().getReturnType(); if (returnType != null) { sb.append(indent); sb.append(" * @returns "); sb.append("{"); if (outputJS) sb.append(mapBackToJS(getModel().evaluate(returnType).toAnnotationString(), false)); else sb.append(getModel().evaluate(returnType).toAnnotationString()); sb.append("} "); String description = getComment().getReturnDescription(); if (description != null) sb.append(description); sb.append("\n"); } } }
protected void emitReturns(StringBuilder sb) { if (getComment().hasReturnType()) { JSTypeExpression returnType = getComment().getReturnType(); if (returnType != null) { sb.append(indent); sb.append(" * @returns "); sb.append("{"); if (outputJS) sb.append(mapBackToJS(getModel().evaluate(returnType).toAnnotationString(Nullability.EXPLICIT), false)); else sb.append(getModel().evaluate(returnType).toAnnotationString(Nullability.EXPLICIT)); sb.append("} "); String description = getComment().getReturnDescription(); if (description != null) sb.append(description); sb.append("\n"); } } }
protected void emitReturns(StringBuilder sb) { if (getComment().hasReturnType()) { JSTypeExpression returnType = getComment().getReturnType(); if (returnType != null) { sb.append(indent); sb.append(" * @returns "); sb.append("{"); if (outputJS) sb.append(mapBackToJS(getModel().evaluate(returnType).toAnnotationString(), false)); else sb.append(getModel().evaluate(returnType).toAnnotationString()); sb.append("} "); String description = getComment().getReturnDescription(); if (description != null) sb.append(description); sb.append("\n"); } } } }
/** * @param node A getter or setter node. */ private JSTypeExpression getTypeFromGetterOrSetter(Node node) { JSDocInfo info = node.getJSDocInfo(); if (info != null) { boolean getter = node.isGetterDef() || node.getBooleanProp(Node.COMPUTED_PROP_GETTER); if (getter && info.getReturnType() != null) { return info.getReturnType(); } else { Set<String> paramNames = info.getParameterNames(); if (paramNames.size() == 1) { return info.getParameterType(Iterables.getOnlyElement(info.getParameterNames())); } } } return new JSTypeExpression(new Node(Token.QMARK), node.getSourceFileName()); }
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 ? 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(JSType.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)); } }
else if(comment.getParameterCount() > 0 || comment.getReturnType() != null)
else if(comment.getParameterCount() > 0 || comment.getReturnType() != null)
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }