1 46 package org.codehaus.groovy.ast.expr; 47 48 import java.util.ArrayList ; 49 import java.util.Arrays ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 53 import org.codehaus.groovy.ast.GroovyCodeVisitor; 54 import org.codehaus.groovy.classgen.AsmClassGenerator2; 55 56 62 public class TupleExpression extends Expression { 63 private List expressions; 64 65 public TupleExpression() { 66 this(new ArrayList ()); 67 } 68 69 public TupleExpression(List expressions) { 70 this.expressions = expressions; 71 } 72 73 public TupleExpression(Expression[] expressionArray) { 74 this(); 75 expressions.addAll(Arrays.asList(expressionArray)); 76 } 77 78 public void addExpression(Expression expression) { 79 expressions.add(expression); 80 } 81 82 public List getExpressions() { 83 return expressions; 84 } 85 86 public void visit(GroovyCodeVisitor visitor) { 87 visitor.visitTupleExpression(this); 88 } 89 90 public Expression transformExpression(ExpressionTransformer transformer) { 91 return new TupleExpression(transformExpressions(getExpressions(), transformer)); 92 } 93 94 protected void resolveType(AsmClassGenerator2 resolver) { 95 boolean failed = false; 96 for (int i = 0; i < expressions.size(); i++) { 97 Expression expression = (Expression) expressions.get(i); 98 expression.resolve(resolver); 99 if (expression.isResolveFailed()) 100 failed = true; 101 } 102 setResolveFailed(failed); 103 } 104 105 public Expression getExpression(int i) { 106 return (Expression) expressions.get(i); 107 } 108 109 public String getText() { 110 StringBuffer buffer = new StringBuffer ("("); 111 boolean first = true; 112 for (Iterator iter = expressions.iterator(); iter.hasNext(); ) { 113 if (first) { 114 first = false; 115 } 116 else { 117 buffer.append(", "); 118 } 119 120 buffer.append(((Expression)iter.next()).getText()); 121 } 122 buffer.append(")"); 123 return buffer.toString(); 124 } 125 126 public String toString() { 127 return super.toString() + expressions; 128 } 129 } 130 | Popular Tags |