Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] perthis instantiation model aspects

Hello,

 

I refactored an aspect using perthis instantiation type and faced a behaviour

I did not expected and I can not find a reason for. Could somebody show me the problem, please?

 

Take this simple interface:

 

public  interface A {

 

            public  void a();

}

 

And this class:

 

public class B implements A {

           

            public void a() {

                        System.out.println("in B");

            }

           

public static void main(String[] args) {

                        new B().a();

            }

}

 

Having this aspect:

public aspect TestAspect perthis(test(A)){

 

            // this does match at runtime with runtime test

            //pointcut test(A a): execution(public void A+.a()) && this(a);

           

            // this does not match at runtime with runtime test

            pointcut test(A a): execution(public void A.a()) && this(a);

           

            void around(A a): test(a) {

                        System.err.println(thisJoinPoint);

                        proceed(a);

            }

}

 

public aspect ExecutionAspect {

           

            // this does match

            //pointcut test(A a): execution(public void A+.a()) && this(a);

           

// this also does match

            pointcut test(A a): execution(public void A.a()) && this(a);

           

            void around(A a): test(a) {

                        System.err.println(thisJoinPoint);

                        proceed(a);

            }

}

 

I know I could simply drop the declaring type in the pointcut declaration.

But I “feel” the second pointcut declaration in the aspect using perthis instantiation model
should also work. Why is that not the case?

 

Thank you very much,

Vincenz


Back to the top