[aosd-discuss] code policy enforcement and AspectJ

leifo Lauvsnes leifo at hotmail.com
Thu Feb 19 08:52:30 EST 2004


I'm trying to write an aspect that helps me enforce that member values 
should only be changed from methods named set*, and from the constructor(s), 
in the same class that the member variable belongs to. Is it possible to do 
this at compile time? The problem is to deny(flag warning) 
constructors/methods in other classes from assigning variables. The aspect 
should be generic, so !withincode(someSpesificClass.new(..)); doesn't help 
me.

Hopefully you understand my question, and have some ideas

aspect that try to explain my idea but doesn't work (doesn't compile):

{
pointcut notSelfCall(Object caller, Object callee) :
set (* *.* && ) !withincode(*.new(..))
this(caller) && target(callee) && caller != callee;
pointcut directMemberAssignment() :
set (* *.*) && !withincode(* set*(..)) &&
!withincode(*.new(..));
declare warning : directMemberAssignment() &&
notSelfCall(caller, callee) :
"Use a setter method for assignment. Constructors in other class can't 
assign values";
}
-Leifo
Sorry about that previous rich text

_________________________________________________________________
MSN Hotmail  http://www.hotmail.com Med markedets beste SPAM-filter. Gratis!




More information about the discuss mailing list