blob: 6c101507ab7c4de9283f1b6890da576859d82d0d (
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
|
import org.aspectj.testing.Tester;
public class SuperInIntroduction {
public static void main (String[] args) {
int result = new Sub().getInt();
Tester.check(8==result, "new Sub().getInt() !8==" + result);
ObjectSub sb = new ObjectSub().getClone();
Tester.check(null != sb, "null new ObjectSub().getClone()");
sb = new ObjectSub().getSuperClone();
Tester.check(null != sb, "null new ObjectSub().getSuperClone()");
}
}
class Super {
protected int protectedInt = 1;
protected int protectedIntMethod() { return protectedInt; }
int defaultInt = 1;
int defaultIntMethod() { return defaultInt; }
}
class Sub extends Super { }
class ObjectSub { }
aspect A {
/** @testcase accessing protected method and field of class within code the compiler controls */
public int Sub.getInt() {
int result;
result = super.protectedInt;
result += super.protectedIntMethod();
result += protectedInt;
result += protectedIntMethod();
result += defaultInt;
result += defaultIntMethod();
result += super.defaultInt;
result += super.defaultIntMethod();
return result;
}
/** @testcase accessing protected method of class outside code the compiler controls */
public ObjectSub ObjectSub.getClone() {
try {
Object result = clone();
return (ObjectSub) result;
} catch (CloneNotSupportedException e) {
return this;
}
}
/** @testcase using super to access protected method of class outside code the compiler controls */
public ObjectSub ObjectSub.getSuperClone() {
ObjectSub result = null;
try {
result = (ObjectSub) super.clone();
Tester.check(false, "expecting CloneNotSupportedException");
} catch (CloneNotSupportedException e) {
result = this; // bad programming - ok for testing
}
return result;
}
}
|