473,796 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8572
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.class file # 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.class file.ClassFile( s)

# Obtain the internal name of the class.

name = unicode(c.inter faces[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_n ame()) # eg. u'getTagName'
is_public = m.access_flags & javaclass.class file.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.class file # 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.class file.ClassFile( s)

# Obtain the internal name of the class.

name = unicode(c.inter faces[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_n ame()) # eg. u'getTagName'
is_public = m.access_flags & javaclass.class file.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
4273
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 as much as possible, so I'd like to call Xerces under the JAXP API. I'd like to validate the XML against a DTD, so that errors are flagged up to the user, and I can transcribe
4
7248
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 across is documentation for validating XML files against XSD files. Is ther any way to parse the XSD file itself? Any help will be appreciated. Thanks for your time.
2
3959
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 Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\ You selected the file named AAA.XML getXmlAlgorithmDocument(): IOException Not logged in
3
2615
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 as "gotchas") for doing this. I'm implementing a program that needs to read a standard configuration file, in key=value pairs for starters (though I'm open to other ideas). Basically it would be no more than about 20 lines total, one key per...
0
2871
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 first goal - parsing html files - I would be very grateful. Even if its a link to somewhere, or perhaps a book to read, that’s fine too. Many thanks, Firelli
3
4386
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 the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
3
11945
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 add to it for my next assignment. I dont want to go to my next assignment when I cannot even fix this error. The error and it is the only error I have thank goodness, says "reached end of file while parsing". Can anyone please take a look, thank you...
7
1977
by: Eric Wertman | last post by:
I have a set of files with this kind of content (it's dumped from WebSphere): ]
1
4409
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 Stack code and parsing code my professor i does not like me using buffer reader on my code and my professor did even give me an example code for parsing as well as pop push top or Stack code and i don't know how to do this code into parsing and pop push...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.