test/tools/javac/warnings/FallThrough.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /**
     2  * @test  /nodynamiccopyright/
     3  * @bug 4986256
     4  * @compile/ref=FallThrough.noLint.out                             -XDrawDiagnostics FallThrough.java
     5  * @compile/ref=FallThrough.lintAll.out         -Xlint:all,-path   -XDrawDiagnostics FallThrough.java
     6  * @compile/ref=FallThrough.lintFallThrough.out -Xlint:fallthrough -XDrawDiagnostics FallThrough.java
     7  */
     9 // control: this class should generate a warning
    10 class FallThrough
    11 {
    12     int m1(int i) {
    13         switch (i) {
    14         case 1: i++; case 2: i++;
    15         }
    16         return i;
    17     }
    18 }
    20 // tests: the warnings that would otherwise be generated should all be suppressed
    21 @SuppressWarnings("fallthrough")
    22 class FallThrough1
    23 {
    24     int m1(int i) {
    25         switch (i) {
    26         case 1: i++; case 2: i++;
    27         }
    28         return i;
    29     }
    30 }
    32 class FallThrough2
    33 {
    34     @SuppressWarnings("fallthrough")
    35     class Bar {
    36         int m1(int i) {
    37             switch (i) {
    38             case 1: i++; case 2: i++;
    39             }
    40             return i;
    41         }
    42     }
    44     @SuppressWarnings("fallthrough")
    45     void m2(int i) {
    46         switch (i) {
    47         case 1: i++; case 2: i++;
    48         }
    49     }
    52     @SuppressWarnings("fallthrough")
    53     static int x = new FallThrough2() {
    54             int m1(int i) {
    55                 switch (i) {
    56                 case 1: i++; case 2: i++;
    57                 }
    58                 return i;
    59             }
    60         }.m1(0);
    62 }

mercurial