1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/warnings/FallThrough.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,62 @@ 1.4 +/** 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 4986256 1.7 + * @compile/ref=FallThrough.noLint.out -XDstdout -XDrawDiagnostics FallThrough.java 1.8 + * @compile/ref=FallThrough.lintAll.out -XDstdout -Xlint:all,-path -XDrawDiagnostics FallThrough.java 1.9 + * @compile/ref=FallThrough.lintFallThrough.out -XDstdout -Xlint:fallthrough -XDrawDiagnostics FallThrough.java 1.10 + */ 1.11 + 1.12 +// control: this class should generate a warning 1.13 +class FallThrough 1.14 +{ 1.15 + int m1(int i) { 1.16 + switch (i) { 1.17 + case 1: i++; case 2: i++; 1.18 + } 1.19 + return i; 1.20 + } 1.21 +} 1.22 + 1.23 +// tests: the warnings that would otherwise be generated should all be suppressed 1.24 +@SuppressWarnings("fallthrough") 1.25 +class FallThrough1 1.26 +{ 1.27 + int m1(int i) { 1.28 + switch (i) { 1.29 + case 1: i++; case 2: i++; 1.30 + } 1.31 + return i; 1.32 + } 1.33 +} 1.34 + 1.35 +class FallThrough2 1.36 +{ 1.37 + @SuppressWarnings("fallthrough") 1.38 + class Bar { 1.39 + int m1(int i) { 1.40 + switch (i) { 1.41 + case 1: i++; case 2: i++; 1.42 + } 1.43 + return i; 1.44 + } 1.45 + } 1.46 + 1.47 + @SuppressWarnings("fallthrough") 1.48 + void m2(int i) { 1.49 + switch (i) { 1.50 + case 1: i++; case 2: i++; 1.51 + } 1.52 + } 1.53 + 1.54 + 1.55 + @SuppressWarnings("fallthrough") 1.56 + static int x = new FallThrough2() { 1.57 + int m1(int i) { 1.58 + switch (i) { 1.59 + case 1: i++; case 2: i++; 1.60 + } 1.61 + return i; 1.62 + } 1.63 + }.m1(0); 1.64 + 1.65 +}