Package com.google.javascript.rhino
Class JSDocInfo
- java.lang.Object
-
- com.google.javascript.rhino.JSDocInfo
-
- All Implemented Interfaces:
java.io.Serializable
public class JSDocInfo extends java.lang.Object implements java.io.SerializableJSDoc 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
JSDocInfoobjects is simplified byJSDocInfoBuilderwhich provides early incompatibility detection.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJSDocInfo.MarkerDefines a class for containing the parsing information for this JSDocInfo.static classJSDocInfo.NamePositionA piece of information (found in a marker) which contains a position with a name node.static classJSDocInfo.StringPositionA piece of information (found in a marker) which contains a position with a string.static classJSDocInfo.TypePositionA piece of information (found in a marker) which contains a position with a type expression syntax tree.static classJSDocInfo.VisibilityVisibility categories.
-
Constructor Summary
Constructors Constructor Description JSDocInfo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSuppression(java.lang.String suppression)Add a suppressed warning.booleancontainsDeclaration()NodegetAssociatedNode()java.util.Collection<java.lang.String>getAuthors()Returns the list of authors or null if none.JSTypeExpressiongetBaseType()Gets the base type specified by the@extendsannotation.java.lang.StringgetBlockDescription()Returns the block-level description or null if none specified.com.google.common.collect.ImmutableList<java.lang.String>getClassTemplateTypeNames()java.lang.StringgetDeprecationReason()Returns the deprecation reason or null if none specified.java.lang.StringgetDescription()Gets the description specified by the@descannotation.java.lang.StringgetDescriptionForParameter(java.lang.String name)Returns the description for the parameter with the given name, if its exists.JSTypeExpressiongetEnumParameterType()Gets the enum parameter type specified by the@enumannotation.java.util.List<JSTypeExpression>getExtendedInterfaces()Returns the interfaces extended by an interfaceintgetExtendedInterfacesCount()Gets the number of extended interfaces specifiedjava.lang.StringgetFileOverview()Returns the file overview or null if none specified.intgetImplementedInterfaceCount()Gets the number of interfaces specified by the@implementsannotation.java.util.List<JSTypeExpression>getImplementedInterfaces()Returns the types specified by the@implementsannotation.java.lang.StringgetLendsName()Gets the name we're lending to in a@lendsannotation.java.lang.StringgetLicense()Gets the description specified by the@licenseannotation.java.util.Collection<JSDocInfo.Marker>getMarkers()Gets the list of all markers for the documentation in this JSDoc.java.lang.StringgetMeaning()Gets the meaning specified by the@meaningannotation.java.util.Set<java.lang.String>getModifies()Returns the set of sideeffect notations.java.lang.StringgetOriginalCommentString()Returns the original JSDoc comment string.intgetParameterCount()Gets the number of parameters defined.java.util.Set<java.lang.String>getParameterNames()Returns the set of names of the defined parameters.JSTypeExpressiongetParameterType(java.lang.String parameter)Gets the parameter type.java.util.Collection<java.lang.String>getReferences()Returns the list of references or null if none.java.lang.StringgetReturnDescription()Returns the description of the returned object or null if none specified.JSTypeExpressiongetReturnType()Gets the return type specified by the@returnannotation.java.lang.StringgetSourceName()Gets the name of the source file that contains this JSDoc.java.util.Set<java.lang.String>getSuppressions()Returns the set of suppressed warnings.com.google.common.collect.ImmutableList<java.lang.String>getTemplateTypeNames()Gets the template type name.JSTypeExpressiongetThisType()Gets the type specified by the@thisannotation.java.util.List<JSTypeExpression>getThrownTypes()Returns the list of thrown types.JSTypeExpressiongetType()Gets the type specified by the@typeannotation.JSTypeExpressiongetTypedefType()Gets the typedef type specified by the@typeannotation.java.util.Collection<Node>getTypeNodes()Returns a collection of all type nodes that are a part of this JSDocInfo.java.lang.StringgetVersion()Returns the version or null if none.JSDocInfo.VisibilitygetVisibility()Gets the visibility specified by@private,@protectedor@publicannotation.booleanhasBaseType()Returns whether thisJSDocInfocontains a type for@extendsannotation.booleanhasDescriptionForParameter(java.lang.String name)Returns whether a description exists for the parameter with the specified name.booleanhasEnumParameterType()Returns whether an enum parameter type, specified using the@enumannotation, is present on this JSDoc.booleanhasFileOverview()Returns whether this has a fileoverview flag.booleanhasModifies()booleanhasParameter(java.lang.String parameter)Returns whether the parameter is defined.booleanhasParameterType(java.lang.String parameter)Returns whether the parameter has an attached type.booleanhasReturnType()Returns whether thisJSDocInfocontains a type for@returnannotation.booleanhasThisType()Returns whether thisJSDocInfocontains a type for@thisannotation.booleanhasType()Returns whether a type, specified using the@typeannotation, is present on this JSDoc.booleanhasTypedefType()Returns whether a typedef parameter type, specified using the@typedefannotation, is present on this JSDoc.booleanisConsistentIdGenerator()booleanisConstant()Returns whether the@constannotation is present on thisJSDocInfo.booleanisConstructor()Returns whether the@constructorannotation is present on thisJSDocInfo.booleanisDefine()Returns whether the@defineannotation is present on thisJSDocInfo.booleanisDeprecated()Returns whether the@deprecatedannotation is present on thisJSDocInfo.booleanisExport()Returns whether the@exportannotation is present on thisJSDocInfo.booleanisExpose()Returns whether the@exposeannotation is present on thisJSDocInfo.booleanisExterns()Returns whether the@externsannotation is present on thisJSDocInfo.booleanisHidden()Returns whether the@hiddenannotation is present on thisJSDocInfo.booleanisIdGenerator()booleanisImplicitCast()Returns whether the@implicitCastannotation is present on thisJSDocInfo.booleanisInterface()Returns whether the@interfaceannotation is present on thisJSDocInfo.booleanisJavaDispatch()Returns whether the@javadispatchannotation is present on thisJSDocInfo.booleanisNgInject()Returns whether JSDoc is annotated with@ngInjectannotation.booleanisNoAlias()Returns whether the@noaliasannotation is present on thisJSDocInfo.booleanisNoCompile()Returns whether the@nocompileannotation is present on thisJSDocInfo.booleanisNoShadow()Returns whether the@noshadowannotation is present on thisJSDocInfo.booleanisNoSideEffects()Returns whether the@nosideeffectsannotation is present on thisJSDocInfo.booleanisNoTypeCheck()Returns whether the@nocheckannotation is present on thisJSDocInfo.booleanisOverride()Returns whether the@overrideannotation is present on thisJSDocInfo.booleanisStableIdGenerator()booleanmakesDicts()Returns whether the@dictannotation is present on thisJSDocInfo.booleanmakesStructs()Returns whether the@structannotation is present on thisJSDocInfo.voidsetAssociatedNode(Node node)Sets the node associated with this JSDoc.voidsetDeprecated(boolean value)voidsetLicense(java.lang.String license)License directives can appear in multiple comments, and always apply to the entire file.voidsetVisibility(JSDocInfo.Visibility visibility)booleanshouldPreserveTry()Returns whether the@preserveTryannotation is present on thisJSDocInfo.java.lang.StringtoString()
-
-
-
Method Detail
-
setDeprecated
public void setDeprecated(boolean value)
-
isConsistentIdGenerator
public boolean isConsistentIdGenerator()
- Returns:
- whether the
@consistentIdGeneratoris present on thisJSDocInfo
-
isStableIdGenerator
public boolean isStableIdGenerator()
- Returns:
- whether the
@stableIdGeneratoris present on thisJSDocInfo.
-
isConstant
public boolean isConstant()
Returns whether the@constannotation is present on thisJSDocInfo.
-
isConstructor
public boolean isConstructor()
Returns whether the@constructorannotation is present on thisJSDocInfo.
-
makesStructs
public boolean makesStructs()
Returns whether the@structannotation is present on thisJSDocInfo.
-
makesDicts
public boolean makesDicts()
Returns whether the@dictannotation is present on thisJSDocInfo.
-
isDefine
public boolean isDefine()
-
isHidden
public boolean isHidden()
Returns whether the@hiddenannotation is present on thisJSDocInfo.
-
isNoTypeCheck
public boolean isNoTypeCheck()
Returns whether the@nocheckannotation is present on thisJSDocInfo.
-
shouldPreserveTry
public boolean shouldPreserveTry()
Returns whether the@preserveTryannotation is present on thisJSDocInfo.
-
isOverride
public boolean isOverride()
Returns whether the@overrideannotation is present on thisJSDocInfo.
-
isNoAlias
public boolean isNoAlias()
Returns whether the@noaliasannotation is present on thisJSDocInfo.
-
isDeprecated
public boolean isDeprecated()
Returns whether the@deprecatedannotation is present on thisJSDocInfo.
-
isInterface
public boolean isInterface()
Returns whether the@interfaceannotation is present on thisJSDocInfo.
-
isExport
public boolean isExport()
Returns whether the@exportannotation is present on thisJSDocInfo.
-
isExpose
public boolean isExpose()
Returns whether the@exposeannotation is present on thisJSDocInfo.
-
isNoShadow
public boolean isNoShadow()
Returns whether the@noshadowannotation is present on thisJSDocInfo.
-
isIdGenerator
public boolean isIdGenerator()
- Returns:
- whether the
@idGeneratoris present on thisJSDocInfo
-
isImplicitCast
public boolean isImplicitCast()
Returns whether the@implicitCastannotation is present on thisJSDocInfo.
-
isNoSideEffects
public boolean isNoSideEffects()
Returns whether the@nosideeffectsannotation is present on thisJSDocInfo.
-
isExterns
public boolean isExterns()
Returns whether the@externsannotation is present on thisJSDocInfo.
-
isJavaDispatch
public boolean isJavaDispatch()
Returns whether the@javadispatchannotation is present on thisJSDocInfo.
-
isNoCompile
public boolean isNoCompile()
Returns whether the@nocompileannotation is present on thisJSDocInfo.
-
containsDeclaration
public boolean containsDeclaration()
- Returns:
- Whether there is declaration present on this
JSDocInfo.
-
setVisibility
public void setVisibility(JSDocInfo.Visibility visibility)
-
addSuppression
public void addSuppression(java.lang.String suppression)
Add a suppressed warning.
-
getVisibility
public JSDocInfo.Visibility getVisibility()
Gets the visibility specified by@private,@protectedor@publicannotation. If no visibility is specified, visibility is inherited from the base class.
-
getParameterType
public JSTypeExpression getParameterType(java.lang.String parameter)
Gets the parameter type.- Parameters:
parameter- the parameter's name- Returns:
- the parameter's type or
nullif this parameter is not defined or has anulltype
-
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:
trueif the parameter has an attached type,falseif 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 not the order in which parameters are defined.- Returns:
- the set of names of the defined parameters. The returned set is immutable.
-
getParameterCount
public int getParameterCount()
Gets the number of parameters defined.
-
getThrownTypes
public java.util.List<JSTypeExpression> getThrownTypes()
Returns the list of thrown types.
-
hasType
public boolean hasType()
Returns whether a type, specified using the@typeannotation, is present on this JSDoc.
-
hasEnumParameterType
public boolean hasEnumParameterType()
Returns whether an enum parameter type, specified using the@enumannotation, is present on this JSDoc.
-
hasTypedefType
public boolean hasTypedefType()
Returns whether a typedef parameter type, specified using the@typedefannotation, is present on this JSDoc.
-
hasReturnType
public boolean hasReturnType()
Returns whether thisJSDocInfocontains a type for@returnannotation.
-
getType
public JSTypeExpression getType()
Gets the type specified by the@typeannotation.
-
getReturnType
public JSTypeExpression getReturnType()
Gets the return type specified by the@returnannotation.
-
getEnumParameterType
public JSTypeExpression getEnumParameterType()
Gets the enum parameter type specified by the@enumannotation.
-
getTypedefType
public JSTypeExpression getTypedefType()
Gets the typedef type specified by the@typeannotation.
-
getThisType
public JSTypeExpression getThisType()
Gets the type specified by the@thisannotation.
-
hasThisType
public boolean hasThisType()
Returns whether thisJSDocInfocontains a type for@thisannotation.
-
getBaseType
public JSTypeExpression getBaseType()
Gets the base type specified by the@extendsannotation.
-
getDescription
public java.lang.String getDescription()
Gets the description specified by the@descannotation.
-
getMeaning
public java.lang.String getMeaning()
Gets the meaning specified by the@meaningannotation. 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@meaningannotation.
-
getLendsName
public java.lang.String getLendsName()
Gets the name we're lending to in a@lendsannotation. In many reflection APIs, you pass an anonymous object to a function, and that function mixes the anonymous object into another object. The@lendsannotation allows the type system to track those property assignments.
-
isNgInject
public boolean isNgInject()
Returns whether JSDoc is annotated with@ngInjectannotation.
-
getLicense
public java.lang.String getLicense()
Gets the description specified by the@licenseannotation.
-
setLicense
public void setLicense(java.lang.String license)
License directives can appear in multiple comments, and always apply to the entire file. Break protection and allow outsiders to update the license string so that we can attach the license text even when the JSDocInfo has been created and tagged with other information.- Parameters:
license- String containing new license text.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hasBaseType
public boolean hasBaseType()
Returns whether thisJSDocInfocontains a type for@extendsannotation.
-
getImplementedInterfaces
public java.util.List<JSTypeExpression> getImplementedInterfaces()
Returns the types specified by the@implementsannotation.- 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@implementsannotation.
-
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.Collection<java.lang.String> getAuthors()
Returns the list of authors or null if none.
-
getReferences
public java.util.Collection<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.
-
getAssociatedNode
public Node getAssociatedNode()
-
setAssociatedNode
public void setAssociatedNode(Node node)
Sets the node associated with this JSDoc. Notice that many nodes may have pointer to the same JSDocInfo object (because we propagate it across the type graph). But there is only one canonical "owner" node of the JSDocInfo, which corresponds to its original place in the syntax tree.
-
getSourceName
public java.lang.String getSourceName()
Gets the name of the source file that contains this JSDoc.
-
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 name.
-
getClassTemplateTypeNames
public com.google.common.collect.ImmutableList<java.lang.String> getClassTemplateTypeNames()
-
getTypeNodes
public java.util.Collection<Node> getTypeNodes()
Returns a collection of all type nodes that are a part of this JSDocInfo. This includes @type, @this, @extends, @implements, @param, @throws, and @return. 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.
-
-