0

I'm writing a Java program for an assignment that starts by taking 2 user input:

  1. the name of a compiled java class file
  2. the name of a method

Then, the program will parse the java class, search for the method that the user enters, and search the method for other methods called by that method, and the methods called by those methods.

Then, from those data, the program should output the method call trees as such

  • classA.method1(parameters)
    • classA.method2(parameters)
      • classA.method3(parameters)
    • classB.method1(parameters)

Can anyone tell me what should I use or learn in order to perform these operations?

ShienXIII
  • 141
  • 1
  • 1
  • 9
  • I would take an existing library to parse Java source code like [JavaParser](http://code.google.com/p/javaparser/). A choice of a library depends on what you're going to do with that code then – user3159253 May 03 '14 at 13:11
  • Problem is I'm only allowed to use standard Java library – ShienXIII May 03 '14 at 13:28
  • Sounds like you've described it pretty well. Parsing the Java .class file is not terribly difficult -- I once wrote a basic parser in a few hours. You will, of course, need to study the [Java Virtual Machine Specification](http://docs.oracle.com/javase/specs/jvms/se7/jvms7.pdf) in order to understand the .class format. – Hot Licks May 03 '14 at 14:09
  • (Basically you break apart the .class into the constant pool, methods, and other extraneous stuff. Walk through each method to find all the calls. Look up the corresponding call targets in the constant pool, and add calling-method/called-method to a table or database that you would then build the call tree from.) – Hot Licks May 03 '14 at 14:16

0 Answers0