1 package org.apache.velocity.runtime.parser.node; 2 3 18 19 20 30 31 import org.apache.velocity.context.InternalContextAdapter; 32 import org.apache.velocity.runtime.parser.Parser; 33 34 import org.apache.velocity.exception.MethodInvocationException; 35 36 public class ASTAddNode extends SimpleNode 37 { 38 public ASTAddNode(int id) 39 { 40 super(id); 41 } 42 43 public ASTAddNode(Parser p, int id) 44 { 45 super(p, id); 46 } 47 48 49 public Object jjtAccept(ParserVisitor visitor, Object data) 50 { 51 return visitor.visit(this, data); 52 } 53 54 59 public Object value( InternalContextAdapter context) 60 throws MethodInvocationException 61 { 62 65 66 Object left = jjtGetChild(0).value( context ); 67 Object right = jjtGetChild(1).value( context ); 68 69 72 73 if (left == null || right == null) 74 { 75 rsvc.error( ( left == null ? "Left" : "Right" ) 76 + " side (" 77 + jjtGetChild( (left == null? 0 : 1) ).literal() 78 + ") of addition operation has null value." 79 + " Operation not possible. " 80 + context.getCurrentTemplateName() + " [line " + getLine() 81 + ", column " + getColumn() + "]"); 82 return null; 83 } 84 85 88 89 if ( !( left instanceof Integer ) || !( right instanceof Integer )) 90 { 91 rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 92 + " side of addition operation is not a valid type. " 93 + "Currently only integers (1,2,3...) and Integer type is supported. " 94 + context.getCurrentTemplateName() + " [line " + getLine() 95 + ", column " + getColumn() + "]"); 96 97 return null; 98 } 99 100 return new Integer ( ( (Integer ) left ).intValue() + ( (Integer ) right ).intValue() ); 101 } 102 103 } 104 105 106 107 108 | Popular Tags |