[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Is there a common syntax for a compile time "if" pointcut?
|
Hi Scott,
You might be interested in our SCoPE compiler, which we coincidentally
just have released. It directly supports what you want to do---"if"
pointcut can be used with declare warning/error when the conditions
are static.
The attached code can be compiled by using SCoPE, which generates the
following error:
|StaticIf.aj:40: You are not permitted to do XYZ
| System.out.println("Hello!");
| ^--------^
|
|1 error.
|Compiler failed.
(Due to current implementation restrictions, we have to write just one
named pointcut with declare warning/error, and to define an empty
advice. We will address those restrictions in the future releases.)
Further information is available at:
http://www.graco.c.u-tokyo.ac.jp/ppp/projects/scope/
Best regards,
Hidehiko Masuhara
--
Dept. of Graphics and Computer Science | 3-8-1 Komaba, Meguro-ku,
Graduate School of Arts and Sciences | Tokyo, Japan 153-8902
University of Tokyo | Phone: +81-3-5454-6679
E-mail: masuhara@xxxxxxx | Fax: +81-3-5454-6990
From: Scott Hayward <shayward@xxxxxxxxxx>
Subject: [aspectj-users] Is there a common syntax for a compile time "if" pointcut?
Date: Wed, 1 Jun 2005 09:45:01 -0700
> Hi,
>
> I'm trying to write an aspect that will declare either a warning or error,
> depending on the value of some constant. However, the "if" pointcut
> designator cannot be used with declare warning/error because it evaluates
> at run time. I need something at compile time.
>
> What I want is to be able to configure an aspect that will declare a
> warning, error or ignore some condition like calls to System.out.
>
> First, I define a set of constants in a class:
>
> /** This constant defines whether a static aspect should generate an
> error */
> public static final String CFG_ERROR = "ERROR";
> /** This constant defines whether a static aspect should generate a
> warning */
> public static final String CFG_WARN = "WARNING";
> /** This constant defines whether a static aspect should be ignored
> */
> public static final String CFG_IGNORE = "IGNORE";
>
> /** This constant configures whether to generate an error, warning or
> ignore */
> public static final String CFG_STATIC_TEST_XYZ = CFG_ERROR;
>
> Now I want to write aspects like this:
>
> /** This pointcut determines if the static test condition is found */
> public pointcut staticTestXYZ() : <<some pointcut, like writing to
> System.out>> ;
>
> /** Declare an warning if configured to do so */
> declare warning : staticTestXYZ() &&
> <<need compile time test for CFG_STATIC_TEST_XYZ=CFG_WARN>> :
> "I'm warning you not to do XYZ";
>
> /** Declare an error if configured to do so */
> declare error : staticTestXYZ() &&
> <<need compile time test for CFG_STATIC_TEST_XYZ=CFG_ERROR>> :
> "You are not permitted to do XYZ";
>
>
> Is there a standard syntax for doing things like this?
>
>
> Thanks,
>
> Scott.
> _______________________________________________________
> Scott Hayward
> Advisory IT Specialist
> IBM Canada Ltd., Pacific Development Centre
> 4611 Canada Way, Burnaby, BC, V5G 4X3 CANADA
> Dir (604) 297-3096 Fax (604) 297-3030 4 / PA1 / 4611 / BURN
> email: shayward@xxxxxxxxxx Web: http://www.can.ibm.com/pdc
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
aspect StaticIf {
/** This constant defines whether a static aspect should generate an
error */
public static final String CFG_ERROR = "ERROR";
/** This constant defines whether a static aspect should generate a
warning */
public static final String CFG_WARN = "WARNING";
/** This constant defines whether a static aspect should be ignored */
public static final String CFG_IGNORE = "IGNORE";
/** This constant configures whether to generate an error, warning or
ignore */
public static final String CFG_STATIC_TEST_XYZ = CFG_ERROR;
/** This pointcut determines if the static test condition is found */
public pointcut staticTestXYZ() : get(* System.out) && within(C);
pointcut reportStaticError() :
staticTestXYZ() && if(CFG_STATIC_TEST_XYZ == CFG_ERROR);
pointcut reportStaticWarning() :
staticTestXYZ() && if(CFG_STATIC_TEST_XYZ == CFG_WARN);
/* Those advice declarations needed due to current implementation
restrictions */
before() : reportStaticError() {}
before() : reportStaticWarning() {}
/** Declare an warning if configured to do so */
declare warning : reportStaticWarning() :
"I'm warning you not to do XYZ";
/** Declare an error if configured to do so */
declare error : reportStaticError() :
"You are not permitted to do XYZ";
}
class C {
public static void main(String[] args) {
System.out.println("Hello!");
}
}