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