test/tools/javac/depDocComment/SuppressDeprecation.java

changeset 1
9a66ca7c79fa
child 611
4172cfff05f0
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /**
2 * @test /nodynamiccopyright/
3 * @bug 4216683 4346296 4656556 4785453
4 * @summary New rules for when deprecation messages are suppressed
5 * @author gafter
6 *
7 * @compile/ref=SuppressDeprecation.out -XDstdout -Xlint:deprecation -XDrawDiagnostics SuppressDeprecation.java
8 */
9
10 /* Test for the contexts in which deprecations warnings should
11 * (and should not) be given. They should be given when
12 * o invoking a deprecated method from a non-deprecated one.
13 * o new X() using a deprecated constructor
14 * o super() to a deprecated constructor
15 * o extending a deprecated class.
16 * But deprecation messages are suppressed as follows:
17 * o Never complain about code in the same outermost class as
18 * the deprecated entity.
19 * o Extending a deprecated class with a deprecated one is OK.
20 * o Overriding a deprecated method with a deprecated one is OK.
21 * o Code appearing in a deprecated class is OK.
22 *
23 */
24
25 class T {
26 /** var.
27 * @deprecated . */
28 int var;
29
30 /** f.
31 * @deprecated . */
32 void f() {
33 }
34
35 /** g.
36 * @deprecated . */
37 void g() {
38 f();
39 }
40
41 void h() {
42 f();
43 }
44
45 /** T.
46 * @deprecated . */
47 T() {
48 }
49
50 /** T.
51 * @deprecated . */
52 T(int i) {
53 this();
54 }
55
56 T(float f) {
57 this();
58 }
59
60 void xyzzy() {
61 new T();
62 new T(1.4f);
63 }
64 /** plugh.
65 * @deprecated . */
66 void plugh() {
67 new T();
68 new T(1.45f);
69 }
70
71 /** calcx..
72 * @deprecated . */
73 int calcx() { return 0; }
74 }
75
76 class U extends T {
77 /** f.
78 * @deprecated . */
79 void f() {
80 }
81
82 void g() { // error (1)
83 super.g(); // error (2)
84 var = 12; // error (3)
85 }
86
87 U() {} // error (4)
88
89 U(int i) {
90 super(i); // error (5)
91 }
92
93 U(float f) {
94 super(1.3f);
95 }
96 }
97
98 class V extends T {} // error (6)
99
100 /** W.
101 * @deprecated . */
102 class W extends T { // ok - inside deprecated class
103 /** W.
104 * @deprecated . */
105 static {
106 new T(1.3f).g(); // ok - called from deprecated static block
107 }
108
109 /** W.
110 * @deprecated . */
111 {
112 new T(1.3f).g(); // ok - called from deprecated block
113 }
114
115 {
116 new T(1.3f).g(); // ok - inside deprecated class
117 }
118
119 int x = calcx(); // ok - inside deprecated class
120
121 /** y.
122 * @deprecated . */
123 int y = calcx();
124 }
125
126 /** X.
127 * @deprecated . */
128 class X {}
129
130 class Y extends X {} // ok - not overriding anything
131
132 /** Z.
133 * @deprecated . */
134 class Z extends X {}

mercurial