Loading ...
Sorry, an error occurred while loading the content.

code that takes in a Java file and outputs the names of the classes and methods?

Expand Messages
  • jw9315
    hi, I was wondering if anyone out there had code which takes in a .java file, and outputs the class names within that file, and the method names and their
    Message 1 of 4 , May 3, 2003
    • 0 Attachment
      hi,
      I was wondering if anyone out there had code which takes in a .java
      file, and outputs the class names within that file, and the method
      names and their arguments?

      If not, can anybody give me advice on how to approach this problem?
      Thanks,
      Jon
    • iank@bearcave.com
      I ve written a .class file disassembler which will output class and method information. This can be found at
      Message 2 of 4 , May 3, 2003
      • 0 Attachment
        I've written a .class file disassembler which will output class and
        method information. This can be found at
        http://www.bearcave.com/software/java/javad/index.html. If you want
        to go from source, you might start with the ANTLR Java parser. You
        can build abstract syntax trees for the Java class information and
        then output this.

        Ian
      • jw9315
        ... and ... want ... You ... Hi, Thanks for that info. I have the Abstract Syntax Tree in memory and was wondering what the easiest way to extract the class
        Message 3 of 4 , May 3, 2003
        • 0 Attachment
          --- In antlr-interest@yahoogroups.com, iank@b... wrote:
          >
          > I've written a .class file disassembler which will output class
          and
          > method information. This can be found at
          > http://www.bearcave.com/software/java/javad/index.html. If you
          want
          > to go from source, you might start with the ANTLR Java parser.
          You
          > can build abstract syntax trees for the Java class information and
          > then output this.
          >
          > Ian
          Hi,
          Thanks for that info. I have the Abstract Syntax Tree in memory and
          was wondering what the easiest way to extract the class and method
          information from this? Would it just be a case of calling getChild()
          and getNextSibling() recursively, and looking for class and method
          names? Alternatively, could I look though the string representation
          of the tree for all the class and method types?

          Is there a set algorithm for going through all the nodes in an AST,
          as I'm having trouble getting my head round it! I don't think I have
          time to implement a tree parser, so I have to use getFirstChild() and
          getNextSibling() when walking the tree...
          Any help would be greatly appreciated, (dissertation handin is very
          near!)
          Jon
        • iank@bearcave.com
          It should be possible to only build abstract syntax tree productions for the syntax you are interested in. For example, the class name and methods. When the
          Message 4 of 4 , May 3, 2003
          • 0 Attachment
            It should be possible to only build abstract syntax tree productions
            for the syntax you are interested in. For example, the class name
            and methods. When the production for the class finishes, you can
            then output output the class skeleton.

            In building the syntax tree, I'd just build my own, rather than
            spending the time to learn the ANTLR tree construction rules. But I
            have some known biases here.

            Ian
          Your message has been successfully submitted and would be delivered to recipients shortly.