/** * Returns whether this {@link JSDocInfo} contains a type for {@code @return} * annotation. */ public boolean hasReturnType() { return hasType(TYPEFIELD_RETURN); }
/** * Whether the current doc info has any of the singleton type * tags that may not appear with other type tags, like * {@code @type} or {@code @typedef}. */ private boolean hasAnySingletonTypeTags() { return currentInfo.hasType() || currentInfo.hasTypedefType() || currentInfo.hasEnumParameterType(); }
/** * Whether the current doc info has any of the singleton type * tags that may not appear with other type tags, like * {@code @type} or {@code @typedef}. */ private boolean hasAnySingletonTypeTags() { return currentInfo.hasType() || currentInfo.hasTypedefType() || currentInfo.hasEnumParameterType(); }
/** * Returns whether an enum parameter type, specified using the {@code @enum} * annotation, is present on this JSDoc. */ public boolean hasEnumParameterType() { return hasType(TYPEFIELD_ENUM); }
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(); }
/** * Returns whether a type, specified using the {@code @type} annotation, is * present on this JSDoc. */ public boolean hasType() { return hasType(TYPEFIELD_TYPE); }
/** * Returns whether an enum parameter type, specified using the {@code @enum} * annotation, is present on this JSDoc. */ public boolean hasEnumParameterType() { return hasType(TYPEFIELD_ENUM); }
/** * Returns whether a typedef parameter type, specified using the * {@code @typedef} annotation, is present on this JSDoc. */ public boolean hasTypedefType() { return hasType(TYPEFIELD_TYPEDEF); }
/** * Returns whether a type, specified using the {@code @type} annotation, is * present on this JSDoc. */ public boolean hasType() { return hasType(TYPEFIELD_TYPE); }
/** * Returns whether a typedef parameter type, specified using the * {@code @typedef} annotation, is present on this JSDoc. */ public boolean hasTypedefType() { return hasType(TYPEFIELD_TYPEDEF); }
/** * Returns whether this {@link JSDocInfo} contains a type for {@code @return} * annotation. */ public boolean hasReturnType() { return hasType(TYPEFIELD_RETURN); }
private Node maybeInjectCastNode(ParseTree node, JSDocInfo info, Node irNode) { if (node.type == ParseTreeType.PAREN_EXPRESSION && info.hasType()) { irNode = newNode(Token.CAST, irNode); } return irNode; }
private Node maybeInjectCastNode(ParseTree node, JSDocInfo info, Node irNode) { if (node.type == ParseTreeType.PAREN_EXPRESSION && info.hasType()) { irNode = newNode(Token.CAST, irNode); } return irNode; }
/** * Infers the type of {@code this}. * @param type The type of this if the info is missing. */ FunctionTypeBuilder inferThisType(JSDocInfo info, JSType type) { // Look at the @this annotation first. inferThisType(info); if (thisType == null) { ObjectType objType = ObjectType.cast(type); if (objType != null && (info == null || !info.hasType())) { thisType = objType; } } return this; }
static JSDocInfo mergeJsdocs(@Nullable JSDocInfo classicJsdoc, @Nullable JSDocInfo inlineJsdoc) { if (inlineJsdoc == null || !inlineJsdoc.hasType()) { return classicJsdoc; } JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(classicJsdoc); builder.recordType(inlineJsdoc.getType()); return builder.build(); }
/** * Infers the type of {@code this}. * @param type The type of this if the info is missing. */ FunctionTypeBuilder inferThisType(JSDocInfo info, JSType type) { // Look at the @this annotation first. inferThisType(info); if (thisType == null) { ObjectType objType = ObjectType.cast(type); if (objType != null && (info == null || !info.hasType())) { thisType = objType; } } return this; }
/** * @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()); }
/** * @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()); }
private boolean isNamedType(Node getProp) { JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(getProp); if (jsdoc != null && jsdoc.hasType() && !jsdoc.containsFunctionDeclaration()) { return false; } return this.currentScope.isNamespace(getProp) || NodeUtil.isTypedefDecl(getProp); } }
/** * Returns whether the author tried to express the concept of a namespace in Closure. TS has a * first-class keyword for it, but in Closure we need to infer it from the JSDoc. Roughly, a * namespace is a static object used for hierarchically organizing values. * * <p>TODO(rado): this might still have some false positives. A more robust check would also * verify that there are child properties (an empty namespace is not useful). */ private boolean isLikelyNamespace(JSDocInfo doc) { if (doc == null) return false; // Authors should prefer @const to express a namespace in externs, and just goog.provide it // in non-extern code. However, there are still usages of @type {Object}. JSTypeExpression type = doc.getType(); if (type != null && type.getRoot().isString() && type.getRoot().getString().equals("Object")) { return true; } return doc.hasConstAnnotation() && !doc.hasType(); }