You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Aleksei Valikov <va...@gmx.net> on 2006/11/21 14:23:53 UTC

Java CodeModel

Hi.

For all you code generators, there's a new open source project CodeModel 
available on dev.java.net:

https://codemodel.dev.java.net

The CodeModel allows you generate lexically correct Java code as Java objects 
which can be afterwords written to disk as Java or resource files.

The CodeModel was the part of JAXB RI, but now it's moved to the standalone 
project (thanks to Kohsuke Kawaguchi of Sun and Gregory Kick

Here's a usage example:

     final JMethod objectEquals = theClass.method(JMod.PUBLIC, 
theClass.owner().BOOLEAN, "equals");
     {
       final JVar object = objectEquals.param(Object.class, "object");
       final JBlock body = objectEquals.body();

       body._if(JOp.not(object._instanceof(theClass)))._then()._return(JExpr.FALSE);
       body._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);

       final JVar equalsBuilder = body.decl(
           JMod.FINAL,
           theClass.owner().ref(EqualsBuilder.class),
           "equalsBuilder",
           JExpr._new(theClass.owner().ref(getEqualsBuilderClass())));
       body.invoke("equals").arg(object).arg(equalsBuilder);
       body._return(equalsBuilder.invoke("isEquals"));
     }

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org