test/tools/javac/depDocComment/SuppressDeprecation.java

changeset 1
9a66ca7c79fa
child 611
4172cfff05f0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/depDocComment/SuppressDeprecation.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,134 @@
     1.4 +/**
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 4216683 4346296 4656556 4785453
     1.7 + * @summary New rules for when deprecation messages are suppressed
     1.8 + * @author gafter
     1.9 + *
    1.10 + * @compile/ref=SuppressDeprecation.out -XDstdout -Xlint:deprecation -XDrawDiagnostics SuppressDeprecation.java
    1.11 + */
    1.12 +
    1.13 +/* Test for the contexts in which deprecations warnings should
    1.14 + * (and should not) be given.  They should be given when
    1.15 + * o  invoking a deprecated method from a non-deprecated one.
    1.16 + * o  new X() using a deprecated constructor
    1.17 + * o  super() to a deprecated constructor
    1.18 + * o  extending a deprecated class.
    1.19 + * But deprecation messages are suppressed as follows:
    1.20 + * o  Never complain about code in the same outermost class as
    1.21 + *    the deprecated entity.
    1.22 + * o  Extending a deprecated class with a deprecated one is OK.
    1.23 + * o  Overriding a deprecated method with a deprecated one is OK.
    1.24 + * o  Code appearing in a deprecated class is OK.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +class T {
    1.29 +    /** var.
    1.30 +     *  @deprecated . */
    1.31 +    int var;
    1.32 +
    1.33 +    /** f.
    1.34 +     *  @deprecated . */
    1.35 +    void f() {
    1.36 +    }
    1.37 +
    1.38 +    /** g.
    1.39 +     *  @deprecated . */
    1.40 +    void g() {
    1.41 +        f();
    1.42 +    }
    1.43 +
    1.44 +    void h() {
    1.45 +        f();
    1.46 +    }
    1.47 +
    1.48 +    /** T.
    1.49 +     *  @deprecated . */
    1.50 +    T() {
    1.51 +    }
    1.52 +
    1.53 +    /** T.
    1.54 +     *  @deprecated . */
    1.55 +    T(int i) {
    1.56 +        this();
    1.57 +    }
    1.58 +
    1.59 +    T(float f) {
    1.60 +        this();
    1.61 +    }
    1.62 +
    1.63 +    void xyzzy() {
    1.64 +        new T();
    1.65 +        new T(1.4f);
    1.66 +    }
    1.67 +    /** plugh.
    1.68 +     *  @deprecated . */
    1.69 +    void plugh() {
    1.70 +        new T();
    1.71 +        new T(1.45f);
    1.72 +    }
    1.73 +
    1.74 +    /** calcx..
    1.75 +     *  @deprecated . */
    1.76 +    int calcx() { return 0; }
    1.77 +}
    1.78 +
    1.79 +class U extends T {
    1.80 +    /** f.
    1.81 +     * @deprecated . */
    1.82 +    void f() {
    1.83 +    }
    1.84 +
    1.85 +    void g() { // error (1)
    1.86 +        super.g(); // error (2)
    1.87 +        var = 12; // error (3)
    1.88 +    }
    1.89 +
    1.90 +    U() {} // error (4)
    1.91 +
    1.92 +    U(int i) {
    1.93 +        super(i); // error (5)
    1.94 +    }
    1.95 +
    1.96 +    U(float f) {
    1.97 +        super(1.3f);
    1.98 +    }
    1.99 +}
   1.100 +
   1.101 +class V extends T {} // error (6)
   1.102 +
   1.103 +/** W.
   1.104 + * @deprecated . */
   1.105 +class W extends T { // ok - inside deprecated class
   1.106 +    /** W.
   1.107 +     * @deprecated . */
   1.108 +    static {
   1.109 +        new T(1.3f).g(); // ok - called from deprecated static block
   1.110 +    }
   1.111 +
   1.112 +    /** W.
   1.113 +     * @deprecated . */
   1.114 +    {
   1.115 +        new T(1.3f).g(); // ok - called from deprecated block
   1.116 +    }
   1.117 +
   1.118 +    {
   1.119 +        new T(1.3f).g(); // ok - inside deprecated class
   1.120 +    }
   1.121 +
   1.122 +    int x = calcx(); // ok - inside deprecated class
   1.123 +
   1.124 +    /** y.
   1.125 +     * @deprecated . */
   1.126 +    int y = calcx();
   1.127 +}
   1.128 +
   1.129 +/** X.
   1.130 + * @deprecated . */
   1.131 +class X {}
   1.132 +
   1.133 +class Y extends X {} // ok - not overriding anything
   1.134 +
   1.135 +/** Z.
   1.136 + * @deprecated . */
   1.137 +class Z extends X {}

mercurial