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 |
Null-valued placeholder for a missing size or initializer. |
static ConstantExpression |
EMPTY_STRING |
Shared empty-string constant. |
static ConstantExpression |
FALSE |
Shared Boolean.FALSE constant, typed as Boolean. |
static ConstantExpression |
NULL |
Shared null constant. |
static ConstantExpression |
PRIM_FALSE |
Boolean.FALSE with the primitive type kept, so the expression type is
boolean rather than Boolean. |
static ConstantExpression |
PRIM_TRUE |
Boolean.TRUE with the primitive type kept, so the expression type is
boolean rather than Boolean. |
static ConstantExpression |
TRUE |
Shared Boolean.TRUE constant, typed as Boolean. |
static ConstantExpression |
VOID |
Constant whose value is Void.class. |
| 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 |
Null-valued placeholder for a missing size or initializer. Callers recognize it by identity, unlike NULL.
Shared empty-string constant. An empty string literal from source has its own instance; use isEmptyStringExpression().
Shared Boolean.FALSE constant, typed as Boolean. A false
literal from source has its own instance; use isFalseExpression().
Shared null constant. A null literal from source has its own instance, so identity comparison with this field is not a null test; use isNullExpression().
Boolean.FALSE with the primitive type kept, so the expression type is
boolean rather than Boolean.
Boolean.TRUE with the primitive type kept, so the expression type is
boolean rather than Boolean.
Shared Boolean.TRUE constant, typed as Boolean. A true
literal from source has its own instance; use isTrueExpression().
Constant whose value is Void.class. Source code has no literal of this form.
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.