@Override
public String generate(Context context) {
if (generatedCache != null) return generatedCache;
final AnonymousClassStructureBuilder builder
= ObjectBuilder.newInstanceOf(annotationClass, context)
.extend();
Class<? extends Annotation> annoClass = annotation.getClass();
List<Method> sortedMethods = Arrays.asList(annoClass.getDeclaredMethods());
Collections.sort(sortedMethods, new Comparator<Method>() {
@Override
public int compare(Method m1, Method m2) {
return m1.getName().compareTo(m2.getName());
}
});
for (Method method : sortedMethods) {
if (((method.getModifiers() & (Modifier.PRIVATE | Modifier.PROTECTED)) == 0)
&& (!"equals".equals(method.getName()) && !"hashCode".equals(method.getName()))) {
try {
builder.publicOverridesMethod(method.getName())
.append(Stmt.load(method.invoke(annotation)).returnValue()).finish();
}
catch (IllegalAccessException e) {
throw new RuntimeException("error generation annotation wrapper", e);
}
catch (InvocationTargetException e) {
throw new RuntimeException("error generation annotation wrapper", e);
}
}
}
return generatedCache = prettyPrintJava(builder.finish().toJavaString());
}
@Override
public MetaClass getType() {
return MetaClassFactory.get(annotationClass);