Class JSDocInfo

  • All Implemented Interfaces:
    java.io.Serializable

    public class JSDocInfo
    extends java.lang.Object
    implements java.io.Serializable
    JSDoc information describing JavaScript code. JSDoc is represented as a unified object with fields for each JSDoc annotation, even though some combinations are incorrect. For instance, if a JSDoc describes an enum, it cannot have information about a return type. This implementation takes advantage of such incompatibilities to reuse fields for multiple purposes, reducing memory consumption.

    Constructing JSDocInfo objects is simplified by JSDocInfoBuilder which provides early incompatibility detection.

    See Also:
    Serialized Form
    • Method Detail

      • clone

        public JSDocInfo clone()
        Overrides:
        clone in class java.lang.Object
      • cloneAndReplaceTypeNames

        public JSDocInfo cloneAndReplaceTypeNames​(java.util.Set<java.lang.String> names)
        Clones this JSDoc but replaces the given names in any type related annotation with unknown type.
        Returns:
        returns the the cloned JSDocInfo
      • clone

        public JSDocInfo clone​(boolean cloneTypeNodes)
      • areEquivalent

        public static boolean areEquivalent​(JSDocInfo jsDoc1,
                                            JSDocInfo jsDoc2)
      • isConsistentIdGenerator

        public boolean isConsistentIdGenerator()
        Returns:
        whether the @idGenerator {consistent} is present on this JSDocInfo
      • isStableIdGenerator

        public boolean isStableIdGenerator()
        Returns:
        whether the @idGenerator {stable} is present on this JSDocInfo.
      • isXidGenerator

        public boolean isXidGenerator()
        Returns:
        whether the @idGenerator {xid} is present on this JSDocInfo.
      • isMappedIdGenerator

        public boolean isMappedIdGenerator()
        Returns:
        whether the @idGenerator {mapped} is present on this JSDocInfo.
      • isConstant

        public boolean isConstant()
        Returns:
        whether this JSDocInfo implies that annotated value is constant.
      • hasConstAnnotation

        public boolean hasConstAnnotation()
        Returns whether the @const annotation is present on this JSDocInfo.
      • isFinal

        public boolean isFinal()
        Returns whether the @final annotation is present on this JSDocInfo.
      • isConstructor

        public boolean isConstructor()
        Returns whether the @constructor annotation is present on this JSDocInfo.
      • isAbstract

        public boolean isAbstract()
        Returns whether the @abstract annotation is present on this JSDocInfo.
      • usesImplicitMatch

        public boolean usesImplicitMatch()
        Returns whether the @record annotation is present on this JSDocInfo.
      • makesUnrestricted

        public boolean makesUnrestricted()
        Returns whether the @unrestricted annotation is present on this JSDocInfo.
      • makesStructs

        public boolean makesStructs()
        Returns whether the @struct annotation is present on this JSDocInfo.
      • makesDicts

        public boolean makesDicts()
        Returns whether the @dict annotation is present on this JSDocInfo.
      • isDefine

        public boolean isDefine()
        Returns whether the @define annotation is present on this JSDocInfo. If this annotation is present, then the getType() method will retrieve the define type.
      • isHidden

        public boolean isHidden()
        Returns whether the @hidden annotation is present on this JSDocInfo.
      • isOverride

        public boolean isOverride()
        Returns whether the @override annotation is present on this JSDocInfo.
      • isDeprecated

        public boolean isDeprecated()
        Returns whether the @deprecated annotation is present on this JSDocInfo.
      • isInterface

        public boolean isInterface()
        Returns whether the @interface annotation is present on this JSDocInfo.
      • isConstructorOrInterface

        public boolean isConstructorOrInterface()
      • isExport

        public boolean isExport()
        Returns whether the @export annotation is present on this JSDocInfo.
      • isExpose

        public boolean isExpose()
        Returns whether the @expose annotation is present on this JSDocInfo.
      • isIdGenerator

        public boolean isIdGenerator()
        Returns:
        whether the @idGenerator is present on this JSDocInfo
      • isImplicitCast

        public boolean isImplicitCast()
        Returns whether the @implicitCast annotation is present on this JSDocInfo.
      • isNoSideEffects

        public boolean isNoSideEffects()
        Returns whether the @nosideeffects annotation is present on this JSDocInfo.
      • isExterns

        public boolean isExterns()
        Returns whether the @externs annotation is present on this JSDocInfo.
      • isTypeSummary

        public boolean isTypeSummary()
        Returns whether the @typeSummary annotation is present on this JSDocInfo.
      • isNoCompile

        public boolean isNoCompile()
        Returns whether the @nocompile annotation is present on this JSDocInfo.
      • isNoCollapse

        public boolean isNoCollapse()
        Returns whether the @nocollapse annotation is present on this JSDocInfo.
      • isNoInline

        public boolean isNoInline()
        Returns whether the @noinline annotation is present on this JSDocInfo.
      • containsDeclarationExcludingTypelessConst

        public boolean containsDeclarationExcludingTypelessConst()
        Returns whether there is a declaration present on this JSDocInfo.

        Does not consider `@const` (without a following type) to indicate a declaration. Whether you want this method, or the`containsDeclaration` that includes const, depends on whether you want to consider /** @const * / a.b.c = 0 a declaration or not.

      • containsTypeDeclaration

        public boolean containsTypeDeclaration()
        Returns whether this JSDoc contains a type declaration such as /** @type {string}
      • containsDeclaration

        public boolean containsDeclaration()
        Returns whether there is a declaration present on this JSDocInfo, including a typeless @const like /** @const * / a.b.c = 0
      • containsFunctionDeclaration

        @Deprecated
        public boolean containsFunctionDeclaration()
        Deprecated.
        This method is quite heuristic, looking for @type annotations that start with "function". Other methods like containsDeclaration() and containsTypeDefinition are generally preferred.
        Returns:
        Whether there is a declaration of a callable type.
      • containsTypeDefinition

        public boolean containsTypeDefinition()
      • isAtSignCodePresent

        public boolean isAtSignCodePresent()
        Returns:
        whether the @code is present within this JSDocInfo.
      • getVisibility

        public JSDocInfo.Visibility getVisibility()
        Gets the visibility specified by @private, @protected or @public annotation. If no visibility is specified, visibility is inherited from the base class.
      • getParameterType

        public JSTypeExpression getParameterType​(java.lang.String parameter)
        Gets the type of a given named parameter.
        Parameters:
        parameter - the parameter's name
        Returns:
        the parameter's type or null if this parameter is not defined or has a null type
      • hasParameter

        public boolean hasParameter​(java.lang.String parameter)
        Returns whether the parameter is defined.
      • hasParameterType

        public boolean hasParameterType​(java.lang.String parameter)
        Returns whether the parameter has an attached type.
        Returns:
        true if the parameter has an attached type, false if the parameter has no attached type or does not exist.
      • getParameterNames

        public java.util.Set<java.lang.String> getParameterNames()
        Returns the set of names of the defined parameters. The iteration order of the returned set is the order in which parameters are defined in the JSDoc, rather than the order in which the function declares them.
        Returns:
        the set of names of the defined parameters. The returned set is immutable.
      • getParameterNameAt

        public java.lang.String getParameterNameAt​(int index)
        Returns the nth name in the defined parameters. The iteration order is the order in which parameters are defined in the JSDoc, rather than the order in which the function declares them.
      • getParameterCount

        public int getParameterCount()
        Gets the number of parameters defined.
      • getThrownTypes

        public java.util.List<JSTypeExpression> getThrownTypes()
        Returns the list of thrown types.
      • getThrowsDescriptionForType

        public java.lang.String getThrowsDescriptionForType​(JSTypeExpression type)
        Get the message for a given thrown type.
      • hasEnumParameterType

        public boolean hasEnumParameterType()
        Returns whether an enum parameter type, specified using the @enum annotation, is present on this JSDoc.
      • hasTypedefType

        public boolean hasTypedefType()
        Returns whether a typedef parameter type, specified using the @typedef annotation, is present on this JSDoc.
      • hasReturnType

        public boolean hasReturnType()
        Returns whether this JSDocInfo contains a type for @return annotation.
      • hasType

        public boolean hasType()
        Returns whether a type, specified using the @type annotation, is present on this JSDoc.
      • hasTypeInformation

        public boolean hasTypeInformation()
      • isInlineType

        public boolean isInlineType()
        Returns whether the type annotation was inlined.
      • getReturnType

        public JSTypeExpression getReturnType()
        Gets the return type specified by the @return annotation.
      • getEnumParameterType

        public JSTypeExpression getEnumParameterType()
        Gets the enum parameter type specified by the @enum annotation.
      • getTypedefType

        public JSTypeExpression getTypedefType()
        Gets the typedef type specified by the @type annotation.
      • getType

        public JSTypeExpression getType()
        Gets the type specified by the @type annotation.
      • getThisType

        public JSTypeExpression getThisType()
        Gets the type specified by the @this annotation.
      • hasThisType

        public boolean hasThisType()
        Returns whether this JSDocInfo contains a type for @this annotation.
      • getBaseType

        public JSTypeExpression getBaseType()
        Gets the base type specified by the @extends annotation.
      • getDescription

        public java.lang.String getDescription()
        Gets the description specified by the @desc annotation.
      • getMeaning

        public java.lang.String getMeaning()
        Gets the meaning specified by the @meaning annotation.

        In localization systems, two messages with the same content but different "meanings" may be translated differently. By default, we use the name of the variable that the message is initialized to as the "meaning" of the message.

        But some code generators (like Closure Templates) inject their own meaning with the jsdoc @meaning annotation.

      • getAlternateMessageId

        public java.lang.String getAlternateMessageId()
        Gets the alternate message ID specified by the @alternateMessageId annotation.

        In localization systems, if we migrate from one message ID algorithm to another, we can specify the old one via @alternateMessageId. This allows the product to use the previous translation while waiting for the new one to be translated.

        Some code generators (like Closure Templates) inject this.

      • getLendsName

        public JSTypeExpression getLendsName()
        Gets the name we're lending to in a @lends annotation.

        In many reflection APIs, you pass an anonymous object to a function, and that function mixes the anonymous object into another object. The @lends annotation allows the type system to track those property assignments.

      • hasLendsName

        public boolean hasLendsName()
      • getClosurePrimitiveId

        public java.lang.String getClosurePrimitiveId()
        Returns the @closurePrimitive {id} identifier
      • hasClosurePrimitiveId

        public boolean hasClosurePrimitiveId()
        Whether this JSDoc is annotated with @closurePrimitive
      • isNgInject

        public boolean isNgInject()
        Returns whether JSDoc is annotated with @ngInject annotation.
      • isWizaction

        public boolean isWizaction()
        Returns whether JSDoc is annotated with @wizaction annotation.
      • isPolymerBehavior

        public boolean isPolymerBehavior()
        Returns whether JSDoc is annotated with @polymerBehavior annotation.
      • isPolymer

        public boolean isPolymer()
        Returns whether JSDoc is annotated with @polymer annotation.
      • isCustomElement

        public boolean isCustomElement()
        Returns whether JSDoc is annotated with @customElement annotation.
      • isMixinClass

        public boolean isMixinClass()
        Returns whether JSDoc is annotated with @mixinClass annotation.
      • isMixinFunction

        public boolean isMixinFunction()
        Returns whether JSDoc is annotated with @mixinFunction annotation.
      • isDisposes

        public boolean isDisposes()
        Returns whether JSDoc is annotated with @disposes annotation.
      • disposesOf

        public boolean disposesOf​(java.lang.String parameterName)
        Return whether the function disposes of specified parameter.
      • getLicense

        public java.lang.String getLicense()
        Gets the description specified by the @license annotation.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringVerbose

        public java.lang.String toStringVerbose()
      • hasBaseType

        public boolean hasBaseType()
        Returns whether this JSDocInfo contains a type for @extends annotation.
      • getImplementedInterfaces

        public java.util.List<JSTypeExpression> getImplementedInterfaces()
        Returns the types specified by the @implements annotation.
        Returns:
        An immutable list of JSTypeExpression objects that can be resolved to types.
      • getImplementedInterfaceCount

        public int getImplementedInterfaceCount()
        Gets the number of interfaces specified by the @implements annotation.
      • getExtendedInterfaces

        public java.util.List<JSTypeExpression> getExtendedInterfaces()
        Returns the interfaces extended by an interface
        Returns:
        An immutable list of JSTypeExpression objects that can be resolved to types.
      • getExtendedInterfacesCount

        public int getExtendedInterfacesCount()
        Gets the number of extended interfaces specified
      • getDeprecationReason

        public java.lang.String getDeprecationReason()
        Returns the deprecation reason or null if none specified.
      • getSuppressions

        public java.util.Set<java.lang.String> getSuppressions()
        Returns the set of suppressed warnings.
      • getModifies

        public java.util.Set<java.lang.String> getModifies()
        Returns the set of sideeffect notations.
      • hasDescriptionForParameter

        public boolean hasDescriptionForParameter​(java.lang.String name)
        Returns whether a description exists for the parameter with the specified name.
      • getDescriptionForParameter

        public java.lang.String getDescriptionForParameter​(java.lang.String name)
        Returns the description for the parameter with the given name, if its exists.
      • getAuthors

        public java.util.List<java.lang.String> getAuthors()
        Returns the list of authors or null if none.
      • getReferences

        public java.util.List<java.lang.String> getReferences()
        Returns the list of references or null if none.
      • getVersion

        public java.lang.String getVersion()
        Returns the version or null if none.
      • getReturnDescription

        public java.lang.String getReturnDescription()
        Returns the description of the returned object or null if none specified.
      • getBlockDescription

        public java.lang.String getBlockDescription()
        Returns the block-level description or null if none specified.
      • hasFileOverview

        public boolean hasFileOverview()
        Returns whether this has a fileoverview flag.
      • getFileOverview

        public java.lang.String getFileOverview()
        Returns the file overview or null if none specified.
      • getMarkers

        public java.util.Collection<JSDocInfo.Marker> getMarkers()
        Gets the list of all markers for the documentation in this JSDoc.
      • getTemplateTypeNames

        public com.google.common.collect.ImmutableList<java.lang.String> getTemplateTypeNames()
        Gets the @template type names.

        Excludes @template types from TTL; get those with getTypeTransformations()

      • getTemplateTypes

        public com.google.common.collect.ImmutableMap<java.lang.String,​JSTypeExpression> getTemplateTypes()
      • getTypeTransformations

        public com.google.common.collect.ImmutableMap<java.lang.String,​Node> getTypeTransformations()
        Gets the type transformations.
      • getTypeExpressions

        public java.util.Collection<JSTypeExpression> getTypeExpressions()
        Returns a collection of all JSTypeExpressions that are a part of this JSDocInfo.

        This includes:

        • base type
        • @extends
        • @implements
        • @lend
        • @param
        • @return
        • @template
        • @this
        • @throws
        • @type
        Any future type specific JSDoc should make sure to add the appropriate nodes here.
        Returns:
        collection of all type nodes
      • getTypeNodes

        public java.util.Collection<Node> getTypeNodes()
        Returns a collection of all type nodes that are a part of this JSDocInfo.

        This includes:

        • @extends
        • @implements
        • @lend
        • @param
        • @return
        • @template
        • @this
        • @throws
        • @type
        Any future type specific JSDoc should make sure to add the appropriate nodes here.
        Returns:
        collection of all type nodes
      • hasModifies

        public boolean hasModifies()
      • getOriginalCommentString

        public java.lang.String getOriginalCommentString()
        Returns the original JSDoc comment string. Returns null unless parseJsDocDocumentation is enabled via the ParserConfig.
      • getOriginalCommentPosition

        public int getOriginalCommentPosition()
      • modifiesThis

        public boolean modifiesThis()
        Get the value of the @modifies{this} annotation stored in the doc info.
      • hasSideEffectsArgumentsAnnotation

        public boolean hasSideEffectsArgumentsAnnotation()
        Returns:
        Whether the @modifies annotation includes "arguments" or any named parameters.