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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
import org.aspectj.testing.Tester;
/** @testcase PR#536 overriding subclass method may be protected when superclass method has default access */
public class RestrictingVisibilityCP {
public static void main(String[] args) {
Tester.expectEventsInString(Const.EXPECTED);
Parent[] tests = new Parent[]
{ new Parent()
, new ValidChild()
, new ValidChild2()
, new ValidChild3()
, new ValidChildTest()
, new ValidChildTest2()
, new ValidChildTest3()
};
Parent child;
for (int i = 0; i< tests.length;i++) {
child = tests[i];
Tester.event(child.getClass().getName());
//System.err.println(", \"" + child.getClass().getName() + "\"");
child.publicAccess();
child.defaultAccess();
child.protectedAccess();
child.drivePrivateAccess();
}
Tester.checkAllEvents();
}
}
/** aspect used to log progess - test case otherwise purejava */
aspect LogAll {
before() : within(Parent+) && execution(* *(..)) {
String name = thisJoinPointStaticPart.toString();
Tester.event(name);
// System.err.println(", \"" + name + "\"");
}
}
class Parent {
public int publicAccess = 1;
protected int protectedAccess = 1;
int defaultAccess = 1;
private int privateAccess = 1;
public void publicAccess() {}
protected void protectedAccess() {}
void defaultAccess() {}
private void privateAccess() {}
void drivePrivateAccess() {
privateAccess();
}
}
class ValidChild extends Parent {
/** @testcase subclass public implementation of public method */
public void publicAccess() { super.publicAccess(); }
/** @testcase subclass protected implementation of protected method */
protected void protectedAccess() { super.protectedAccess(); }
/** @testcase subclass default implementation of default method */
void defaultAccess() { super.defaultAccess(); }
/** @testcase subclass implementation of private method - not overriding */
private void privateAccess() { }
void drivePrivateAccess() {
privateAccess();
super.drivePrivateAccess();
}
int publicAccessSub = publicAccess;
int protectedAccessSub = protectedAccess;
int defaultAccessSub = defaultAccess;
}
class ValidChild2 extends Parent {
/** @testcase subclass public implementation of protected method */
public void protectedAccess() { super.protectedAccess(); }
/** @testcase subclass public implementation of default method */
public void defaultAccess() { super.defaultAccess(); }
}
class ValidChild3 extends Parent {
/** @testcase subclass protected implementation of default method */
// todo: restore to restore ce
protected void defaultAccess() { super.defaultAccess(); }
}
class ValidChildTest extends ValidChild {
/** @testcase subsubclass public implementation of public method */
public void publicAccess() { super.publicAccess(); }
/** @testcase subsubclass protected implementation of protected method */
protected void protectedAccess() { super.protectedAccess(); }
/** @testcase subsubclass default implementation of default method */
void defaultAccess() { super.defaultAccess(); }
/** @testcase subsubclass implementation of private method - not overriding */
private void privateAccess() { }
void drivePrivateAccess() {
privateAccess();
super.drivePrivateAccess();
}
}
class ValidChildTest2 extends ValidChild {
/** @testcase subsubclass public implementation of protected method */
public void protectedAccess() { super.protectedAccess(); }
/** @testcase subsubclass public implementation of default method */
public void defaultAccess() { super.defaultAccess(); }
}
class ValidChildTest3 extends ValidChild {
/** @testcase PR#536 subsubclass protected implementation of default method */
// todo protected void defaultAccess() { super.defaultAccess(); }
}
class ValidChild5 extends Parent {
int one = publicAccess;
int two = protectedAccess;
int three = defaultAccess;
}
class ValidClass {
static int[] ra;
static {
ra = new int[]
{ (new Parent()).publicAccess
, (new ValidChild()).publicAccess
, (new ValidChildTest()).publicAccess
, (new Parent()).defaultAccess
, (new ValidChild()).defaultAccess
, (new ValidChildTest()).defaultAccess
, (new Parent()).protectedAccess
, (new ValidChild()).protectedAccess
, (new ValidChildTest()).protectedAccess
};
for (int i = 0; i < ra.length; i++) {
Tester.check(1 == ra[i],
"expected 1 at " + i + " got i" + ra[i]);
}
}
}
class Const {
public static final String[] EXPECTED = new String[]
{ "Parent"
, "execution(void Parent.publicAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "ValidChild"
, "execution(void ValidChild.publicAccess())"
, "execution(void Parent.publicAccess())"
, "execution(void ValidChild.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void ValidChild.protectedAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void ValidChild.drivePrivateAccess())"
, "execution(void ValidChild.privateAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "ValidChild2"
, "execution(void Parent.publicAccess())"
, "execution(void ValidChild2.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void ValidChild2.protectedAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "ValidChild3"
, "execution(void Parent.publicAccess())"
, "execution(void ValidChild3.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "execution(void ValidChildTest.publicAccess())"
, "execution(void ValidChild.publicAccess())"
, "execution(void Parent.publicAccess())"
, "ValidChildTest"
, "execution(void ValidChildTest.defaultAccess())"
, "execution(void ValidChild.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void ValidChildTest.protectedAccess())"
, "execution(void ValidChild.protectedAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void ValidChildTest.drivePrivateAccess())"
, "execution(void ValidChildTest.privateAccess())"
, "execution(void ValidChild.drivePrivateAccess())"
, "execution(void ValidChild.privateAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "ValidChildTest2"
, "execution(void ValidChild.publicAccess())"
, "execution(void Parent.publicAccess())"
, "execution(void ValidChildTest2.defaultAccess())"
, "execution(void ValidChild.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void ValidChildTest2.protectedAccess())"
, "execution(void ValidChild.protectedAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void ValidChild.drivePrivateAccess())"
, "execution(void ValidChild.privateAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
, "ValidChildTest3"
, "execution(void ValidChild.publicAccess())"
, "execution(void Parent.publicAccess())"
, "execution(void ValidChild.defaultAccess())"
, "execution(void Parent.defaultAccess())"
, "execution(void ValidChild.protectedAccess())"
, "execution(void Parent.protectedAccess())"
, "execution(void ValidChild.drivePrivateAccess())"
, "execution(void ValidChild.privateAccess())"
, "execution(void Parent.drivePrivateAccess())"
, "execution(void Parent.privateAccess())"
};
}
|