diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_variable/C.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_variable/C.java
new file mode 100644
index 000000000000..b356ca51be45
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_variable/C.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+class C {
+ void m() throws Exception {
+ String s1 = null;
+ String s2 = s1, s3 = null;
+ System.out.println(s2 + s3);
+
+ AutoCloseable r1 = null;
+ try (AutoCloseable r2 = r1; AutoCloseable r3 = null) {
+ System.out.println(r2.toString() + r3.toString());
+ }
+ }
+
+ void n() throws Exception {
+ String s1 = null;
+ String s2 = s1, s3 = s1;
+ System.out.println(s2 + s3);
+
+ AutoCloseable r1 = null;
+ try (AutoCloseable r2 = r1; AutoCloseable r3 = r1) {
+ System.out.println(r2 + r3);
+ }
+ }
+
+ int boxing(Long l) {
+ long ll = l;
+ return (int) ll;
+ }
+
+ public int foo() {
+ int a = 2;
+ int b = a;
+ return b;
+ }
+
+ public int bar() {
+ int b = 3;
+ return b;
+ }
+
+ public int bar2() throws Exception{
+ final Exception b = new Exception();
+ throw b;
+ }
+
+ public int baz() {
+ int a;
+ int b = 3;
+ a = b;
+ return a;
+ }
+
+ public int bazoom() {
+ final int i = foo();
+ bar();
+ final int value = i;
+ System.out.println(value);
+ return 3;
+ }
+
+ double time() {
+ double time = 0.0, dt = time - 1.0;
+ System.out.println(time);
+ return dt;
+ }
+
+ double time2() {
+ double time = 0.0, dt = time - 1.0;
+ return time;
+ }
+
+ void time3() {
+ double time = 0.0, dt = time - 1.0;
+ double time2 = time;
+ time2 += 1;
+ }
+
+ void through() throws Exception {
+ Exception e2 = instance(), e3 = new RuntimeException(e2);
+ throw e2;
+ }
+
+ Exception instance() {
+ return null;
+ }
+
+ public void neededResourceVariable(java.io.InputStream in) throws java.io.IOException {
+ try (java.io.InputStream inn = in) {
+ final int read = inn.read();
+ // do stuff with in
+ }
+ }
+
+ int parenthesized() {
+ final int i = 1 + 2;
+ return (i);
+ }
+
+ void parenthesized2() {
+ final RuntimeException t = new RuntimeException();
+ throw (t);
+ }
+
+ void parenthesized3(int i) {
+ int j = (i);
+ }
+
+ void parenthesized4(int k) {
+ final int j = 1;
+ k = (j);
+ }
+
+ void parenthesized5() {
+ final int j = 1;
+ int k = (j);
+ System.out.println(k);
+ }
+
+ void usedIn8Inner(int j) {
+ for (int i = 0; i < 7; i++) {
+ int k = i;
+ int n = j;
+ class F {
+ {
+ System.out.println(k + n);
+ }
+ }
+ }
+ }
+
+ void nameShadow(final String name) {
+ final String child = name;
+ class A {
+ void foo(String s){}
+ }
+
+ A a = new A() {
+ void foo(String name) {
+ System.out.println(child);
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/C.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/C.java
deleted file mode 100644
index b188ba7ea2ac..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/C.java
+++ /dev/null
@@ -1,142 +0,0 @@
-class C {
- void m() throws Exception {
- String s1 = null;
- String s2 = s1, s3 = null;
- System.out.println(s2 + s3);
-
- AutoCloseable r1 = null;
- try (AutoCloseable r2 = r1; AutoCloseable r3 = null) {
- System.out.println(r2.toString() + r3.toString());
- }
- }
-
- void n() throws Exception {
- String s1 = null;
- String s2 = s1, s3 = s1;
- System.out.println(s2 + s3);
-
- AutoCloseable r1 = null;
- try (AutoCloseable r2 = r1; AutoCloseable r3 = r1) {
- System.out.println(r2 + r3);
- }
- }
-
- int boxing(Long l) {
- long ll = l;
- return (int) ll;
- }
-
- public int foo() {
- int a = 2;
- int b = a;
- return b;
- }
-
- public int bar() {
- int b = 3;
- return b;
- }
-
- public int bar2() throws Exception{
- final Exception b = new Exception();
- throw b;
- }
-
- public int baz() {
- int a;
- int b = 3;
- a = b;
- return a;
- }
-
- public int bazoom() {
- final int i = foo();
- bar();
- final int value = i;
- System.out.println(value);
- return 3;
- }
-
- double time() {
- double time = 0.0, dt = time - 1.0;
- System.out.println(time);
- return dt;
- }
-
- double time2() {
- double time = 0.0, dt = time - 1.0;
- return time;
- }
-
- void time3() {
- double time = 0.0, dt = time - 1.0;
- double time2 = time;
- time2 += 1;
- }
-
- void through() throws Exception {
- Exception e2 = instance(), e3 = new RuntimeException(e2);
- throw e2;
- }
-
- Exception instance() {
- return null;
- }
-
- public void neededResourceVariable(java.io.InputStream in) throws java.io.IOException {
- try (java.io.InputStream inn = in) {
- final int read = inn.read();
- // do stuff with in
- }
- }
-
- int parenthesized() {
- final int i = 1 + 2;
- return (i);
- }
-
- void parenthesized2() {
- final RuntimeException t = new RuntimeException();
- throw (t);
- }
-
- void parenthesized3(int i) {
- int j = (i);
- }
-
- void parenthesized4(int k) {
- final int j = 1;
- k = (j);
- }
-
- void parenthesized5() {
- final int j = 1;
- int k = (j);
- System.out.println(k);
- }
-
- void usedIn8Inner(int j) {
- for (int i = 0; i < 7; i++) {
- int k = i;
- int n = j;
- class F {
- {
- System.out.println(k + n);
- }
- }
- }
- }
-
- void nameShadow(final String name) {
- final String child = name;
- class A {
- void foo(String s){}
- }
-
- A a = new A() {
- void foo(String name) {
- System.out.println(child);
- }
- };
- }
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/expected.xml
deleted file mode 100644
index aa7bda34c4c4..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/unnecessary_local_vars/expected.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
-
- C.java
- 3
- Redundant local variable
- Local variable <code>s1</code> is redundant #loc
-
-
-
- C.java
- 4
- Redundant local variable
- Local variable <code>s2</code> is redundant #loc
-
-
-
- C.java
- 7
- Redundant local variable
- Local variable <code>r1</code> is redundant #loc
-
-
-
- C.java
- 15
- Redundant local variable
- Local variable <code>s2</code> is redundant #loc
-
-
-
- C.java
- 15
- Redundant local variable
- Local variable <code>s3</code> is redundant #loc
-
-
-
- C.java
- 30
- Redundant local variable
- Local variable <code>a</code> is redundant #loc
-
-
-
- C.java
- 31
- Redundant local variable
- Local variable <code>b</code> is redundant #loc
-
-
-
- C.java
- 36
- Redundant local variable
- Local variable <code>b</code> is redundant #loc
-
-
-
- C.java
- 41
- Redundant local variable
- Local variable <code>b</code> is redundant #loc
-
-
-
- C.java
- 47
- Redundant local variable
- Local variable <code>b</code> is redundant #loc
-
-
-
- C.java
- 55
- Redundant local variable
- Local variable <code>value</code> is redundant #loc
-
-
-
- C.java
- 94
- Redundant local variable
- Local variable <code>i</code> is redundant #loc
-
-
-
- C.java
- 99
- Redundant local variable
- Local variable <code>t</code> is redundant #loc
-
-
-
- C.java
- 108
- Redundant local variable
- Local variable <code>j</code> is redundant #loc
-
-
-
- C.java
- 104
- Redundant local variable
- Local variable <code>j</code> is redundant #loc
-
-
-
- C.java
- 113
- Redundant local variable
- Local variable <code>j</code> is redundant #loc
-
-
-
- C.java
- 114
- Redundant local variable
- Local variable <code>k</code> is redundant #loc
-
-
-
- C.java
- 121
- Redundant local variable
- Local variable <code>n</code> is redundant #loc
-
-
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/InstanceVariableUninitializedUse.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/InstanceVariableUninitializedUse.java
index f43884c69be6..99d048471e38 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/InstanceVariableUninitializedUse.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/InstanceVariableUninitializedUse.java
@@ -1,22 +1,32 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.siyeh.igtest.initialization.instance_variable_uninitialized_use;
import java.io.IOException;
-
-
-
class InstanceVariableUnitializedUse {
-
int i;
- InstanceVariableUnitializedUse() throws IOException {
+ InstanceVariableUnitializedUse() throws IOException {
try (java.io.FileInputStream in = new java.io.FileInputStream("asdf" + (i=3) + "asdf")) {}
System.out.println(i);
-
}
}
-class InstanceFieldVsDoWhile {
+class InstanceFieldVsDoWhile {
private Object object;
public InstanceFieldVsDoWhile() {
@@ -25,11 +35,12 @@ class InstanceFieldVsDoWhile {
} while (object.hashCode() < 1000); // Instance field used before initialization
}
}
+
class FinalField {
private final Object object;
FinalField() {
- System.out.println(object);
+ System.out.println(object);
object = null;
}
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/expected.xml
deleted file mode 100644
index e8f00e82629f..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/instance_variable_uninitialized_use/expected.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/StaticVariableUninitializedUse.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/StaticVariableUninitializedUse.java
index 72b83d469012..91055e99897f 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/StaticVariableUninitializedUse.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/StaticVariableUninitializedUse.java
@@ -1,22 +1,37 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.siyeh.igtest.initialization.static_variable_uninitialized_use;
public class StaticVariableUninitializedUse {
-
static Integer i;
static String s;
static {
- System.out.println(StaticVariableUninitializedUse.s);
+ System.out.println(StaticVariableUninitializedUse.s);
}
+
public static void main(String[] args) {
if (s instanceof Object) {}
- if (i == 42) {
+ if (i == 42) {
System.out.println("Unbelievable");
}
System.out.println("only warn once in a method" + i);
}
static int foo() {
- return i;
+ return i;
}
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/expected.xml
deleted file mode 100644
index f099eb98a6ac..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/initialization/static_variable_uninitialized_use/expected.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
- StaticVariableUninitializedUse.java
- 9
- Static field used before initialization
- Static field <code>StaticVariableUninitializedUse.s</code> used before initialization #loc
-
-
-
- StaticVariableUninitializedUse.java
- 13
- Static field used before initialization
- Static field <code>i</code> used before initialization #loc
-
-
-
- StaticVariableUninitializedUse.java
- 20
- Static field used before initialization
- Static field <code>i</code> used before initialization #loc
-
-
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/dataflow/UnnecessaryLocalVariableInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/dataflow/UnnecessaryLocalVariableInspectionTest.java
index 4efbf1a23d4b..faffd9a83a4f 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/dataflow/UnnecessaryLocalVariableInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/dataflow/UnnecessaryLocalVariableInspectionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,22 +15,14 @@
*/
package com.siyeh.ig.dataflow;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.LanguageLevelProjectExtension;
-import com.intellij.pom.java.LanguageLevel;
-import com.intellij.testFramework.IdeaTestUtil;
-import com.siyeh.ig.IGInspectionTestCase;
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
-public class UnnecessaryLocalVariableInspectionTest extends IGInspectionTestCase {
+public class UnnecessaryLocalVariableInspectionTest extends LightInspectionTestCase {
@Override
- protected Sdk getTestProjectSdk() {
- final Sdk sdk = IdeaTestUtil.getMockJdk17();
- LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST);
- return sdk;
+ protected InspectionProfileEntry getInspection() {
+ return new UnnecessaryLocalVariableInspection();
}
- public void test() throws Exception {
- doTest("com/siyeh/igtest/dataflow/unnecessary_local_vars",
- new UnnecessaryLocalVariableInspection());
- }
+ public void test() { doNamedTest("C"); }
}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/InstanceVariableUninitializedUseInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/InstanceVariableUninitializedUseInspectionTest.java
index afd90aea2e6f..acfac149b815 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/InstanceVariableUninitializedUseInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/InstanceVariableUninitializedUseInspectionTest.java
@@ -1,11 +1,28 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.siyeh.ig.initialization;
-import com.siyeh.ig.IGInspectionTestCase;
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
-public class InstanceVariableUninitializedUseInspectionTest
- extends IGInspectionTestCase {
-
- public void test() throws Exception {
- doTest("com/siyeh/igtest/initialization/instance_variable_uninitialized_use", new InstanceVariableUninitializedUseInspection());
+public class InstanceVariableUninitializedUseInspectionTest extends LightInspectionTestCase {
+ @Override
+ protected InspectionProfileEntry getInspection() {
+ return new InstanceVariableUninitializedUseInspection();
}
+
+ public void test() { doNamedTest("InstanceVariableUninitializedUse"); }
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/StaticVariableUninitializedUseInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/StaticVariableUninitializedUseInspectionTest.java
index 3a61f5c07e80..31b6d0e6351c 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/StaticVariableUninitializedUseInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/initialization/StaticVariableUninitializedUseInspectionTest.java
@@ -1,12 +1,28 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.siyeh.ig.initialization;
-import com.siyeh.ig.IGInspectionTestCase;
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
-public class StaticVariableUninitializedUseInspectionTest
- extends IGInspectionTestCase {
-
- public void test() throws Exception {
- doTest("com/siyeh/igtest/initialization/static_variable_uninitialized_use",
- new StaticVariableUninitializedUseInspection());
+public class StaticVariableUninitializedUseInspectionTest extends LightInspectionTestCase {
+ @Override
+ protected InspectionProfileEntry getInspection() {
+ return new StaticVariableUninitializedUseInspection();
}
+
+ public void test() { doNamedTest("StaticVariableUninitializedUse"); }
}