summaryrefslogtreecommitdiffstats
path: root/tests/java5/annotations/ajdkExamples/DecpAnnotations.aj
blob: d3cd3fd42e4b0fdc791e8416aa6ec8bbce073ba4 (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
public aspect DecpAnnotations {
	
	public String SecuredObject.getSecurityCredentials() {
		return "none";
	}
	
	declare parents : (@Secured *) implements SecuredObject;
	
	declare parents : (@Secured BankAccount+) implements SecuredObject;
	
	public static void main(String[] args) {
		Foo foo = new Foo();
		Goo goo = new Goo();
		BankAccount acc = new BankAccount();
		PrivateBankAccount pacc = new PrivateBankAccount();
		BusinessBankAccount bacc = new BusinessBankAccount();
		
		System.out.println("Test Foo is not secured: " + 
				((foo instanceof SecuredObject) ? "FAIL" : "PASS")
			);
		System.out.println("Test Goo is secured: " + 
				((goo instanceof SecuredObject) ? "PASS" : "FAIL")
			);
		System.out.println("goo credentials: " + goo.getSecurityCredentials());
		System.out.println("Test BankAccount is not secured: " + 
				((acc instanceof SecuredObject) ? "FAIL" : "PASS")
			);
		System.out.println("Test PrivateBankAccount is not secured: " + 
				((pacc instanceof SecuredObject) ? "FAIL" : "PASS")
			);
		System.out.println("Test BusinessBankAccount is secured: " + 
				((bacc instanceof SecuredObject) ? "PASS" : "FAIL")
			);		
	}
}


interface SecuredObject {}
@interface Secured {}

class Foo {}
@Secured class Goo{}

class BankAccount {}

class PrivateBankAccount extends BankAccount {}

@Secured class BusinessBankAccount extends BankAccount {}