[aosd-discuss] code policy enforcement and AspectJ

Ronald Bodkin rbodkin at pacbell.net
Thu Feb 19 22:53:36 EST 2004


Eric is right... there is no way to say this in AspectJ today.
 
This sounds like another possible use case for pertype aspects (see the aspectj-users archive for more information on this proposed language extension). It would be nice if the specification for them allowed creating declare warning or error to bind to a single type throughout operate on a single type like in this example. I would also like to see generics in AspectJ allow one to define parameterized pointcuts, which would also enable this kind of expression.
 
You might post to aspectj-users to lobby for a version of pertype aspects that supports this to be included in aspectj 1.2 (along with a description of why you want it),

Eric Bodden <eric at bodden.de> wrote:
> The aspect should be generic, so
> !withincode(someSpesificClass.new(..)); doesn't help me.

No that's not possible IMHO, I think the best you can do is something like:

public aspect PolicyEnforcementForSetters {
declare warning : set(* SomeClass.*) && !withincode(*
SomeClass.set*(..)) && !withincode(* SomeClass.new(..))
: "set only allowed from set* methods and constructors";
}

Your Problem is that you would need something like a Class variable. *
matches every classname. What you want is that "SomeClass" can be any class
but always the same over the whole pointcut, so something like:

set(* .*) && !withincode(* .set*(..)) && !withincode(*
.new(..))
for every possible 

At the moment I think this impossible. Interesting problem however.

On the other hand I don't quite see why such a policy would be useful.
Somebody can (and should) just declare the attribute "private" if it should
not be set from the outside. The rest is then easy to formulate in AspectJ
(using "*" for ).

Eric

-- 
Eric Bodden
RWTH Aachen University
ICQ UIN: 12656220
Website: http://www.bodden.de
PGP key: http://www.bodden.de/pub_key.asc




__________________________________________________
AOSD Discuss mailing list - discuss at aosd.net
To unsubscribe go to http://aosd.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://server2.hostvalu.com/pipermail/discuss_aosd.net/attachments/20040219/c081ea89/attachment.htm


More information about the discuss mailing list