473,378 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

parsing java files

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
3 8490
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
4
by: Pushya | last post by:
Hello - I am trying to parse a .XSD file to obtain information about element name and type in the file. I have been trying to find some kind of documentation for Schema Parsing. All I come...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
3
by: John Doe | last post by:
I've been doing some reading/research on parsing simple configuration files through C, and have heard various opinions on the matter. I'd like to solicit some opinions and design criteria (as well...
0
by: firelli | last post by:
Hi, I would like to be able to read (parse) an html file into my Java program. Once I'm able to do this, I need to be able to analyse the html code. If you could offer any help in meeting for...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
3
by: spittinfire | last post by:
-------------------------------------------------------------------------------- I am trying to correct the errors on an assignment that has already been graded because I have to now modify it and...
7
by: Eric Wertman | last post by:
I have a set of files with this kind of content (it's dumped from WebSphere): ]
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.