1 52 53 package freemarker.core; 54 55 import freemarker.template.TemplateException; 56 57 61 final class ReturnInstruction extends TemplateElement { 62 63 private Expression exp; 64 65 ReturnInstruction(Expression exp) { 66 this.exp = exp; 67 } 68 69 void accept(Environment env) throws TemplateException { 70 if (exp != null) { 71 env.setLastReturnValue(exp.getAsTemplateModel(env)); 72 } 73 if (nextSibling() != null) { 74 throw new Return(); 76 } 77 if (!(getParent() instanceof Macro || getParent().getParent() instanceof Macro)) { 78 throw new Return(); 80 } 81 } 82 83 public String getCanonicalForm() { 84 String expString = exp == null ? "" : " " + exp.getCanonicalForm(); 85 return "<#return" + expString + "/>"; 86 } 87 88 public String getDescription() { 89 return "return" + " [" + getStartLocation() + "]"; 90 } 91 92 static class Return extends RuntimeException { 93 } 94 } 95 96 97 | Popular Tags |