3 Replies Latest reply on Jul 10, 2003 6:55 AM by bialek

    method.setBody with $$ parameters

    bialek

      With the CtNewMethod.copy, we can create a copy of a method.
      Is there a way to overwrite the method's body ?(not just insertBefore/after)
      I need a body like:
      {
      x = object1.$proceed($$);
      y=something_after(x)
      return y;
      }
      object1 has the same interface as the class being called and I need to create such body for every method.

      Thanks
      ++Robert

        • 1. Re: method.setBody with $$ parameters
          chiba

          I think you should use insertAfter() in this particular
          case. But if you want, you can also use setBody().
          However, $proceed does not work in the new body
          since setBody() overwrites the original body. To
          avoid this, you must first rename the original method
          and create a new one without $proceed.

          • 2. Re: method.setBody with $$ parameters
            bialek

            Thanks for the hint :)
            The problem is just how to access the parameters passed to the method after I have renamed it?
            Can I use $$ parameter for the renamed method ?

            ++Robert

            • 3. Re: method.setBody with $$ parameters
              bialek

              YES, the $$ parameter works great!
              There were only problems with $proceed.
              It is possible to create new methods in the following way:
              { return "+methodName+"($$); }

              ++Robert