/** * Determines whether the given JsDoc info declares a function type. */ static boolean isFunctionTypeDeclaration(JSDocInfo info) { return info.getParameterCount() > 0 || info.hasReturnType() || info.hasThisType() || info.isConstructor() || info.isInterface(); }
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"); } } } }
/** * Determines whether the given JsDoc info declares a function type. */ static boolean isFunctionTypeDeclaration(JSDocInfo info) { return info.getParameterCount() > 0 || info.hasReturnType() || info.hasThisType() || info.isConstructor() || info.isInterface() || info.isAbstract(); }
static boolean hasAnnotatedType(JSDocInfo jsdoc) { if (jsdoc == null) { return false; } return jsdoc.hasType() || jsdoc.hasReturnType() || jsdoc.getParameterCount() > 0 || jsdoc.isConstructorOrInterface() || jsdoc.hasTypedefType() || jsdoc.hasThisType() || jsdoc.hasEnumParameterType(); }
private void visitFunction(NodeTraversal t, Node function) { JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(function); checkForAtSignCodePresence(t, function, jsDoc); if (jsDoc == null && !hasAnyInlineJsDoc(function)) { checkMissingJsDoc(t, function); } else { if (t.inGlobalScope() || hasAnyInlineJsDoc(function) || !jsDoc.getParameterNames().isEmpty() || jsDoc.hasReturnType()) { checkParams(t, function, jsDoc); } checkReturn(t, function, jsDoc); } }
/** Adds return type information to class getters */ private void addReturnTypeIfMissing( PolymerClassDefinition cls, String getterPropName, JSTypeExpression jsType) { Node classMembers = NodeUtil.getClassMembers(cls.definition); Node getter = NodeUtil.getFirstGetterMatchingKey(classMembers, getterPropName); if (getter != null) { JSDocInfo info = NodeUtil.getBestJSDocInfo(getter); if (info == null || !info.hasReturnType()) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(info); builder.recordReturnType(jsType); getter.setJSDocInfo(builder.build()); } } }
/** * @deprecated This method is quite heuristic, looking for @type annotations that start with * "function". Other methods like containsDeclaration() and containsTypeDefinition are generally * preferred. * @return Whether there is a declaration of a callable type. */ @Deprecated public boolean containsFunctionDeclaration() { boolean hasFunctionType = hasType() && getType().getRoot().isFunction(); return hasFunctionType || hasReturnType() || hasThisType() || getParameterCount() > 0 || getFlag(MASK_CONSTRUCTOR) || (getFlag(MASK_NOSIDEEFFECTS) && !hasType()); }
/** * @return Whether there is a declaration present on this {@link JSDocInfo}. */ public boolean containsDeclaration() { return (hasType() || hasReturnType() || hasEnumParameterType() || hasTypedefType() || hasThisType() || getParameterCount() > 0 || visibility != Visibility.INHERITED || getFlag(MASK_CONSTANT | MASK_CONSTRUCTOR | MASK_DEFINE | MASK_OVERRIDE | MASK_EXPORT | MASK_EXPOSE | MASK_DEPRECATED | MASK_INTERFACE | MASK_IMPLICITCAST | MASK_NOSIDEEFFECTS | MASK_RECORD)); }
/** * @return Whether there is a declaration present on this {@link JSDocInfo}. */ public boolean containsDeclaration() { return (hasType() || hasReturnType() || hasEnumParameterType() || hasTypedefType() || hasThisType() || getParameterCount() > 0 || visibility != Visibility.INHERITED || getFlag(MASK_CONSTANT | MASK_CONSTRUCTOR | MASK_DEFINE | MASK_OVERRIDE | MASK_NOALIAS | MASK_EXPORT | MASK_EXPOSE | MASK_DEPRECATED | MASK_INTERFACE | MASK_IMPLICITCAST | MASK_NOSIDEEFFECTS | MASK_RECORD)); }
/** * @return True if n is a function node which is explicitly annotated * as returning a nullable type, other than {?}. */ private static boolean isReturnTypeNullable(Node n) { if (n == null || !n.isFunction()) { return false; } FunctionType functionType = n.getJSType().toMaybeFunctionType(); if (functionType == null) { // If the JSDoc declares a non-function type on a function node, we still shouldn't crash. return false; } JSType returnType = functionType.getReturnType(); if (returnType == null || returnType.isUnknownType() || !returnType.isNullable()) { return false; } JSDocInfo info = NodeUtil.getBestJSDocInfo(n); return info != null && info.hasReturnType(); }
/** * @return Whether there is a declaration of a callable type. */ public boolean containsFunctionDeclaration() { boolean hasFunctionType = hasType() && getType().getRoot().isFunction(); return hasFunctionType || hasReturnType() || hasThisType() || getParameterCount() > 0 || getFlag(MASK_CONSTRUCTOR) || (getFlag(MASK_NOSIDEEFFECTS) && !hasType()); }
/** * Whether the current doc info has other type tags, like * {@code @param} or {@code @return} or {@code @type} or etc. */ private boolean hasAnyTypeRelatedTags() { return currentInfo.isConstructor() || currentInfo.isInterface() || currentInfo.getParameterCount() > 0 || currentInfo.hasReturnType() || currentInfo.hasBaseType() || currentInfo.getExtendedInterfacesCount() > 0 || currentInfo.getLendsName() != null || currentInfo.hasThisType() || hasAnySingletonTypeTags(); }
private void visitFunction(NodeTraversal t, Node function, Node parent) { JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(function); if (jsDoc == null && !hasAnyInlineJsDoc(function)) { checkMissingJsDoc(t, function); } else { if (t.inGlobalScope() || hasAnyInlineJsDoc(function) || !jsDoc.getParameterNames().isEmpty() || jsDoc.hasReturnType()) { checkParams(t, function, jsDoc); } checkReturn(t, function, jsDoc); } if (parent.isMemberFunctionDef() && "constructor".equals(parent.getString()) && jsDoc != null && !jsDoc.getVisibility().equals(Visibility.INHERITED)) { t.report(function, CONSTRUCTOR_DISALLOWED_JSDOC); } }
/** * @return True if n is a function node which is explicitly annotated * as returning a nullable type, other than {?}. */ private static boolean isReturnTypeNullable(Node n) { if (n == null || !n.isFunction()) { return false; } FunctionType functionType = n.getJSType().toMaybeFunctionType(); if (functionType == null) { // If the JSDoc declares a non-function type on a function node, we still shouldn't crash. return false; } JSType returnType = functionType.getReturnType(); if (returnType == null || returnType.isUnknownType() || !returnType.isNullable()) { return false; } JSDocInfo info = NodeUtil.getBestJSDocInfo(n); return info != null && info.hasReturnType(); }
if (info.hasReturnType()) { visitTypeExpression(info.getReturnType(), false);
/** * Whether the current doc info has other type tags, like * {@code @param} or {@code @return} or {@code @type} or etc. */ private boolean hasAnyTypeRelatedTags() { return currentInfo.isConstructor() || currentInfo.isInterface() || currentInfo.isAbstract() || currentInfo.getParameterCount() > 0 || currentInfo.hasReturnType() || currentInfo.hasBaseType() || currentInfo.getExtendedInterfacesCount() > 0 || currentInfo.hasLendsName() || currentInfo.hasThisType() || hasAnySingletonTypeTags(); }
private void checkReturn(NodeTraversal t, Node function, JSDocInfo jsDoc) { if (jsDoc != null && (jsDoc.hasType() || jsDoc.isConstructor() || jsDoc.hasReturnType() || jsDoc.isOverride())) { return; } Node parent = function.getParent(); if (parent.isMemberFunctionDef() && parent.getString().equals("constructor")) { // ES6 class constructors should never have "@return". return; } if (function.getFirstChild().getJSDocInfo() != null) { return; } FindNonTrivialReturn finder = new FindNonTrivialReturn(); NodeTraversal.traverse(compiler, function.getLastChild(), finder); if (finder.found) { t.report(function, MISSING_RETURN_JSDOC); } }
private void checkReturn(NodeTraversal t, Node function, JSDocInfo jsDoc) { if (jsDoc != null && (jsDoc.hasType() || jsDoc.hasReturnType() || jsDoc.isOverride() || jsDoc.isConstructor())) { return; } if (function.getFirstChild().getJSDocInfo() != null) { return; } FindNonTrivialReturn finder = new FindNonTrivialReturn(); NodeTraversal.traverseEs6(compiler, function.getLastChild(), finder); if (finder.found) { t.report(function, MISSING_RETURN_JSDOC); } }