private Expression serialize(Expression e) { if (e instanceof AnnotationConstantExpression) { AnnotationConstantExpression ace = (AnnotationConstantExpression) e; return serialize((AnnotationNode) ace.getValue()); } else if (e instanceof ListExpression) { boolean annotationConstant = false; ListExpression le = (ListExpression) e; List<Expression> list = le.getExpressions(); List<Expression> newList = new ArrayList<Expression>(list.size()); for (Expression exp: list) { annotationConstant = annotationConstant || exp instanceof AnnotationConstantExpression; newList.add(serialize(exp)); } ClassNode type = ClassHelper.OBJECT_TYPE; if (annotationConstant) type = type.makeArray(); return new ArrayExpression(type, newList); } return e; }
List<Expression> outer = new ArrayList<Expression>(meta.size()); for (AnnotationNode an : meta) { Expression serialized = serialize(an); outer.add(serialized);
private Expression serialize(AnnotationNode an) { MapExpression map = new MapExpression(); for (String key : an.getMembers().keySet()) { map.addMapEntryExpression(new ConstantExpression(key), serialize(an.getMember(key))); } List<Expression> l = new ArrayList<Expression>(2); l.add(new ClassExpression(an.getClassNode())); l.add(map); return new ArrayExpression(ClassHelper.OBJECT_TYPE, l); } }
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { AnnotationCollectorTransform.ClassChanger actt = new AnnotationCollectorTransform.ClassChanger(); actt.transformClass(classNode); } }, Phases.SEMANTIC_ANALYSIS);