1 23 package org.objectweb.medor.expression.lib; 24 25 import org.objectweb.jorm.type.api.PType; 26 import org.objectweb.medor.expression.api.BinaryOperator; 27 import org.objectweb.medor.expression.api.Operator; 28 import org.objectweb.medor.expression.api.ParameterOperand; 29 import org.objectweb.medor.expression.api.UnaryOperator; 30 import org.objectweb.medor.expression.api.Expression; 31 import org.objectweb.medor.expression.api.Operand; 32 import org.objectweb.medor.expression.api.CalculatedParameterOperand; 33 34 37 public class ExpressionPrinter { 38 public static String e2str(Expression e) { 39 40 if (e instanceof Operand) { 41 PType type = e.getType(); 42 if (e instanceof ParameterOperand) { 43 return 44 (e instanceof CalculatedParameterOperand 45 ? "CalculatedParam(" 46 : "Param(") 47 + ((ParameterOperand) e).getName() + ", " 48 + (type == null ? "nullType" : type.getJormName()) + ", " 49 + e.toString() + ")"; 50 } 51 else 52 return e.toString(); 53 } else if (e instanceof BinaryOperator) { 54 BinaryOperator bo = (BinaryOperator) e; 55 return "(" 56 + e2str(bo.getExpression(0)) 57 + " " + bo.getOperatorString() + " " 58 + e2str(bo.getExpression(1)) 59 + ")"; 60 } else if (e instanceof UnaryOperator) { 61 UnaryOperator uo = (UnaryOperator) e; 62 return uo.getOperatorString() + "(" 63 + e2str(uo.getExpression(0)) + ")"; 64 } else if (e instanceof Operator) { 65 Operator op = (Operator) e; 66 StringBuffer s = new StringBuffer (); 67 s.append(op.getOperatorString()); 68 s.append("("); 69 String sep = ""; 70 for (int i=0; i< op.getOperandNumber(); i++) { 71 s.append(sep); 72 sep = ", "; 73 s.append(e2str(op.getExpression(i))); 74 } 75 s.append(")"); 76 return s.toString(); 77 } 78 return ""; 79 } 80 81 } 82 | Popular Tags |