invariant:ex2
This is an old revision of the document!
Invariants: Mandate setters
Task: Signal a warning for assignments to private fields outside of setter methods.
One common coding convention is that no private field should be assigned to outside of setter methods. Write an aspect to signal a warning at compile time for these illegal assignment expressions.
Follow the template given below, where the pointcut picks out join points of private field sets outside of setter methods. “Outside”, here, means that the code for the assignment is outside the text of the setter.
aspect Answer2 { declare warning: <pointcut>: "Bad field set"; }
Tools:
set
and withincode
primitive pointcuts and the void set*(..)
signature pattern.
invariant/ex2.1172422093.txt.gz · Last modified: 2007/02/25 17:48 by bdefrain