Advertisement Jump to content
Sign in to follow this  
Son of Cain

[java] java.lang.reflect and Code Generation

This topic is 4918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!