Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Tracing method using AspectJ

You will have to use an "after returning" advice, collect the return value, and check it inside the advice:

        after() returning(boolean retValue) : execution(boolean HelloWorld.*(..)) {
            if(retValue) {
                System.err.println(thisJoinPoint);
            }
        }

-Ramnivas
===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com
M: (408)203-4621


samuel cheung wrote:
Thank Matthew,

But in this aspect how does it make sure it only print when the return
value is ture? I dont' see any part of the aspect check that?


1. Yes
public class HelloWorld {

        public boolean println () {
                System.out.println("Hello World!");
                return true;
        }

        public static void main(String[] args) {
                new HelloWorld().println();
        }

}

aspect Tracing1 {
        before () : execution(boolean HelloWorld.*(..)) {
                System.err.println(thisJoinPoint);
        }
}

2. I have another question, let's say I have a class with a function
with list argument,
like this:

class AClass {
  private void aFun(List list){
   // any implementation
  }
}

is it possible to trace when aFun() actually add something to the list
(i.e. inside aFun it calls list.add()) ?

Thank you.



On 11/9/05, Matthew Webster <matthew_webster@xxxxxxxxxx> wrote:
  
Samuel,

1. Yes
public class HelloWorld {

        public boolean println () {
                System.out.println("Hello World!");
                return true;
        }

        public static void main(String[] args) {
                new HelloWorld().println();
        }

}

aspect Tracing1 {
        before () : execution(boolean HelloWorld.*(..)) {
                System.err.println(thisJoinPoint);
        }
}

2. Yes
aspect Tracing2 {
        before () : call(boolean *(..)) && withincode(public void main(..))
{
                System.err.println(thisJoinPoint);
        }
}

3. No, unless you want to use new Java 5 language features like annotations.

Cheers

Matthew Webster
 AOSD Project
 Java Technology Centre, MP146
 IBM Hursley Park, Winchester,  SO21 2JN, England
 Telephone: +44 196 2816139 (external) 246139 (internal)
 Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:        aspectj-users-bounces@xxxxxxxxxxx

To:        aspectj-users@xxxxxxxxxxx
cc:
Subject:        [aspectj-users] Tracing method using AspectJ


Hi,

 I am new to AspectJ, I have a few questions. I appreciate if anyone
 can help with me that:
 1. I read the tracing example,
http://eclipse.org/aspectj/doc/released/progguide/examples-development.html#d0e2490

 I would like to know if I can setup so that I only trace method
 depends on the Return value of the method that I am trying to trace.
 And if I can get the value of the input parameters?

 2. Is it possible to trace a method depends on the CALLER of that method?

 3. Do I need to use Java5 for AspectJ?

 Thank you.
 _______________________________________________
 aspectj-users mailing list
 aspectj-users@xxxxxxxxxxx
 https://dev.eclipse.org/mailman/listinfo/aspectj-users








_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



    
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

  

Back to the top