1 Reply Latest reply on Jul 6, 2004 11:56 AM by Shigeru Chiba

    Urgent, please give me a hand ???

    Eric Chow Apprentice

      Hi,

      I am going to use Javassist to do some education project.
      But I have so many problems and questions if I should use Javassist or other library.


      1. retrieve all the variable names and its corresponding values (global variables, and local variables) ?

      2. can I insert a statement into a specific line within a method?
      for example,

      public void init() {
      int a = 10;
      // <<<<<<< insert a statement here : a = a * a;
      System.out.println(a);
      }

      3. can I modify a specific statement ?
      for example,

      public void init(int x) {
      return x; //<<<<<<< modify it to: return (x * 2);
      }


      Would you please to show me some example about the above questions ???
      Please give me a hand !!! It's very urgent for me...
      Thanks a lot.


      Best regadrs,
      Eric

        • 1. Re: Urgent, please give me a hand ???
          Shigeru Chiba Expert

          Basically, if you have detailed knowledge of Java bytecode/class file,
          you can do all the three things with the lower-level API of Javassist.
          If you want to use only higher-level API, then

          > 1. retrieve all the variable names and its corresponding values
          > (global variables, and local variables) ?

          You can obtain not local variable names but all the fields.

          > 2. can I insert a statement into a specific line within a method?

          Yes.

          > 3. can I modify a specific statement ?

          The answer depends on the kind of statement.
          You can modify method calls, field accesses, etc but not all the kinds.