1

I'm looking for a very simple way, from Python, to get information about Java classes:

  • name of the class
  • what it extends and implements
  • methods with returns types and parameters
  • attributes with type information

Basically all of the information you'd need to generate a javadoc.

Is there an existing Python library that can get me this information either for a .java or .class file, doesn't matter. I'd probably even be okay with something that gets this information from a javadoc.

I know there is javaclass library but that is overkill for what I'm looking for.

Just want to make sure something doesn't already exist like this before I implement my own.

Lex Berezhny
  • 512
  • 3
  • 15
  • 2
    "Just want to make sure something doesn't already exist like this before I implement my own." Wouldn't googling solve that problem more reliably? – blubb Sep 03 '11 at 14:12
  • What I'm looking for could easily not be a project on its own but a one-off script someone has written. Also, google is not perfect, there are plenty of tiny libraries out there that are almost impossible to find by googling. – Lex Berezhny Sep 03 '11 at 14:27
  • Can you run your python code in jython? – mmmmmm Sep 03 '11 at 14:32
  • @lex: Maybe I am misunderstanding the question. How do you expect to find to these small scripts (in order to analyze them), if not via some search tool? – blubb Sep 03 '11 at 14:34
  • @Mark yes, but that is the last resort, I don't want to be dependent on Jython. again, it seems overkill for just getting basic info. – Lex Berezhny Sep 03 '11 at 14:45
  • Someone appears to have asked the exact same question a year ago and there wasn't a solution given that I'm looking for, they also suggested using Jython. http://stackoverflow.com/questions/3120073/parsing-java-class-from-perl-or-python – Lex Berezhny Sep 03 '11 at 14:47
  • @Mark: I guess if nobody else provides a solution you should post your Jython suggestion as a solution and I will accept it as the correct answer since that seems like the most robust way to go if I am going to write it from scratch. – Lex Berezhny Sep 03 '11 at 15:00

1 Answers1

1

If your Python code does not make much use of C based libraries you could run the code in Jython which is Python run on the Java VM.

Otherwise you could write a small Java/jython executable that gets the information and writes it to stdout to be read by a CPython program calling it.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117