1 package spoon.examples.bound.processing; 2 3 import spoon.examples.bound.annotation.Bound; 4 import spoon.examples.bound.template.BoundTemplate; 5 import spoon.processing.AbstractAnnotationProcessor; 6 import spoon.reflect.declaration.CtClass; 7 import spoon.reflect.declaration.CtExecutable; 8 import spoon.reflect.declaration.CtParameter; 9 import spoon.template.Substitution; 10 import spoon.template.Template; 11 12 public class BoundProcessor extends 13 AbstractAnnotationProcessor<Bound, CtParameter<?>> { 14 15 public void process(Bound annotation, CtParameter<?> element) { 16 CtExecutable<?> e = element.getParent(); 17 if (e.getBody() == null) 18 return; 19 if (!(e.getDeclaringType() instanceof CtClass)) { 20 return; 21 } 22 CtClass<?> type = (CtClass<?>) e.getDeclaringType(); 23 Template t = new BoundTemplate(element.getSimpleName(), annotation 24 .min(), annotation.max()); 25 e.getBody().insertBegin( 26 Substitution.substituteMethodBody(type, t, "test", getFactory() 27 .Type().createReference(Double .class))); 28 } 29 } 30 | Popular Tags |