|
|||||||||
PREV CLASS NEXT CLASS | 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
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
an expression like: def (x, y) = [1, 2]
.
Expression getLeftExpression()
" method. In which case you might then
use instanceof
and casting to perform operations specific to a
single local variable (VariableExpression
) or for the multiple
assignment case (TupleExpression
).
Alternatively, if isMultipleAssignmentDeclaration()
is false
you can use the method "VariableExpression getVariableExpression()
" method.
Similarly, if isMultipleAssignmentDeclaration()
is true
you can use the method "TupleExpression getTupleExpression()
" method.
Calling either of these expression getters when the "isMultipleAssignment" condition
is not appropriate is unsafe and will result in a ClassCastException
.
Constructor Summary | |
---|---|
DeclarationExpression(Expression left,
Token operation,
Expression right)
Creates a DeclarationExpression for Expressions like "def (x, y) = [1, 2]" |
|
DeclarationExpression(VariableExpression left,
Token operation,
Expression right)
Creates a DeclarationExpression for VariableExpressions like "def x" or "String y = 'foo'". |
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)
Return a copy of the expression calling the transformer on any nested expressions |
void |
visit(GroovyCodeVisitor visitor)
|
Methods inherited from class org.codehaus.groovy.ast.expr.BinaryExpression |
---|
getLeftExpression, getOperation, getRightExpression, getText, newAssignmentExpression, newInitializationExpression, toString |
Methods inherited from class org.codehaus.groovy.ast.expr.Expression |
---|
getType, setType, transformExpressions, transformExpressions |
Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode |
---|
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
Methods inherited from class org.codehaus.groovy.ast.ASTNode |
---|
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getNodeMetaData, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
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 declarationpublic 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 declarationMethod Detail |
---|
public void visit(GroovyCodeVisitor visitor)
visit
in class BinaryExpression
public VariableExpression getVariableExpression()
ClassCastException
- if the left hand side is not a VariableExpression (and is probably a multiple assignment statement).public TupleExpression getTupleExpression()
ClassCastException
- if the left hand side is not a TupleExpression (and is probably a VariableExpression).public void setLeftExpression(Expression leftExpression)
setLeftExpression
in class BinaryExpression
leftExpression
- either a VariableExpression or a TupleExpression with one or more elements.public void setRightExpression(Expression rightExpression)
setRightExpression
in class BinaryExpression
public Expression transformExpression(ExpressionTransformer transformer)
Expression
transformExpression
in class BinaryExpression
public boolean isMultipleAssignmentDeclaration()
|
Copyright © 2003-2012 The Codehaus. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |