Help with defining pointcut for method execution on interface hierarchy

View: New views
5 Messages — Rating Filter:   Alert me  

Help with defining pointcut for method execution on interface hierarchy

by Johan Haleby :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'd like to get some help to define a pointcut. I have an empty marker interface (A) from which several other interfaces extends e.g.

public interface B extends A {
      void myMethodInB();
}

Then I have an implementation of B (BImpl) which also extends other interfaces that doesn't extend from A such as X, Y, and Z, e.g.

public class BImpl implements B, X, Y, Z {
   public void myMethodInB() {
      ....
  }

   public void myMethodInX() {
      ....
  }
    ...
}

I want to define a pointcut that only intercepts methods declared in a subinterface of A. So for example the only method that should be intercepted in BImpl is the myMethodInB method since B extends A. The other methods such as myMethodInX should not be intercepted. Does anyone know how a pointcut like this would look like?

Thanks
/Johan



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

Re: Help with defining pointcut for method execution on interface hierarchy

by Andy Clement :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm afraid I can't come up with a pointcut for that.  Best I could do
is something like:

aspect X {
        public static boolean check(JoinPoint.StaticPart jpsp) {
                Object o = ((MethodSignature)jpsp.getSignature()).getDeclaringType();
                boolean b = // work out what you want...
                return b;
        }
        before(): execution(* A+.*(..)) && if(check(thisJoinPointStaticPart))  {
                System.out.println(thisJoinPoint);
        }

}

where you do your extra analysis in the check() method.  But this is
not a purely static match of course.

Andy

2009/9/10 Johan Haleby <johan.haleby@...>:

> Hi,
>
> I'd like to get some help to define a pointcut. I have an empty marker
> interface (A) from which several other interfaces extends e.g.
>
> public interface B extends A {
>       void myMethodInB();
> }
>
> Then I have an implementation of B (BImpl) which also extends other
> interfaces that doesn't extend from A such as X, Y, and Z, e.g.
>
> public class BImpl implements B, X, Y, Z {
>    public void myMethodInB() {
>       ....
>   }
>
>    public void myMethodInX() {
>       ....
>   }
>     ...
> }
>
> I want to define a pointcut that only intercepts methods declared in a
> subinterface of A. So for example the only method that should be intercepted
> in BImpl is the myMethodInB method since B extends A. The other methods such
> as myMethodInX should not be intercepted. Does anyone know how a pointcut
> like this would look like?
>
> Thanks
> /Johan
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: Help with defining pointcut for method execution on interface hierarchy

by Johan Haleby :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I solved it using a similar approach that you suggested but I was curious if you could construct it with a pointcut instead.  Thanks for your answer and for a great project!

/Johan

On Wed, Sep 16, 2009 at 11:25 PM, Andy Clement <andrew.clement@...> wrote:
I'm afraid I can't come up with a pointcut for that.  Best I could do
is something like:

aspect X {
       public static boolean check(JoinPoint.StaticPart jpsp) {
               Object o = ((MethodSignature)jpsp.getSignature()).getDeclaringType();
               boolean b = // work out what you want...
               return b;
       }
       before(): execution(* A+.*(..)) && if(check(thisJoinPointStaticPart))  {
               System.out.println(thisJoinPoint);
       }

}

where you do your extra analysis in the check() method.  But this is
not a purely static match of course.

Andy

2009/9/10 Johan Haleby <johan.haleby@...>:
> Hi,
>
> I'd like to get some help to define a pointcut. I have an empty marker
> interface (A) from which several other interfaces extends e.g.
>
> public interface B extends A {
>       void myMethodInB();
> }
>
> Then I have an implementation of B (BImpl) which also extends other
> interfaces that doesn't extend from A such as X, Y, and Z, e.g.
>
> public class BImpl implements B, X, Y, Z {
>    public void myMethodInB() {
>       ....
>   }
>
>    public void myMethodInX() {
>       ....
>   }
>     ...
> }
>
> I want to define a pointcut that only intercepts methods declared in a
> subinterface of A. So for example the only method that should be intercepted
> in BImpl is the myMethodInB method since B extends A. The other methods such
> as myMethodInX should not be intercepted. Does anyone know how a pointcut
> like this would look like?
>
> Thanks
> /Johan
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users


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

Re: Help with defining pointcut for method execution on interface hierarchy

by Víctor Llorens Vilella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm quite new in Aspects, but I had to build an aspect for a similar isue.

execution(public A.*(..) ) worked for me.

Methods are in B, but in fact their main interface is A.
What do you all think?

2009/9/17 Johan Haleby <johan.haleby@...>
Hi,

I solved it using a similar approach that you suggested but I was curious if you could construct it with a pointcut instead.  Thanks for your answer and for a great project!

/Johan


