1 package spoon.template; 2 3 import spoon.reflect.code.CtBlock; 4 import spoon.reflect.code.CtExpression; 5 import spoon.reflect.code.CtReturn; 6 import spoon.reflect.declaration.CtClass; 7 import spoon.reflect.declaration.CtSimpleType; 8 9 17 public abstract class ExpressionTemplateParameter<T> implements 18 TemplateParameter<T> { 19 20 23 public ExpressionTemplateParameter() { 24 } 25 26 31 public abstract T expression() throws Throwable ; 32 33 public CtExpression getSubstitution(CtSimpleType<?> targetType) { 34 CtClass<?> c; 35 CtBlock<?> b; 36 c= targetType.getFactory().Template().get(this.getClass()); 37 if(c==null) { 38 c=targetType.getFactory().Class().get(this.getClass()); 39 } 40 if (this instanceof Template) { 41 b = Substitution.substitute(targetType, (Template) this, c 42 .getMethod("expression").getBody()); 43 } else { 44 b = targetType.getFactory().Core().clone(c.getMethod("expression") 45 .getBody()); 46 } 47 return ((CtReturn<?>) b.getStatements().get(0)).getReturnedExpression(); 48 } 49 50 public T S() { 51 return null; 52 } 53 } 54 | Popular Tags |