1 46 package org.codehaus.groovy.ast.stmt; 47 48 import java.util.ArrayList ; 49 import java.util.List ; 50 51 import org.codehaus.groovy.ast.GroovyCodeVisitor; 52 import org.codehaus.groovy.ast.expr.Expression; 53 54 60 public class SwitchStatement extends Statement { 61 62 private Expression expression; 63 private List caseStatements = new ArrayList (); 64 private Statement defaultStatement; 65 66 67 public SwitchStatement(Expression expression) { 68 this(expression, EmptyStatement.INSTANCE); 69 } 70 71 public SwitchStatement(Expression expression, Statement defaultStatement) { 72 this.expression = expression; 73 this.defaultStatement = defaultStatement; 74 } 75 76 public void visit(GroovyCodeVisitor visitor) { 77 visitor.visitSwitch(this); 78 } 79 80 public List getCaseStatements() { 81 return caseStatements; 82 } 83 84 public Expression getExpression() { 85 return expression; 86 } 87 88 public Statement getDefaultStatement() { 89 return defaultStatement; 90 } 91 92 public void setDefaultStatement(Statement defaultStatement) { 93 this.defaultStatement = defaultStatement; 94 } 95 96 public void addCase(CaseStatement caseStatement) { 97 caseStatements.add(caseStatement); 98 } 99 100 103 public CaseStatement getCaseStatement(int idx) { 104 if (idx >= 0 && idx < caseStatements.size()) { 105 return (CaseStatement) caseStatements.get(idx); 106 } 107 return null; 108 } 109 } 110 | Popular Tags |