Reputation: 359
I try to do my job, which is "Analysis of source code in Java applications", where I analyze uncompiled .java or .txt files.
I create this topic, where I learned that I'm going the wrong way. From what I heard, I thought that the best way to deal with the use ANTLR or JavaCC, but I can not figure out how it works and how to use it (JavaCC I could not break in). I would like to find something where I could program the "classical" in Netbeans that I use.
Would it be possible to use java.lang.reflect (in my topic someone wrote that it can be used only in compiled code)? Is there a way where I could write all this without any "supplements" or using only Java libraries?
Thanks for any valuable advice. I'm a very confused and do not know how to begin.
Here is a description of my work:
1. Selection of the host language analyzer,
2. Build a scanner (lexical analyzer),
3. Build parser (syntax analyzer),
4. Save the information obtained in the form of XML,
5. UML graphical representation of the analyzed project.
The main objective is to create UML, XML is an addition.
Upvotes: 1
Views: 755
Reputation: 308948
A much easier solution would be to acquire a UML tool that supported importing Java source and generating the diagrams for you.
Your way is fraught with difficulties. You're stuck on the input side, but you haven't even considered the graphical side yet. Drawing the diagrams won't be easy, even if you succeed in figuring out how to create an abstract syntax tree.
Upvotes: 1
Reputation: 29649
Broadly speaking, you have two choices.
If you want to work with source code, you have to build something that can interpret those files, and form a model of the programming constructs in them. This is non-trivial - you're basically building a substantial subset of a compiler, and you have to deal with a lot of housekeeping stuff - loading files, working out references to .jar files etc. and dealing with the fact the code might not actually compile. If you choose this route, your best option is ANTLR; go read the wiki and the books, and get stuck in.
The alternative is to work with compiled files - jars etc. - you can use reflection tools to interpret the code. This simplifies matters - at least you know the code compiles, and someone else has done a lot of the housekeeping. It's still not trivial.
Upvotes: 0