diff options
Diffstat (limited to 'plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java')
-rw-r--r-- | plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java index 7bfc8aa08ff0..a0456798059d 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java @@ -2,15 +2,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; class IfCanBeSwitch { void m1(int i) { // ok - if (i == 0) System.out.println("zero"); else if (i == 1) System.out.println("one"); else System.out.println("many"); + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (i == 0) System.out.println("zero"); else if (i == 1) System.out.println("one"); else System.out.println("many"); } void m1(char c) { // ok - if (c == '0') System.out.println("zero"); else if (c == '1') System.out.println("one"); else System.out.println("many"); + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (c == '0') System.out.println("zero"); else if (c == '1') System.out.println("one"); else System.out.println("many"); } void m1(byte i) { // ok - if (i == (byte)0) System.out.println("zero"); else if (i == (byte)1) System.out.println("one"); else System.out.println("many"); + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (i == (byte)0) System.out.println("zero"); else if (i == (byte)1) System.out.println("one"); else System.out.println("many"); } void m2(int i) { // bad, long literals @@ -23,7 +23,7 @@ class IfCanBeSwitch { void polyadic() { String s = null; - if (s.equals("asdf") || s.equals("addd") || s.equals("lkjh")) { + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (s.equals("asdf") || s.equals("addd") || s.equals("lkjh")) { System.out.println("asdf"); } else if (s.equals("null")) { @@ -59,14 +59,14 @@ class IfCanBeSwitch { } void nullSafe(String earth) { - if (earth.equals("foo")) { + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (earth.equals("foo")) { } else if ("bar".equals(earth)) { } else { } } void nullSafe2(@NotNull String narf) { - if ("foo".equals((narf))) { + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> ("foo".equals((narf))) { // do this } else if ("bar".equals(narf)){ // do that @@ -75,4 +75,21 @@ class IfCanBeSwitch { // do something else. } } + + Num num; + enum Num { + ONE, TWO + } + Num getNum() { + return num; + } + void ifWithGetterToSwitch() { + <warning descr="'if' statement replaceable with 'switch' statement">if</warning> (getNum() == Num.ONE) { + System.out.println(1); + } else if (getNum() == Num.TWO) { + System.out.println(2); + } else { + System.out.println("-"); + } + } }
\ No newline at end of file |