public class ConstantExpression
extends Expression
Represents a constant value expression such as literals (null, true, false, numbers, strings),
class literals, and other compile-time constant values. Each user-defined constant expression
maintains its own instance to preserve line and column information for accurate error reporting.
Predefined instances (e.g., NULL, TRUE, FALSE) are provided as
internal constants and should not be compared directly; use the isXXXExpression() methods instead.
| Modifiers | Name | Description |
|---|---|---|
static ConstantExpression |
EMPTY_EXPRESSION |
|
static ConstantExpression |
EMPTY_STRING |
|
static ConstantExpression |
FALSE |
|
static ConstantExpression |
NULL |
|
static ConstantExpression |
PRIM_FALSE |
|
static ConstantExpression |
PRIM_TRUE |
|
static ConstantExpression |
TRUE |
|
static ConstantExpression |
VOID |
| Fields inherited from class | Fields |
|---|---|
class Expression |
EMPTY_ARRAY |
| Constructor and description |
|---|
ConstantExpression(Object value)Creates a constant expression with the specified value. |
ConstantExpression(Object value, boolean keepPrimitive)Creates a constant expression with optional primitive type preservation. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public String |
getConstantName()Returns the constant name associated with this expression. |
|
public String |
getText() |
|
public Object |
getValue()Returns the constant value represented by this expression. |
|
public boolean |
isEmptyStringExpression()Indicates whether this constant expression represents an empty string value. |
|
public boolean |
isFalseExpression()Indicates whether this constant expression represents the boolean false value. |
|
public boolean |
isNullExpression()Indicates whether this constant expression represents a null value. |
|
public boolean |
isTrueExpression()Indicates whether this constant expression represents the boolean true value. |
|
public void |
setConstantName(String constantName)Sets the constant name for this expression. |
|
public String |
toString() |
|
public Expression |
transformExpression(ExpressionTransformer transformer) |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class Expression |
getType, setType, transformExpression, transformExpressions, transformExpressions |
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Creates a constant expression with the specified value. The type of this constant expression will be inferred from the value's class.
value - the constant value; may be null to represent a null literal Creates a constant expression with optional primitive type preservation.
If keepPrimitive is true, primitive wrapper types (Integer, Long, Boolean, etc.)
are kept as their primitive equivalents rather than boxed types.
value - the constant value; may be nullkeepPrimitive - if true, preserve primitive types for wrapper classes (e.g., Integer
becomes int); if false, use the boxed typeReturns the constant name associated with this expression. This is typically used for named constants defined in source code.
Returns the constant value represented by this expression.
Indicates whether this constant expression represents an empty string value.
Indicates whether this constant expression represents the boolean false value.
Indicates whether this constant expression represents a null value.
Indicates whether this constant expression represents the boolean true value.
Sets the constant name for this expression.
constantName - the name to associate with this constant; may be nullCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.