iam planning to develope one application, which will take java byte code or class diagram or metamodel as an input and produces the source code according to package structure.
But i need some suggestions like,
How to start this application, mean do there any api that convert the metamodel or byte code to source code.
You can check with Jdec framework in that case.It is doing the following functionality:
Selective Decompilation of a class file
Disassembling a java class
It is open source.
http://jdec.sourceforge.net/
I think it might be a good start.
Not sure if BCEL is what you are looking for but it's worth taking a look.
When I personally need to decompile some java bytecode I'm using JAD.
Also when you're looking for an general introduction to java bytecode for an better understanding try the two links in the comments (I'm restricted to two links per answer so I apologize the inconvenience).
Related
I've an android project opensource written in Java (Eclipse). There are about 300 classes..I wanna to be able to understand the code quicker and to have a general representation of all the classes, interfaces and to know how they are connected each other.
Is there a way in Eclips or an external utility that could help retrieve the class structure of the project?
I have not tried it, but this looks good: http://sourceforge.net/projects/jug/
EDIT: Well this one looks even better: http://www.objectaid.com/home
EDIT 2: See this, too: http://www.nwiresoftware.com/
I haven't done that yet with Java, but you can try some of the options discussed here:
How to generate UML diagrams (especially sequence diagrams) from Java code
to get UML diagrams of your code
There are quite a few UML plugins available out there for Eclipse. It's really about how much information you want and which you feel comfortable with. The most popular one I found is Object Aid but a quick Google search for UML plugins for Eclipse returns a number of options.
If you want detailed UML diagrams then I highly recommend taking a look at Enterprise Architect. It provides tight integration with Eclipse. The desktop version is quite affordable.
Is there a site where we can find JAVA API class diagrams.
It helps to be able to see the class hierarchy (example Exception class hierarchy) in a visual manner.
Thanks.
This might not be as visual as you like, but the hierarchy can be seen in the official Java docs.
If your are asking for class hierarchy in general, found this one on Javase docs
There's nothing pre-built that I know of. If you're using an IDE (Eclipse, NetBeans, Intelli-J, etc.) it almost certainly has a built-in class hierarchy browser.
That said, the online JavaDocs do have a text-based class hierarchy for every single class. As per your example, here's what it shows for Exception:
http://docs.oracle.com/javase/7/docs/api/overview-tree.html though it is not uml,but i think it is clear
althoug there is not api uml,we can look api tree
i was looking for it too, i found this germany website click here.
That site represents all class diagrams and also provided you 223 pdf files with those diagrams.
The problem is the java version (java 1.4) but it still very helpful to me.
I have recently started adding such Class diagrams along with the class lists based on search criteria on my blog. Here are few samples -
http://www.buggybread.com/2015/09/java-class-diagram-collections-classes.html
http://www.buggybread.com/2015/10/java-javaio-stream-classes.html
http://www.buggybread.com/2015/10/java-se-list-of-algorithm-classes-and.html
http://www.buggybread.com/2015/10/java-se-javalang-string-classes.html
http://www.buggybread.com/2015/10/class-diagram-java-se-javautil-map_2.html
I haven't added lot of such material for Java SE and it's still not linked and indexed properly. Still you can search either on website or on google by adding the site name to your search. Thanks.
I'd like to merge several java classes into one. I've read ASM documentation and this http://www.jroller.com/eu/entry/merging_class_methods_with_asm but I can't understand how I can achieve my goal.
Are there more detailed examples about this?
Thanks
from java 1.5 there is a feature called instrumentation which enable you to manipulate byte code of a program during runtime. In addition, you can also manipulate byte code while the class loader loads specific class to the JVM memory. the ASM framework provide you tools to manipulate byte code easily by converting byte code assembler to something readable and adding some utilities to simplify your work. notice that manipulating byte code is very advance technique and you really need to know about the JVM and byte code before doing it.
I personally suggest you will do the ideas that appear above. but if you still presist doing it i suggest you read about instrumentation here: http://www.javalobby.org/java/forums/t19309.html
and than deep dive to ASM or javaassist framework: http://sleeplessinslc.blogspot.co.il/2008/07/java-instrumentation.html
i think java assist is easier to i suggest working with that.
i hoped i help
Does anyone knows a tool for Java (something like codedom for C#) that provides a way to generate Java code to a .java file?
EDIT:
I'm building a platform the main objective of which is to automate an operation. Giving some input, I want to generate code for an external tool. So it isn't generation on runtime. I want to generate and output that to an actual file.
JET maybe outdated (I didn't use it) JET Tutorial Part 1
More Plugins for Eclipse Plugins in Code Generation
EDIT:
Sorry I don't know codedom and what features this tool implies.
Standalone is Freemarker
and Velocity see also this example
I have had some success using ASM to both modify existing classes at the bytecode level or to generate completely new classes on the fly. The tutorial walks you through this in a very understandable fashion.
ASM like most such tools generates bytecode not source. The reason for this is if you want to dynamically generate and execute new code from with a program, historically it was not straight forward to invoke the Java compiler. Therefore it was generally easier to generate and use bytecode than source.
If you need to generate and run the code immediately within your program I recommend you use bytecode manipulation tool. If all you need is Java source, I would roll my own code generator that takes my input format and generates the code. You may want to look for a framework to help you with this but since a source file is just text, usually it is just as easy to create this yourself especially if you have a custom input format.
ABSE and AtomWeaver form a code generation and model-driven-development framework where you can easily implement what you want. ABSE is a new methodology where you compose your code generator from smaller bits (called Atoms) and AtomWaver is an straightforward IDE that lets you implement, manipulate and use your generator models.
It also allows non-programmers to build programs/configurations/whatever, made from already-built parts (Atoms you have previously prepared).
This project is just being publicly launched now, and an alpha version is being made available now. ABSE is open, and AtomWeaver is free for personal and commercial use.
Get more info here : http://www.abse.info (Disclaimer: I am the project lead)
What you could try is to use an existing grammar (e.g. from ANTLR) and build the AST. Then from the AST generate the code. That should be much more robust than simple templating. For something in the middle I suggest the (eye-opening) talk from Terence Parr about StringTemplate. (Sorry, don't have the link for the talk at hand)
I am not sure what you really need, but take a look at javassist. Is it the thing you are looking for?
I'm working on a Java project and am looking for a library that creates C++ source code, much like Java Code Model (discussed here: A Java API to generate Java source files).
I answered a similar question, but for Java code. The generation technology is language neutral, but your success will depend on how much of your design you can encode in the templates (as in the Java example). I think the other approach in which you try to code your entire app in the model and then have all your code generated for you will never be more than a fantasy, however.