|
Groovy 1.8.1 | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.expr.Expression
org.codehaus.groovy.ast.expr.BinaryExpression
org.codehaus.groovy.ast.expr.DeclarationExpression
public class DeclarationExpression extends BinaryExpression
Represents one or more local variables. Typically it is a single local variable
declared by name with an expression like "def foo" or with type "String foo". However,
the multiple assignment feature allows you to create two or more variables using using
an expression like "def (x, y) = [1, 2]".
You can access the left hand side of a declaration using either the
"getLeftExpression() : Expression" or "getVariableExpression() : VariableExpression" API.
If the declaration is a multiple assignment statement then getVariableExpression will
throw a ClassCastException because the left hand side is not a VariableExpression. The
safe way to access the VariableExpression on the left hand side is to use
"getLeftExpression()" with an instanceof check afterwards or to invoke the
"isMultipleAssignmentDeclaration() : boolean" method. If "isMultipleAssignmentDeclaration"
returns true then it is always safe to call "getVariableExpression()". If
"isMultipleAssignmentDeclaration" returns false then it is never safe to call
"getVariableExpression()".
Constructor Summary | |
DeclarationExpression(VariableExpression left, Token operation, Expression right)
Creates a DeclarationExpression for VariableExpressions like "def x" or "String y = 'foo'". |
|
DeclarationExpression(Expression left, Token operation, Expression right)
Creates a DeclarationExpression for Expressions like "def (x, y) = [1, 2]" |
Method Summary | |
---|---|
TupleExpression
|
getTupleExpression()
This method returns the left hand side of the declaration cast to the TupleExpression type. |
VariableExpression
|
getVariableExpression()
This method returns the left hand side of the declaration cast to the VariableExpression type. |
boolean
|
isMultipleAssignmentDeclaration()
This method tells you if this declaration is a multiple assignment declaration, which has the form "def (x, y) = ..." in Groovy. |
void
|
setLeftExpression(Expression leftExpression)
This method sets the leftExpression for this BinaryExpression. |
void
|
setRightExpression(Expression rightExpression)
|
Expression
|
transformExpression(ExpressionTransformer transformer)
|
void
|
visit(GroovyCodeVisitor visitor)
|
Methods inherited from class BinaryExpression | |
---|---|
getLeftExpression, getOperation, getRightExpression, getText, newAssignmentExpression, newInitializationExpression, setLeftExpression, setRightExpression, toString, transformExpression, visit |
Methods inherited from class Expression | |
---|---|
getType, setType, transformExpression, transformExpressions, transformExpressions |
Methods inherited from class AnnotatedNode | |
---|---|
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
Methods inherited from class ASTNode | |
---|---|
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getNodeMetaData, getText, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition, visit |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Constructor Detail |
---|
public DeclarationExpression(VariableExpression left, Token operation, Expression right)
left
- the left hand side of a variable declarationoperation
- the operation, typically an assignment operatorright
- the right hand side of a declaration
public DeclarationExpression(Expression left, Token operation, Expression right)
left
- the left hand side of a declaration. Must be either a VariableExpression or
a TupleExpression with at least one element.operation
- the operation, typically an assignment operatorright
- the right hand side of a declaration
Method Detail |
---|
public TupleExpression getTupleExpression()
public VariableExpression getVariableExpression()
public boolean isMultipleAssignmentDeclaration()
public void setLeftExpression(Expression leftExpression)
leftExpression
- either a VariableExpression or a TupleExpression with one or more elements.
public void setRightExpression(Expression rightExpression)
public Expression transformExpression(ExpressionTransformer transformer)
public void visit(GroovyCodeVisitor visitor)
Copyright © 2003-2010 The Codehaus. All rights reserved.