Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] code policy enforcement and AspectJ

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

_________________________________________________________________
MSN Messenger http://www.msn.no/messenger Den korteste veien mellom deg og dine venner



Back to the top