Class LiteralExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.LiteralExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class LiteralExpr extends Object implements Expression
A literal value: integers, floats, strings, booleans, chars, or null.
-
-
Constructor Summary
Constructors Constructor Description LiteralExpr(Object value, SourceType type)Creates a literal with an unknown source location.LiteralExpr(Object value, SourceType type, SourceLocation location)Creates a literal.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()Gets the inferred type of this expression.ObjectgetValue()booleanisNull()booleanisNumeric()booleanisString()static LiteralExprofBoolean(boolean value)Creates a boolean literal.static LiteralExprofChar(char value)Creates a char literal.static LiteralExprofDouble(double value)Creates a double literal.static LiteralExprofFloat(float value)Creates a float literal.static LiteralExprofInt(int value)Creates an int literal.static LiteralExprofLong(long value)Creates a long literal.static LiteralExprofNull()Creates a null literal typed as Object.static LiteralExprofString(String value)Creates a String literal.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetType(SourceType type)voidsetValue(Object value)StringtoString()LiteralExprwithType(SourceType type)Replaces the source type.LiteralExprwithValue(Object value)Replaces the literal value.-
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, getChildren, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
LiteralExpr
public LiteralExpr(Object value, SourceType type, SourceLocation location)
Creates a literal.- Parameters:
value- the literal value, or null for the null literaltype- the literal's source typelocation- the source location, or null for unknown
-
LiteralExpr
public LiteralExpr(Object value, SourceType type)
Creates a literal with an unknown source location.- Parameters:
value- the literal value, or null for the null literaltype- the literal's source type
-
-
Method Detail
-
getValue
public Object getValue()
- Returns:
- the value
-
setValue
public void setValue(Object value)
- Parameters:
value- the new literal value
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
setType
public void setType(SourceType type)
- Parameters:
type- the new source type
-
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)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
ofInt
public static LiteralExpr ofInt(int value)
Creates an int literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofLong
public static LiteralExpr ofLong(long value)
Creates a long literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofFloat
public static LiteralExpr ofFloat(float value)
Creates a float literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofDouble
public static LiteralExpr ofDouble(double value)
Creates a double literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofBoolean
public static LiteralExpr ofBoolean(boolean value)
Creates a boolean literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofChar
public static LiteralExpr ofChar(char value)
Creates a char literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofString
public static LiteralExpr ofString(String value)
Creates a String literal.- Parameters:
value- the literal value- Returns:
- the new literal
-
ofNull
public static LiteralExpr ofNull()
Creates a null literal typed as Object.- Returns:
- the new literal
-
withValue
public LiteralExpr withValue(Object value)
Replaces the literal value.- Parameters:
value- the new literal value- Returns:
- this expression
-
withType
public LiteralExpr withType(SourceType type)
Replaces the source type.- Parameters:
type- the new source type- Returns:
- this expression
-
isNull
public boolean isNull()
- Returns:
- true if the value is null
-
isString
public boolean isString()
- Returns:
- true if the value is a String
-
isNumeric
public boolean isNumeric()
- Returns:
- true if the value is a Number
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-