1 52 53 package freemarker.core; 54 55 import freemarker.template.*; 56 57 60 final class Range extends Expression { 61 62 final Expression left; 63 final Expression right; 64 65 Range(Expression left, Expression right) { 66 this.left = left; 67 this.right = right; 68 } 69 70 boolean hasRhs() { 71 return right != null; 72 } 73 74 TemplateModel _getAsTemplateModel(Environment env) 75 throws TemplateException 76 { 77 int min = EvaluationUtil.getNumber(left, env).intValue(); 78 int max = 0; 79 if (right != null) { 80 max = EvaluationUtil.getNumber(right, env).intValue(); 81 return new NumericalRange(min, max); 82 } 83 return new NumericalRange(min); 84 } 85 86 boolean isTrue(Environment env) throws TemplateException { 87 String msg = "Error " + getStartLocation() + ". " 88 + "\nExpecting a boolean here." 89 + " Expression " + this + " is a range."; 90 throw new NonBooleanException(msg, env); 91 } 92 93 public String getCanonicalForm() { 94 String rhs = right != null ? right.getCanonicalForm() : ""; 95 return left.getCanonicalForm() + ".." + rhs; 96 } 97 98 boolean isLiteral() { 99 boolean rightIsLiteral = right == null || right.isLiteral(); 100 return constantValue != null || (left.isLiteral() && rightIsLiteral); 101 } 102 103 Expression _deepClone(String name, Expression subst) { 104 return new Range(left.deepClone(name, subst), right.deepClone(name, subst)); 105 } 106 } 107 | Popular Tags |