aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs164/pr164016/Code.aj
blob: e60f099364a1b88b000e94ffa8e0d259e3517395 (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
61
62
63
64
65
66
67
68
69
70
71
package test;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;

interface A {
	void doA();
}

interface BBad extends A {
	void doB();
}

interface BGood extends A {
	void doB();
	void doA();
}

class TargetBad { }
class TargetGood { }

@Aspect
 class DeclareParentsAspect {

//	@DeclareParents(value = "test.TargetGood", defaultImpl = BImplGood.class)
 //       private BGood bGood;

	@DeclareParents(value = "test.TargetBad", defaultImpl = BImplGood.class)
	private BBad bBad;

	public static class BImplGood implements BGood, BBad {

		public void doB() {
			System.out.println("doB");
		}

		public void doA() {
			System.out.println("doA");
		}
	}
}

public class Code {
	public static void main(String... args) { 
/*
		{
			TargetGood target = new TargetGood();
			BGood b = (BGood) target;
			b.doB();
			b.doA();
		}
*/
		{
			TargetBad target = new TargetBad();
			BBad b = (BBad) target;
			b.doB();

			/*
			The following line is the problem.
			The Generated class should refer to ajc$test_DeclareParentsAspect$test_BBad

			Instead...

			Exception in thread "main" java.lang.NoSuchFieldError: ajc$test_DeclareParentsAspect$test_A
			at test.TargetBad.doA(TargetBad.java:1)
			at test.Main.main(Main.java:21)
			*/
			b.doA();
		}
	}

}