summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/test/com/siyeh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets/test/com/siyeh')
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.after.java11
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.java11
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/equals_with_itself/EqualsWithItself.java23
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/TestCaseWithNoTestMethodsInspection.java15
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_method_naming_convention/JUnit3MethodNamingConvention.java10
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/BeforeAnnotationUsed.java9
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/JUnit3StyleTestMethodInJUnit4Class.java10
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit4_method_naming_convention/JUnit4MethodNamingConvention.java16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_case_with_no_test_methods/TestCaseWithNoTestMethods.java19
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit3TestMethodIsPublicVoidNoArg.java16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit4TestMethodIsPublicVoidNoArg.java24
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java29
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml44
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/naming/native_method_naming_convention/NativeMethodNamingConvention.java2
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java51
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml129
17 files changed, 218 insertions, 214 deletions
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.after.java
new file mode 100644
index 000000000000..42653ac7af63
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.after.java
@@ -0,0 +1,11 @@
+class LocalClass {
+
+ void foo() {
+ class A<T> {
+ void foo() {}
+ }
+ class B<T> extends A<T> {}
+ A<String> bb = new B();
+ bb.foo();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.java
new file mode 100644
index 000000000000..1c905035b914
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/abstraction/type_may_be_weakened/LocalClass.java
@@ -0,0 +1,11 @@
+class LocalClass {
+
+ void foo() {
+ class A<T> {
+ void foo() {}
+ }
+ class B<T> extends A<T> {}
+ B<String> b<caret>b = new B();
+ bb.foo();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
index 370aba53a19c..a134fcd8d9fb 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/TypeMayBeWeakened.java
@@ -162,4 +162,15 @@ class Test implements Foo2 {
interface Foo {
void bar();
}
-interface Foo2 extends Foo {} \ No newline at end of file
+interface Foo2 extends Foo {}
+class Helper {
+
+ void foo() {
+ class A<T> {
+ void foo() {}
+ }
+ class B<T> extends A<T> {}
+ B<String> <warning descr="Type of variable 'b' may be weakened to 'A'">b</warning> = new B();
+ b.foo();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/equals_with_itself/EqualsWithItself.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/equals_with_itself/EqualsWithItself.java
new file mode 100644
index 000000000000..03347da345a5
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/equals_with_itself/EqualsWithItself.java
@@ -0,0 +1,23 @@
+class EqualsWithItself {
+
+ boolean foo(Object o) {
+ return o.<warning descr="Identical qualifier and argument to 'equals()' call">equals</warning>(((o)));
+ }
+
+ boolean withGetter() {
+ return getValue().<warning descr="Identical qualifier and argument to 'equals()' call">equals</warning>(getValue());
+ }
+
+ boolean withMethodCall() {
+ return build().equals(build());
+ }
+
+ private Integer value = 1;
+ public Integer getValue() {
+ return value;
+ }
+
+ public Object build() {
+ return new Object();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/TestCaseWithNoTestMethodsInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/TestCaseWithNoTestMethodsInspection.java
deleted file mode 100644
index f2f0afea3a7c..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/TestCaseWithNoTestMethodsInspection.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.siyeh.igtest.junit;
-
-import junit.framework.TestCase;
-
-public class TestCaseWithNoTestMethodsInspection extends TestCase
-{
- public TestCaseWithNoTestMethodsInspection()
- {
- }
-
- public void teardown()
- {
-
- }
-}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_method_naming_convention/JUnit3MethodNamingConvention.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_method_naming_convention/JUnit3MethodNamingConvention.java
new file mode 100644
index 000000000000..fbe2e70e0945
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_method_naming_convention/JUnit3MethodNamingConvention.java
@@ -0,0 +1,10 @@
+public class JUnit3MethodNamingConvention extends junit.framework.TestCase {
+
+ public void <warning descr="JUnit 3 test method name 'testA' is too short (5 < 8)">testA</warning>() {}
+
+ public void <warning descr="JUnit 3 test method name 'testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (82 > 64)">testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
+
+ public void <warning descr="JUnit 3 test method name 'testGiveMeMore$$$' doesn't match regex 'test[A-Za-z_\d]*'">testGiveMeMore$$$</warning>() {}
+
+ public void test_me_properly() {}
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/BeforeAnnotationUsed.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/BeforeAnnotationUsed.java
new file mode 100644
index 000000000000..6ef566f99035
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/BeforeAnnotationUsed.java
@@ -0,0 +1,9 @@
+import org.junit.Before;
+
+public class BeforeAnnotationUsed {
+
+ @Before
+ public void before() {}
+
+ public void <warning descr="Old style JUnit test method 'testOldStyle()' in JUnit 4 class">testOldStyle</warning>() {}
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/JUnit3StyleTestMethodInJUnit4Class.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/JUnit3StyleTestMethodInJUnit4Class.java
new file mode 100644
index 000000000000..e5df9e6d40ba
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit3_style_test_method_in_junit4_class/JUnit3StyleTestMethodInJUnit4Class.java
@@ -0,0 +1,10 @@
+import org.junit.Test;
+
+public class JUnit3StyleTestMethodInJUnit4Class {
+
+ @Test
+ public void junit4Test() {
+ }
+
+ public void <warning descr="Old style JUnit test method 'testJUnit3()' in JUnit 4 class">testJUnit3</warning>() {}
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit4_method_naming_convention/JUnit4MethodNamingConvention.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit4_method_naming_convention/JUnit4MethodNamingConvention.java
new file mode 100644
index 000000000000..69379a9abb87
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/junit4_method_naming_convention/JUnit4MethodNamingConvention.java
@@ -0,0 +1,16 @@
+import org.junit.Test;
+
+public class JUnit4MethodNamingConvention {
+
+ @Test
+ public void <warning descr="JUnit 4 test method name 'a' is too short (1 < 4)">a</warning>() {}
+
+ @Test
+ public void <warning descr="JUnit 4 test method name 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (78 > 64)">abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
+
+ @Test
+ public void <warning descr="JUnit 4 test method name 'more$$$' doesn't match regex '[a-z][A-Za-z_\d]*'">more$$$</warning>() {}
+
+ @Test
+ public void assure_foo_is_never_null() {}
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_case_with_no_test_methods/TestCaseWithNoTestMethods.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_case_with_no_test_methods/TestCaseWithNoTestMethods.java
new file mode 100644
index 000000000000..559dcce72720
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_case_with_no_test_methods/TestCaseWithNoTestMethods.java
@@ -0,0 +1,19 @@
+public class <warning descr="JUnit test case 'TestCaseWithNoTestMethods' has no tests">TestCaseWithNoTestMethods</warning> extends junit.framework.TestCase {
+
+ TestCaseWithNoTestMethods() {}
+
+ public int testOne() {
+ return 1;
+ }
+
+ public static void testTwo() {}
+ void testThree() {}
+ public void testFour(int i) {}
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit3TestMethodIsPublicVoidNoArg.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit3TestMethodIsPublicVoidNoArg.java
new file mode 100644
index 000000000000..68a5df1305f6
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit3TestMethodIsPublicVoidNoArg.java
@@ -0,0 +1,16 @@
+public class JUnit3TestMethodIsPublicVoidNoArg extends junit.framework.TestCase {
+
+ public JUnit3TestMethodIsPublicVoidNoArg() {}
+
+ void <warning descr="Test method 'testOne()' is not declared 'public void'">testOne</warning>() {}
+
+ public int <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>() {
+ return 2;
+ }
+
+ public static void <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() {}
+
+ public void <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(int i) {}
+
+ public void testFive() {}
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit4TestMethodIsPublicVoidNoArg.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit4TestMethodIsPublicVoidNoArg.java
new file mode 100644
index 000000000000..8641acb3b49e
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_is_public_void_no_arg/JUnit4TestMethodIsPublicVoidNoArg.java
@@ -0,0 +1,24 @@
+import org.junit.Test;
+
+public class JUnit4TestMethodIsPublicVoidNoArg {
+
+ @Test
+ JUnit4TestMethodIsPublicVoidNoArg() {}
+
+ @Test
+ void <warning descr="Test method 'testOne()' is not declared 'public void'">testOne</warning>() {}
+
+ @Test
+ public int <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>() {
+ return 2;
+ }
+
+ @Test
+ public static void <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() {}
+
+ @Test
+ public void <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(int i) {}
+
+ @Test
+ public void testFive() {}
+} \ No newline at end of file
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>&lt;code&gt;if&lt;/code&gt; 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>&lt;code&gt;if&lt;/code&gt; 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>&lt;code&gt;if&lt;/code&gt; 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>&lt;code&gt;if&lt;/code&gt; 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>&lt;code&gt;if&lt;/code&gt; 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>&lt;code&gt;if&lt;/code&gt; statement replaceable with 'switch' statement #loc</description>
- </problem>
-</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/native_method_naming_convention/NativeMethodNamingConvention.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/native_method_naming_convention/NativeMethodNamingConvention.java
index 9f39c4ceb884..9b8a8e66d289 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/native_method_naming_convention/NativeMethodNamingConvention.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/naming/native_method_naming_convention/NativeMethodNamingConvention.java
@@ -28,4 +28,6 @@ public class NativeMethodNamingConvention implements Runnable
public native void run();
private void a() {}
+
+ public static native void <warning descr="'native' method name 'b' is too short">b</warning>();
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
index 4ba7a97033ad..9a10262e3148 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
@@ -1,5 +1,7 @@
package com.siyeh.igtest.numeric.pointless_arithmetic_expression;
+import java.util.Random;
+
public class PointlessArithmeticExpression
{
private static final int ZERO_CONSTANT = 0;
@@ -8,11 +10,11 @@ public class PointlessArithmeticExpression
public static void main(String[] args)
{
final int i = 2;
- final int j = i + 0;
+ final int j = <warning descr="'i + 0' can be replaced with 'i'">i + 0</warning>;
System.out.println(j);
- int k = 0+j;
+ int k = <warning descr="'0+j' can be replaced with 'j'">0+j</warning>;
System.out.println(k);
- k = j - 0;
+ k = <warning descr="'j - 0' can be replaced with 'j'">j - 0</warning>;
System.out.println(k);
k = 0 - j;
System.out.println(k);
@@ -20,11 +22,11 @@ public class PointlessArithmeticExpression
System.out.println(k);
k = j * ONE_CONSTANT;
System.out.println(k);
- k = j / 1;
+ k = <warning descr="'j / 1' can be replaced with 'j'">j / 1</warning>;
System.out.println(k);
String string = "foo" + 0;
- k = j%1;
+ k = <warning descr="'j%1' can be replaced with '0'">j%1</warning>;
System.out.println(k);
if(k<=Integer.MAX_VALUE)
@@ -90,9 +92,9 @@ public class PointlessArithmeticExpression
}
void more(int i) {
- System.out.println(i / i);
- System.out.println(i - i);
- System.out.println(i % i);
+ System.out.println(<warning descr="'i / i' can be replaced with '1'">i / i</warning>);
+ System.out.println(<warning descr="'i - i' can be replaced with '0'">i - i</warning>);
+ System.out.println(<warning descr="'i % i' can be replaced with '0'">i % i</warning>);
}
}
class Main {
@@ -111,18 +113,29 @@ class Main {
return (CONST + (new Main(5).i) * 8) - (Main.CONST + new Main(5).i * (8));
}
- int one = 5/5;
+ int one = <warning descr="'5/5' can be replaced with '1'">5/5</warning>;
}
class Expanded {{
- int m = 1/**/ - (byte)0 - 9; // warn
- int j = 8 * 0 * 8;
- int k = 1 + /*a*/0 +/**/ 9;
- byte l = (byte) (1L - 1L);
+ int m = <warning descr="'1/**/ - (byte)0 - 9' can be replaced with '1/**/ - 9'">1/**/ - (byte)0 - 9</warning>; // warn
+ int j = <warning descr="'8 * 0 * 8' can be replaced with '0'">8 * 0 * 8</warning>;
+ int k = <warning descr="'1 + /*a*/0 +/**/ 9' can be replaced with '1 + /*a*//**/ 9'">1 + /*a*/0 +/**/ 9</warning>;
+ byte l = (byte) (<warning descr="'1L - 1L' can be replaced with '0L'">1L - 1L</warning>);
byte u = 1;
- int z = 2 / 1 / 1;
- System.out.println(u * 1);
- long g = 8L / 8L;
- long h = 9L * 0L;
- int a = 8 * 0 * 8 * ; // don't warn
+ int z = <warning descr="'2 / 1 / 1' can be replaced with '2 / 1'">2 / 1 / 1</warning>;
+ System.out.println(<warning descr="'u * 1' can be replaced with 'u'">u * 1</warning>);
+ long g = <warning descr="'8L / 8L' can be replaced with '1L'">8L / 8L</warning>;
+ long h = <warning descr="'9L * 0L' can be replaced with '0L'">9L * 0L</warning>;
+ int a = 8 * 0 * 8 *<error descr="Expression expected"> </error>; // don't warn
int minus = 2 - 1 - 1;
-}} \ No newline at end of file
+ int div = 3 / 2 / 2;
+ int mod = 3 % 2 % 2;
+}}
+class SideEffects {
+ public static void main( String args[] ){
+ Random rand = new Random();
+ int array[] = {1, 2, 4};
+ int i = 1;
+ int b = array[i++] - array[i++];
+ System.out.println(rand.nextInt(1000) - rand.nextInt(1000));
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml
deleted file mode 100644
index f6af12237ea0..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml
+++ /dev/null
@@ -1,129 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<problems>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>11</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i + 0&lt;/code&gt; can be replaced with 'i' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>13</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;0+j&lt;/code&gt; can be replaced with 'j' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>15</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;j - 0&lt;/code&gt; can be replaced with 'j' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>23</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;j / 1&lt;/code&gt; can be replaced with 'j' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>27</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;j%1&lt;/code&gt; can be replaced with '0' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>93</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i / i&lt;/code&gt; can be replaced with '1' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>94</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i - i&lt;/code&gt; can be replaced with '0' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>95</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i % i&lt;/code&gt; can be replaced with '0' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>111</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;(CONST + (new Main(5).i) * 8) - (Main.CONST + new Main(5).i * (8))&lt;/code&gt; can be replaced with '0' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>114</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;5/5&lt;/code&gt; can be replaced with '1' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>117</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;1/**/ - (byte)0 - 9&lt;/code&gt; can be replaced with '1/**/ - 9' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>118</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;8 * 0 * 8&lt;/code&gt; can be replaced with '0' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>119</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;1 + /*a*/0 +/**/ 9&lt;/code&gt; can be replaced with '1 + /*a*//**/ 9' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>120</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;1L - 1L&lt;/code&gt; can be replaced with '0L' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>122</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;2 / 1 / 1&lt;/code&gt; can be replaced with '2 / 1' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>123</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;u * 1&lt;/code&gt; can be replaced with 'u' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>124</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;8L / 8L&lt;/code&gt; can be replaced with '1L' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>125</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;9L * 0L&lt;/code&gt; can be replaced with '0L' #loc</description>
- </problem>
-</problems> \ No newline at end of file