parsing java files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stéphane bard

    #1

    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)?
  • Paul Boddie

    #2
    Re: parsing java files

    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

    Comment

    • Gabriel Genellina

      #3
      Re: parsing java files

      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!


      Comment

      • stéphane bard

        #4
        Re: parsing java files

        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
        >

        Comment

        Working...