Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] can you say that AspectJ types are Java types?

Hi,

I use eclipse 3.2 and AJDT 1.4.0.

I have some doubts about aspectj and any help would be appreciated.

1. I can not capture classA calls to itself or to classB with pointcut "publicCallsAndCallers" . I want to capture each call to any public method and the       object where the call is made.

2. Whenever I try to define a pointcut with the negation of another pointcut, I can not do it when it has parameters (example: pointcut             "publicButSayCallsAndCallers") due to "negation doesn't allow binding" error, thus limiting its reuse, however, I can do it
   if the pointcut is rewriten without parameters (example: pointcut "publicButSayCalls").



I also have some suggestions for AJDT:

1. For debug purposes, I think it would be nice to be able to select the advices that we do not want to be executed.

2. When we select an advice we can see the joinpoints advised by it. It would also be nice to see the joinpoints captured by a selected pointcut.



All the questions above are based at the following code:

public aspect Doubts {

    // captures each call to any public method and the object where the call is made
    pointcut publicCallsAndCallers(Object caller): call(public * *.*.*(..)) && this(caller) && !within(Doubts);
   
    before(Object caller):publicCallsAndCallers(caller){
       
        System.out.println("joinpoint: " + thisJoinPoint.toString());
        System.out.println("caller: " + caller.toString ());
       
    }   

    // captures each call to all public methods started by the word "say" and the object where the call is made
    pointcut publicSayCallsAndCallers(Object caller):call(public * *.*.*say*(..)) && this(caller) && !within(Doubts);
   
    before(Object caller): publicSayCallsAndCallers(caller){
       
        System.out.println("call to *say* method. joinpoint: " + thisJoinPoint.toString());
        System.out.println("caller: " + caller.toString());
    }
   
    // captures each call to all public methods but those started by the word "say" and the object where the call is made
    pointcut publicButSayCallsAndCallers(Object caller1, Object caller2):call(public * *.*.*(..)) && !publicSayCallsAndCallers(caller2) && this(caller1) && !within(Doubts);
   
    before(): publicButSayCallsAndCallers(Object caller1, Object caller2){
       
        System.out.println("call to not *say* method. joinpoint: " + thisJoinPoint.toString());
        System.out.println ("caller: " + caller1.toString());
       
    }   
   
    // captures each call to all public methods started by the word "say"
    pointcut publicSayCalls():call(public * *.*.*say*(..)) && !within(Doubts);
   
    before(): publicSayCalls(){
       
        System.out.println("call to *say* method. joinpoint: " + thisJoinPoint.toString());
       
    }
   
    // captures each call to all public methods but those started by the word "say"
    pointcut publicButSayCalls():call(public * *.*.*(..)) && !publicSayCalls() && !within(Doubts);
   
    before(): publicButSayCalls(){
       
        System.out.println("call to not *say* method. joinpoint: " + thisJoinPoint.toString());
       
    }
}

public class classA {
      
    public static void main(String[] args) {
      
        doSomething();
        doNothing();
      
    }
  
    public static void doSomething(){

        classB b = new classB();
        b.start();
      
        classB b2 = new classB();
        b2.start();
      
    }
  
    public static void doNothing(){}
  
}

public class classB {

    public void start(){
      
        sayHello();
        sayGoodbye();
      
    }
  
    public void sayHello(){
      
        printString("Hello World!");
        classC c = new classC();
        c.sayHello();
      
    }
  
    public void sayGoodbye(){
      
        printString("Bye World!");
      
    }
  
    private void printString(String s){
      
        System.out.println(s);
      
    }
  
}

public class classC {

    public void sayHello(){
      
        printString("Hello C World!");
  
    }
  
    private void printString(String s){
      
        System.out.println(s);
      
    }
  
}




Thanks in advance.
--
Sérgio Bryton


Back to the top