1 52 53 package freemarker.core; 54 55 import freemarker.template.TemplateException; 56 import freemarker.template.TemplateHashModel; 57 import freemarker.template.TemplateModel; 58 59 63 final class Dot extends Expression { 64 private final Expression target; 65 private final String key; 66 67 Dot(Expression target, String key) { 68 this.target = target; 69 this.key = key; 70 } 71 72 TemplateModel _getAsTemplateModel(Environment env) throws TemplateException 73 { 74 TemplateModel leftModel = target.getAsTemplateModel(env); 75 if(leftModel instanceof TemplateHashModel) { 76 return ((TemplateHashModel) leftModel).get(key); 77 } 78 throw invalidTypeException(leftModel, target, env, "hash"); 79 } 80 81 public String getCanonicalForm() { 82 return target.getCanonicalForm() + "." + key; 83 } 84 85 boolean isLiteral() { 86 return target.isLiteral(); 87 } 88 89 Expression _deepClone(String name, Expression subst) { 90 return new Dot(target.deepClone(name, subst), key); 91 } 92 93 boolean onlyHasIdentifiers() { 94 return (target instanceof Identifier) || ((target instanceof Dot) && ((Dot) target).onlyHasIdentifiers()); 95 } 96 } | Popular Tags |