1 6 package tests.jfun.parsec.mssql; 7 8 13 final class ExpressionCaseWhen implements Expression { 14 15 18 public int getPrecedence() { 19 return Precedences.case_stmt(); 20 } 21 22 25 public void acceptVisitor(ExpressionVisitor v) { 26 v.visitCaseWhen(cases, def); 27 } 28 public boolean hasDefault(){ 29 return def != null; 30 } 31 private final BoolWhenThen[] cases; 32 private final Expression def; 33 34 38 ExpressionCaseWhen(final BoolWhenThen[] cases, final Expression def) { 39 this.cases = cases; 40 this.def = def; 41 } 42 static Expression nodef(final BoolWhenThen[] cases){ 43 return new ExpressionCaseWhen(cases, null); 44 } 45 static Expression def(final BoolWhenThen[] cases, Expression def){ 46 return new ExpressionCaseWhen(cases, def); 47 } 48 public String toString(){ 49 final StringBuffer buf = new StringBuffer ("case"); 50 for(int i=0; i<cases.length; i++){ 51 final BoolWhenThen bwt = cases[i]; 52 buf.append(" when ").append(bwt.getWhen()).append(" then ").append(bwt.getThen()); 53 } 54 if(def != null) 55 buf.append(" else ").append(def); 56 buf.append(" end"); 57 return buf.toString(); 58 } 59 } 60 | Popular Tags |