On Wed, Sep 16, 2009 at 11:25 PM, Andy Clement <andrew.clement@...> wrote:
I'm afraid I can't come up with a pointcut for that.  Best I could do
is something like:

aspect X {
       public static boolean check(JoinPoint.StaticPart jpsp) {
               Object o = ((MethodSignature)jpsp.getSignature()).getDeclaringType();
               boolean b = // work out what you want...
               return b;
       }
       before(): execution(* A+.*(..)) && if(check(thisJoinPointStaticPart))  {
               System.out.println(thisJoinPoint);
       }

}

where you do your extra analysis in the check() method.  But this is
not a purely static match of course.

Andy

2009/9/10 Johan Haleby <johan.haleby@...>:
> Hi,
>
> I'd like to get some help to define a pointcut. I have an empty marker
> interface (A) from which several other interfaces extends e.g.
>
> public interface B extends A {
>       void myMethodInB();
> }
>
> Then I have an implementation of B (BImpl) which also extends other
> interfaces that doesn't extend from A such as X, Y, and Z, e.g.
>
> public class BImpl implements B, X, Y, Z {
>    public void myMethodInB() {
>       ....
>   }
>
>    public void myMethodInX() {
>       ....
>   }
>     ...
> }
>
> I want to define a pointcut that only intercepts methods declared in a
> subinterface of A. So for example the only method that should be intercepted
> in BImpl is the myMethodInB method since B extends A. The other methods such
> as myMethodInX should not be intercepted. Does anyone know how a pointcut
> like this would look like?
>
> Thanks
> /Johan
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users


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




--
Victor Llorens Vilella


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

Re: Help with defining pointcut for method execution on interface hierarchy

by Andy Clement :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Victor,

I think the difference in Johans case is that A does not define the
method, it is just a marker interface, and the sub-interfaces actually
define the methods.

If A defined the method, then your pointcut would work.

Andy

2009/9/17 Víctor Llorens Vilella <victor.llorens@...>:

> I'm quite new in Aspects, but I had to build an aspect for a similar isue.
>
> execution(public A.*(..) ) worked for me.
>
> Methods are in B, but in fact their main interface is A.
> What do you all think?
>
> 2009/9/17 Johan Haleby <johan.haleby@...>
>>
>> Hi,
>>
>> I solved it using a similar approach that you suggested but I was curious
>> if you could construct it with a pointcut instead.  Thanks for your answer
>> and for a great project!
>>
>> /Johan
>>
>> On Wed, Sep 16, 2009 at 11:25 PM, Andy Clement <andrew.clement@...>
>> wrote:
>>>
>>> I'm afraid I can't come up with a pointcut for that.  Best I could do
>>> is something like:
>>>
>>> aspect X {
>>>        public static boolean check(JoinPoint.StaticPart jpsp) {
>>>                Object o =
>>> ((MethodSignature)jpsp.getSignature()).getDeclaringType();
>>>                boolean b = // work out what you want...
>>>                return b;
>>>        }
>>>        before(): execution(* A+.*(..)) &&
>>> if(check(thisJoinPointStaticPart))  {
>>>                System.out.println(thisJoinPoint);
>>>        }
>>>
>>> }
>>>
>>> where you do your extra analysis in the check() method.  But this is
>>> not a purely static match of course.
>>>
>>> Andy
>>>
>>> 2009/9/10 Johan Haleby <johan.haleby@...>:
>>> > Hi,
>>> >
>>> > I'd like to get some help to define a pointcut. I have an empty marker
>>> > interface (A) from which several other interfaces extends e.g.
>>> >
>>> > public interface B extends A {
>>> >       void myMethodInB();
>>> > }
>>> >
>>> > Then I have an implementation of B (BImpl) which also extends other
>>> > interfaces that doesn't extend from A such as X, Y, and Z, e.g.
>>> >
>>> > public class BImpl implements B, X, Y, Z {
>>> >    public void myMethodInB() {
>>> >       ....
>>> >   }
>>> >
>>> >    public void myMethodInX() {
>>> >       ....
>>> >   }
>>> >     ...
>>> > }
>>> >
>>> > I want to define a pointcut that only intercepts methods declared in a
>>> > subinterface of A. So for example the only method that should be
>>> > intercepted
>>> > in BImpl is the myMethodInB method since B extends A. The other methods
>>> > such
>>> > as myMethodInX should not be intercepted. Does anyone know how a
>>> > pointcut
>>> > like this would look like?
>>> >
>>> > Thanks
>>> > /Johan
>>> >
>>> >
>>> >
>>> > _______________________________________________
>>> > aspectj-users mailing list
>>> > aspectj-users@...
>>> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>> >
>>> >
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@...
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@...
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>
>
>
> --
> Victor Llorens Vilella
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users