Package org.codehaus.groovy.ast.expr
Class PropertyExpression
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.expr.Expression
org.codehaus.groovy.ast.expr.PropertyExpression
- All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>,NodeMetaDataHandler
- Direct Known Subclasses:
AttributeExpression
Represents a property access such as the expression "foo.bar".
-
Field Summary
Fields inherited from class org.codehaus.groovy.ast.expr.Expression
EMPTY_ARRAYFields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
ConstructorsConstructorDescriptionPropertyExpression(Expression objectExpression, String propertyName) Builds a property access that is not safe, with a constant property name.PropertyExpression(Expression objectExpression, Expression property) Builds a property access that is not safe.PropertyExpression(Expression objectExpression, Expression property, boolean safe) Builds a property access, optionally with safe navigation. -
Method Summary
Modifier and TypeMethodDescriptionReturns the receiver of this property access.Returns the expression that names the property.Returns the property name when it is a constant.getText()Returns a human-readable text representation of this AST node.booleanReports this property access as dynamic.booleanIndicates whether the receiver stands for an implicitthisrather than an expression written at this property.booleanisSafe()booleanIndicates whether this access uses spread-dot navigation (*.).booleanisStatic()Returns the static-access flag.voidsetImplicitThis(boolean implicitThis) Records whether the receiver stands for an implicitthis.voidsetObjectExpression(Expression objectExpression) Replaces the receiver of this property access.voidsetSpreadSafe(boolean spreadSafe) Records whether this access uses spread-dot navigation (*.).voidsetStatic(boolean isStatic) Records whether this access targets a static member.toString()transformExpression(ExpressionTransformer transformer) Transforms this expression and any nested expressions according to the provided transformer.voidvisit(GroovyCodeVisitor visitor) Accepts a code visitor for AST traversal and transformation.Methods inherited from class org.codehaus.groovy.ast.expr.Expression
getType, setType, transformExpressions, transformExpressionsMethods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
PropertyExpression
Builds a property access that is not safe, with a constant property name.- Parameters:
objectExpression- receiver of the accesspropertyName- name stored as aConstantExpression
-
PropertyExpression
Builds a property access that is not safe.- Parameters:
objectExpression- receiver of the accessproperty- expression that yields the property name
-
PropertyExpression
Builds a property access, optionally with safe navigation.- Parameters:
objectExpression- receiver of the accessproperty- expression that yields the property namesafe-truefor?.navigation, which yieldsnullwhen the receiver isnull
-
-
Method Details
-
transformExpression
Description copied from class:ExpressionTransforms this expression and any nested expressions according to the provided transformer. This method is called during AST transformation phases and must recursively transform any nested expressions to support full AST tree transformation.- Specified by:
transformExpressionin classExpression- Parameters:
transformer- theExpressionTransformerto apply- Returns:
- a transformed copy of this expression (or this expression itself if no changes are needed)
-
visit
Description copied from class:ASTNodeAccepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.- Overrides:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-
getObjectExpression
Returns the receiver of this property access.- Returns:
- the receiver expression
-
setObjectExpression
Replaces the receiver of this property access.- Parameters:
objectExpression- the receiver to store
-
getProperty
Returns the expression that names the property.- Returns:
- the property-name expression
-
getPropertyAsString
Returns the property name when it is a constant. A non-constant property has no fixed name at this node.- Returns:
ConstantExpression.getText()of the property, ornullwhen the property is not aConstantExpression
-
getText
Description copied from class:ASTNodeReturns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type. -
isDynamic
public boolean isDynamic()Reports this property access as dynamic. This implementation always returnstrue.- Returns:
true
-
isImplicitThis
public boolean isImplicitThis()Indicates whether the receiver stands for an implicitthisrather than an expression written at this property. The flag startsfalse.- Returns:
truewhen the receiver was inserted for an implicitthis
-
setImplicitThis
public void setImplicitThis(boolean implicitThis) Records whether the receiver stands for an implicitthis.- Parameters:
implicitThis-truewhen the receiver was not written at this property
-
isSafe
public boolean isSafe()- Returns:
- is this a safe navigation, i.e. if true then if the source object is null then this navigation will return null
-
isSpreadSafe
public boolean isSpreadSafe()Indicates whether this access uses spread-dot navigation (*.). The flag startsfalse.- Returns:
truewhen the access is spread-safe
-
setSpreadSafe
public void setSpreadSafe(boolean spreadSafe) Records whether this access uses spread-dot navigation (*.).- Parameters:
spreadSafe-trueto mark the access as spread-safe
-
isStatic
public boolean isStatic()Returns the static-access flag. It startsfalseand is copied bytransformExpression(ExpressionTransformer).- Returns:
truewhen the access is marked static
-
setStatic
public void setStatic(boolean isStatic) Records whether this access targets a static member.- Parameters:
isStatic-trueto mark the access as static
-
toString
-