summaryrefslogtreecommitdiffstats
path: root/tests/java5/annotations/ajdkExamples/DeclaresWithAnnotations.aj
blob: 029ebafa1e37e34cbb7cc022754a30c7b8fcb46f (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
import org.xyz.model.Model;

public aspect DeclaresWithAnnotations {
	
	declare warning : withincode(@PerformanceCritical * *(..)) &&
      call(@ExpensiveOperation * *(..))
      : "Expensive operation called from within performance critical section";
	
	declare error : call(* org.xyz.model.*.*(..)) &&
       !@within(Trusted)
       : "Untrusted code should not call the model classes directly";
	
}

@interface PerformanceCritical {}

@interface ExpensiveOperation {}

@interface Trusted {}


class Foo {
	
	@PerformanceCritical Foo getFoo() {
		Model m = new Model();  
		m.foo();              // DE
		Foo foo = makeFoo();  // DW
		return foo;
	}
	
	Foo getFoo2() {
		Foo foo = makeFoo();
		return foo;
	}
	
	@ExpensiveOperation Foo makeFoo() {
		return new Foo();
	}
}

@Trusted class Goo {
	
	public void goo() {
		Model m = new Model();
		m.foo();
	}
	
}