views:

122

answers:

4

I want to get a .java file, recognize the first class in the file and getting information about annotations, methods and attributes from this class.

Is there any module in both languages that already does that? I could build up a simple regexp to do it also, but I don't known how to recognize in the regexp the braces indicating the end of the class/method.

A: 

Why are you trying this in perl/python rather than just using a javadoc-aware program that can pull out the info?

Daenyth
+2  A: 

If you load the java classes inside Jython you probably could use introspection to find the information you need.

Fabian
A: 

I would suggest Inline::Java for accessing Java class from Perl,Once you have that interface running, you can easily access methods and attributes from the class.

Nikhil Jain
A: 

You could write a lexer using regular expressions. After, you could write a finite automata (like you mentioned) to build a parser using the DFA::Simple library.

See this link for an example: http://www.perl.com/pub/a/2004/09/23/fsms.html

That is probably a lot of work, though. Consider using an existing parser generator that is mentioned here http://en.wikipedia.org/wiki/Comparison_of_parser_generators.

gnucom