Class AnnotationExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.decl.AnnotationExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class AnnotationExpr extends Object implements Expression
A Java annotation use, in marker, single-value, or normal (named-values) form.
-
-
Constructor Summary
Constructors Constructor Description AnnotationExpr(SourceType annotationType)Creates an annotation use with no values at an unknown location.AnnotationExpr(SourceType annotationType, SourceLocation location)Creates an annotation use with no values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.AnnotationExpraddValue(AnnotationValue value)Adds an element-value pair.AnnotationExpraddValue(String name, Expression value)Adds an element-value pair from a name and value.SourceTypegetAnnotationType()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.ExpressiongetSingleValue()Returns the lone "value" element's expression.SourceTypegetType()Gets the inferred type of this expression.ExpressiongetValue(String name)Looks up an element value by name.NodeList<AnnotationValue>getValues()booleanisMarker()booleanisNormal()booleanisSingleValue()voidsetAnnotationType(SourceType annotationType)Sets the annotation type.voidsetParent(ASTNode parent)Sets the parent node.StringtoString()AnnotationExprwithAnnotationType(SourceType annotationType)Sets the annotation type.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
AnnotationExpr
public AnnotationExpr(SourceType annotationType, SourceLocation location)
Creates an annotation use with no values.- Parameters:
annotationType- the annotation typelocation- the source location, or null for unknown
-
AnnotationExpr
public AnnotationExpr(SourceType annotationType)
Creates an annotation use with no values at an unknown location.- Parameters:
annotationType- the annotation type
-
-
Method Detail
-
getAnnotationType
public SourceType getAnnotationType()
- Returns:
- the annotation type
-
setAnnotationType
public void setAnnotationType(SourceType annotationType)
Sets the annotation type.- Parameters:
annotationType- the annotation type
-
getValues
public NodeList<AnnotationValue> getValues()
- Returns:
- the values
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the parent node.
-
withAnnotationType
public AnnotationExpr withAnnotationType(SourceType annotationType)
Sets the annotation type.- Parameters:
annotationType- the annotation type- Returns:
- this annotation
-
addValue
public AnnotationExpr addValue(AnnotationValue value)
Adds an element-value pair.- Parameters:
value- the pair to add- Returns:
- this annotation
-
addValue
public AnnotationExpr addValue(String name, Expression value)
Adds an element-value pair from a name and value.- Parameters:
name- the element namevalue- the element value- Returns:
- this annotation
-
isMarker
public boolean isMarker()
- Returns:
- true if this annotation has no element values (marker form)
-
isSingleValue
public boolean isSingleValue()
- Returns:
- true if the only element is named "value" (single-value form)
-
isNormal
public boolean isNormal()
- Returns:
- true if this annotation is neither marker nor single-value form
-
getSingleValue
public Expression getSingleValue()
Returns the lone "value" element's expression.- Returns:
- the value expression, or null if not in single-value form
-
getValue
public Expression getValue(String name)
Looks up an element value by name.- Parameters:
name- the element name- Returns:
- the value expression, or null if no such element
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type of this expression
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-