Sign in to follow this  
Son of Cain

[java] java.lang.reflect and Code Generation

Recommended Posts

Hi folks, My current project must generate Java code, and so I have to design a class that represents a legal Java method. I've searched google extensively, but all I got was tutorials about how to retrive information about methods of an existing class - which is not what I need. So, do you guys know of a good book or tutorial that deals with reflect? I've seen the Type and TypeVariable interfaces, as well as GenericDeclaration, but I couldn't figure out a way of working with them in order to generate code. Can you guys brainstorm for a while? ;) Son Of Cain

Share this post

Link to post
Share on other sites
Exactly that, thank you =D

BTW, I sticked with Velocity and its templates to generate the code I need. Fast and easily customizable!

Son Of Cain

Share this post

Link to post
Share on other sites
Here is some ant stuff for a beautifier call to JIndent (for copy paste purposes), this is just a ant target:

<!-- ================================================================== -->
<!-- Format Source Code recursively throughout the source tree -->
<!-- ================================================================== -->
<target name="format" depends="compile" description="JIndent Format" >
<java jar="lib/Jindent.jar"
classpathref="classpath" >
<arg value="-r" />
<arg value="${src}" />

You'll also need the JIndent pure java downloads from, and to put the jars from that download in the /lib dir of your project. This is not the JIndent-ant.jar but nearly all the other jars that come with the d/l.

It's nice, and you can edit this to accept a file with your custome format preferences, just like checkstyle, that is incase you find checkstyle not up to par. I don't remember if checkstyle accepts java1.5 -- I knodw the jalopy documentation says only to 1.4.1 (or so).


[Edited by - Lucidquiet on August 5, 2005 4:22:55 PM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this