mardi 24 février 2015

Library for parsing Java code in Java



Before I get into the task behind my question and the question itself, I would like to say that I am completely open to other ways to accomplish my task. This (obviously) includes ways that are already available within Java, but I'm just not thinking of.


The Task:




Convert Java source code into Java Objects that I can then manipulate through Java.




For example:



public int multiplyNumbers(int x, int y){
return x*y;
}


The above method would be stored in a "Method" class, which would have some enums or other way of identifying that this method is "Public". It would further specify that the return type is "int", probably through the same means. There would probably be a "Return" object, that would have an enum or other way of identifying which type the return object is holding. There would be a "Parameters" object that would hold an array of objects, and in this case they would hold two "Variable" objects that would have a name of "x" and "y" respectively, and both have an enum or some other way of identifying that they are of type "int".

This is just an example of one possible implementation of a structure to hold the Java code in custom Java objects, and is just meant to give an idea of what I'm trying to accomplish.



Now, onto the question.



The Question:




Is there some free (as in beer) library that will parse Java code to correctly identify the components of a class, method, etc? And, failing that, is there somewhere that I can start to begin writing my own (again, with an emphasis on correctness) Java code parser in Java?




This is not time sensitive, I'm just trying to find a new way of playing with Java that might have benefits down the road. Would prefer Java 7+, but it's not a requirement.




Aucun commentaire:

Enregistrer un commentaire