By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

parsing java files

P: n/a
hello
i would like to parse java files an detect
class name's, attributes name's type's and visibility (and or list of
methods).

is there any module who can parse easily a java file without using
(jython)?
Sep 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
stéphane bard wrote:
hello
i would like to parse java files an detect
class name's, attributes name's type's and visibility (and or list of
methods).

is there any module who can parse easily a java file without using
(jython)?
There are probably a number of standard parser solutions which can
expose such information. However, another solution is that provided by
the javaclass package:

import javaclass.classfile # http://www.python.org/pypi/javaclass

# Read the contents of the compiled class.

f = open("org/w3c/dom/Element.class", "rb")
s = f.read()
f.close()

# Process the class data.

c = javaclass.classfile.ClassFile(s)

# Obtain the internal name of the class.

name = unicode(c.interfaces[0].get_name()) # u'org/w3c/dom/Node'
for m in c.methods:

# Obtain each method name and access details.

method_name = unicode(m.get_name()) # eg. u'getTagName'
is_public = m.access_flags & javaclass.classfile.PUBLIC

Obviously, this is more convoluted than it needs to be, but the
original purpose of the module employed is to assist in translating
Java class data to other forms - notably Python bytecode - although
such experiments haven't been continued by myself for quite some time.
The class decoding part illustrated above should be quite usable,
however.

Paul

Sep 21 '06 #2

P: n/a
At Thursday 21/9/2006 17:51, stéphane bard wrote:
>i would like to parse java files an detect
class name's, attributes name's type's and visibility (and or list of
methods).

is there any module who can parse easily a java file without using
(jython)?
I would get the needed info using javadoc (in
Java) and then process the output in Python.

Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Sep 21 '06 #3

P: n/a
i use javaclass and it's great !!
this is what i need. thank's paul

gabriel thank's too for advice
Paul Boddie a écrit :
stéphane bard wrote:
>hello
i would like to parse java files an detect
class name's, attributes name's type's and visibility (and or list of
methods).

is there any module who can parse easily a java file without using
(jython)?

There are probably a number of standard parser solutions which can
expose such information. However, another solution is that provided by
the javaclass package:

import javaclass.classfile # http://www.python.org/pypi/javaclass

# Read the contents of the compiled class.

f = open("org/w3c/dom/Element.class", "rb")
s = f.read()
f.close()

# Process the class data.

c = javaclass.classfile.ClassFile(s)

# Obtain the internal name of the class.

name = unicode(c.interfaces[0].get_name()) # u'org/w3c/dom/Node'
for m in c.methods:

# Obtain each method name and access details.

method_name = unicode(m.get_name()) # eg. u'getTagName'
is_public = m.access_flags & javaclass.classfile.PUBLIC

Obviously, this is more convoluted than it needs to be, but the
original purpose of the module employed is to assist in translating
Java class data to other forms - notably Python bytecode - although
such experiments haven't been continued by myself for quite some time.
The class decoding part illustrated above should be quite usable,
however.

Paul
Sep 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.