blob: 3d6a574228ad56012cde18b5810e1143daddfdf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
public aspect MarkMyMethodsAspect {
/* All methods not marked with @Read nor @Write are marked with @Write
*
* When @MarkMyMethods is present on a Type, all public methods of
* that type must either be marked with @Read or @Write. If neither of
* @Read or @Write is present on such a method, the method is automatically
* annotated with the default marker, i.e. @Write
*
* *******************************************************
* BUG
* internal null pointer exception with the first part
* of the declare statement.
* *******************************************************
*
*/
declare @method : !@(Write || Read) public !static * (@MarkMyMethods *).*(..) : @Write;
// This one works
//declare @method : !@(Read) public !static * (@MarkMyMethods *).*(..) : @Write;
// This one too
//declare @method : !@(Write) public !static * (@MarkMyMethods *).*(..) : @Write;
/* Cannot have @Read or @Write methods without @MarkMyMethods
*
* When @Read or @Write is present on a method, the enclosing type must
* have the @AccessClassified annotation.
*/
declare error : execution(@Read public * !@MarkMyMethods *.*(..)) :
"Cannot have public @Read methods inside non @AccessClassified types.";
declare error : execution(@Write public * !@MarkMyMethods *.*(..)) :
"Cannot have public @Write methods inside non @AccessClassified types.";
/* Cannot have a method marked with both @Read and @Write
*
* What would be necessary is to have an annotation that can take
* a parameter to identify which type of access is needed that would prevent
* the user from having the 2 at the same time e.g. @Access(READ). Unfortunately,
* AspectJ 1.5 can currently only work with marker annotations and ignores
* parameter annotations.
*/
declare error : readMethod() && writeMethod() :
"Cannot have both @Read and @Write on the same method.";
/*
* public @Read methods inside @MarkMyMethods types
*/
public pointcut readMethod() :
execution(@Read public !static * @MarkMyMethods *.*(..));
/*
* public @Write methods inside @MarkMyMethods types
*/
public pointcut writeMethod() :
execution(@Write public !static * @MarkMyMethods *.*(..));
}
|