diff options
Diffstat (limited to 'plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch')
-rw-r--r-- | plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java | 29 | ||||
-rw-r--r-- | plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml | 44 |
2 files changed, 23 insertions, 50 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 diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml deleted file mode 100644 index e56ebb574747..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<problems> - <problem> - <file>IfCanBeSwitch.java</file> - <line>5</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> - - <problem> - <file>IfCanBeSwitch.java</file> - <line>9</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> - - <problem> - <file>IfCanBeSwitch.java</file> - <line>13</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> - - <problem> - <file>IfCanBeSwitch.java</file> - <line>26</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> - - <problem> - <file>IfCanBeSwitch.java</file> - <line>62</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> - - <problem> - <file>IfCanBeSwitch.java</file> - <line>69</line> - <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class> - <description><code>if</code> statement replaceable with 'switch' statement #loc</description> - </problem> -</problems>
\ No newline at end of file |