Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut on annotated methods

Seems to work for me just fine...
----------------------------------------------------------------------------------------------------------
public class Main {
    public static void main(String[] args){
        WiredClz wc =  new WiredClz();
        wc.doWiredMethod("x", "y");
        wc.doWiredMethod2("y");
    }
}
----------------------------------------------------------------------------------------------------------

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface WiredMethod{
}

----------------------------------------------------------------------------------------------------------
public class WiredClz{
    @WiredMethod
    public void doWiredMethod(String x, String y){
        System.out.println("do Wired Method" + x + y);
    }

    @WiredMethod
    public void doWiredMethod2(String y){
        System.out.println("do Wired Method2" + y);
    }
}

----------------------------------------------------------------------------------------------------------
public aspect WiringAspect{
    pointcut WiringMethods(Object o) : execution (@WiredMethod * *(*))
&& args(o);
    void around(Object o) : WiringMethods(o){
        System.out.println("Before");
        proceed(o);
    }
}

----------------------------------------------------------------------------------------------------------

ajc.bat -1.5 -showWeaveInfo -classpath ..\lib\aspectjrt.jar Main.java
WiredClz.java WiredMethod.java WiringAspect.aj

Join point 'method-execution(void
WiredClz.doWiredMethod2(java.lang.String))' in Type 'WiredClz'
(WiredClz.java:8) advised by around advice from 'WiringAspect'
(WiringAspect.aj:4)

----------------------------------------------------------------------------------------------------------

java.exe -classpath ".;..\lib\aspectjrt.jar" Main

do Wired Methodxy
Before
do Wired Method2y

----------------------------------------------------------------------------------------------------------

On Wed, Mar 26, 2008 at 9:16 AM, joss <jonathan.clairembault@xxxxxxxxx> wrote:
> Hi all,
>
>  I am not used to annotation mechanisms. So I would like to know why my
>  annotated methods are not woven. here is my example :
>
>  -------------------------------------------------------------------
>  import java.lang.annotation.*;
>
>  @Retention(RetentionPolicy.RUNTIME)
>  @Target(ElementType.METHOD)
>  public @interface WritingMethod {}
>  --------------------------------------------------------------------
>  pointcut writingMethodCalled(Object o):
>         execution(@WritingMethod void *(*)) &&
>         args(o);
>
>  void around(Object o): writingMethodCalled(o) {
>         // this is not executed
>         proceed(o);
>     }
>  ----------------------------------------------------------------------
>  @WritingMethod
>     public void saveBean(Object obj) {
>         System.out.println("Saved object: " + obj);
>     }
>
>  Thanks in advance,
>  Jonathan Clairembault
>  _______________________________________________
>  aspectj-users mailing list
>  aspectj-users@xxxxxxxxxxx
>  https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top