users@codemodel.java.net

Is it possible to obtain a JDefinedClass from a java.lang.Class

From: MARIE Loic <loic.marie_at_thalesgroup.com>
Date: Mon, 1 Aug 2011 15:49:45 +0200

Hello,

First of all, sorry for my poor english level...

I have one technical question : is it possible to obtain a JDefinedClass from an existing java.lang.Class ?
This from the perspective of annotating an existing Bean copy without introspecting the existing Bean.

The code snippet I attempt to do may be like this :

JCodeModel cm = new JCodeModel();

// My existing Bean
JClass baseClass = cm.ref(MyBean.class);

// Make a JDefinedClass of a MyBean copy (with methods and attributs already defined).
JDefinedClass copiedClass = cm._getClass(baseClass, "org.pkg.test.newClassName");

// Add the annotation to the myMethod() method.
copiedClass.getMethod("myMethod", null).annotate(MyAnnotation.class);

Thank you for your reply.
Best regards.

---
Loïc MARIE