summaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj/annotationGen/DeclareParentsTest.aj
blob: 0a0da67694ef956f3ba18e69bd2a1b24a0114f74 (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
import org.aspectj.lang.reflect.*;
import java.lang.reflect.*;

public aspect DeclareParentsTest {
	
	declare parents : B || C extends A;

    declare parents : A implements I,J;
	
	public static void main(String[] args) throws ClassNotFoundException {
		AjType<DeclareParentsTest> myType = AjTypeSystem.getAjType(DeclareParentsTest.class);
		DeclareParents[] decPs = myType.getDeclareParents();
		if (decPs.length != 2) throw new RuntimeException("Expecting 2 members, got " + decPs.length);
		if (decPs[0].isExtends()) {
			checkExtends(decPs[0]);
			checkImplements(decPs[1]);
		} else {
			checkExtends(decPs[1]);
			checkImplements(decPs[0]);
		}
	}
	
	private static void checkExtends(DeclareParents extendsDecP) throws ClassNotFoundException {
		if (!extendsDecP.isExtends()) throw new RuntimeException("Should be extends");
		AjType declaring = extendsDecP.getDeclaringType();
		if (declaring.getJavaClass() != DeclareParentsTest.class) throw new RuntimeException("wrong declaring type");
		TypePattern tp = extendsDecP.getTargetTypesPattern();
		if (!tp.asString().equals("(B || C)")) throw new RuntimeException("expecting (B || C) but got '" + tp.asString() + "'");
		Type[] parentTypes = extendsDecP.getParentTypes();
		if (parentTypes.length != 1) throw new RuntimeException("expecting 1 parent type");
		if (((AjType<?>)parentTypes[0]).getJavaClass() != A.class) throw new RuntimeException("expecting parent to be A but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");
	}
	
	private static void checkImplements(DeclareParents implementsDecP) throws ClassNotFoundException {
		if (!implementsDecP.isImplements()) throw new RuntimeException("Should be implements");
		AjType declaring = implementsDecP.getDeclaringType();
		if (declaring.getJavaClass() != DeclareParentsTest.class) throw new RuntimeException("wrong declaring type");
		TypePattern tp = implementsDecP.getTargetTypesPattern();
		if (!tp.asString().equals("A")) throw new RuntimeException("expecting A but got '" + tp.asString() + "'");
		Type[] parentTypes = implementsDecP.getParentTypes();
		if (parentTypes.length != 2) throw new RuntimeException("expecting 2 parent types");
		if (((AjType<?>)parentTypes[0]).getJavaClass() != I.class) throw new RuntimeException("expecting parent to be I but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");		
		if (((AjType<?>)parentTypes[1]).getJavaClass() != J.class) throw new RuntimeException("expecting parent to be J but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");		
	}
}


class A {}

class B {}

class C {}

interface I {}

interface J {}