[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] pointcut on annotated methods
|
- From: "Bhaskar Maddala" <maddalab@xxxxxxxxx>
- Date: Wed, 26 Mar 2008 12:55:32 -0400
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=qW3gHDGUduKwg0/6WzDXkix4j79G+rJry3LMMXk0S3Q=; b=GmwVNI6ABFFOAy/VmhSGG9iGlq35JsaHwTyeAKHKZgLuk3+or9qiJp7LQjOcvyySJ2a/gWWa4VAyMUm1KVPkTYC01VGmQMOpARemDaQ7AwMRtSz0JymHxeH1+QtDw4AFzbC+BokEHLYNjhekrWrPTOGmzOw32eSxeLRBVd9CToM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=pd9/jIGCi87mHaNj3PeP78z5iehMftmiWvAHFmTD/1o919ftkGYtlxb1nKW4SBtZQatSPOlVkPlHDr3CyBWljClmAEJWLpEJnGZ1vBhGglEcX+UyGaYxOmZuNAGtRZREdhTOVbSGgNsB3xc77GduTdsxD8M/G13OxWKKstjDJxg=
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
>