Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javadocs to Source code generation?

 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a set of Javadocs (HTML files) from which I wish to generate class structures (.java files).
Is it possible? (It should be..then how?).
Any tool/API available for this?
I would appreciate any pointers.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fundamentally, no, this isn't going to be possible. The javadoc does not have enough information in it to do this. It would be possible for you to parse the HTML and extract some information, such as class name, method names & signatures, some fields... but none of the implementing code for methods will be available. This information was ignored when the javadoc was generated, and there's no way to reverse engineer it just using the javadoc.
 
john guthrie
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course, xdoclet takes javadoc-style comments and generates code...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay john,
Your JR assignment is to create that doclet for the rest of us.
 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
Thanks, and I didn't mean to generate the implementation. I know it's impossible - I was just referring to generating the class structures (methods signatures and variables).
Also I don't think XDoclets would be helpful, because AFAIK it generates code from the embedded comments/tags in the source code - while the scenario here is something else. Am I right?

Originally posted by Jim Yingst:
Fundamentally, no, this isn't going to be possible. The javadoc does not have enough information in it to do this. It would be possible for you to parse the HTML and extract some information, such as class name, method names & signatures, some fields... but none of the implementing code for methods will be available. This information was ignored when the javadoc was generated, and there's no way to reverse engineer it just using the javadoc.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds right, Bhiku. Another issue is that I don't believe there's really a spec for the HTML formatting generated javadoc - Sun could change the format from release to release if they want. This has happened a few times since Java's earliest releases, though since 1.2 it's looked pretty stable. This probably isn't a big issue, but it's something to be aware of. You can study the current HTML format and make a tool that parses it to extract as much code as you can - but you can't really guarantee that the tool will work if Sun makes revisions in the future.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18091
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance you could do this to a degree. Not all JavaDocs contain quite everything, so some tweaking might be required.
Of course, since this is reverse-engineering, it's probably either been made illegal under the DMCA or will be under new, improved DMCA V2
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic