[jboss-user] [Javassist user questions] - try finally around a method

sanjayvacharya do-not-reply at jboss.com
Sun Sep 14 00:59:25 EDT 2008


Hi,

Is there a way to add try/finally around a method using java assist? I do not want to create a whole new method and delegate to it but simply alter the existing method. I could not find a way of accomplishing the same without having to create a foo$impl() or equivalent and delegating to the same. 

Also, is there a way to obtain the string code in an existing method's body via CtMethod? I mean the actual method body code.

The following is what I am trying to accomplish:


  | public void foo() {
  |    System.out.println("Foo");
  | }
  | 

to be changed to:


  | public void foo() {
  |   try {
  |      System.out.println("Entering foo");
  |      System.out.println("Foo");
  |   } finally {
  |      System.out.println("Exited foo");
  |   }
  | }
  | 

Thanks in advance.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4176351#4176351

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4176351



More information about the jboss-user mailing list