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