Cleanup (heavy highlighting tests converted)

This commit is contained in:
Roman Shevchenko
2015-07-22 16:28:46 +02:00
parent b526a66917
commit 569ff3cb71
10 changed files with 248 additions and 338 deletions
@@ -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 <warning descr="Local variable 's1' is redundant">s1</warning> = null;
String <warning descr="Local variable 's2' is redundant">s2</warning> = s1, s3 = null;
System.out.println(s2 + s3);
AutoCloseable <warning descr="Local variable 'r1' is redundant">r1</warning> = null;
try (AutoCloseable r2 = r1; AutoCloseable r3 = null) {
System.out.println(r2.toString() + r3.toString());
}
}
void n() throws Exception {
String s1 = null;
String <warning descr="Local variable 's2' is redundant">s2</warning> = s1, <warning descr="Local variable 's3' is redundant">s3</warning> = s1;
System.out.println(s2 + s3);
AutoCloseable r1 = null;
try (AutoCloseable r2 = r1; AutoCloseable r3 = r1) {
System.out.println(<error descr="Operator '+' cannot be applied to 'java.lang.AutoCloseable', 'java.lang.AutoCloseable'">r2 + r3</error>);
}
}
int boxing(Long l) {
long ll = l;
return (int) ll;
}
public int foo() {
int <warning descr="Local variable 'a' is redundant">a</warning> = 2;
int <warning descr="Local variable 'b' is redundant">b</warning> = a;
return b;
}
public int bar() {
int <warning descr="Local variable 'b' is redundant">b</warning> = 3;
return b;
}
public int bar2() throws Exception{
final Exception <warning descr="Local variable 'b' is redundant">b</warning> = new Exception();
throw b;
}
public int baz() {
int a;
int <warning descr="Local variable 'b' is redundant">b</warning> = 3;
a = b;
return a;
}
public int bazoom() {
final int i = foo();
bar();
final int <warning descr="Local variable 'value' is redundant">value</warning> = 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 <warning descr="Local variable 'i' is redundant">i</warning> = 1 + 2;
return (i);
}
void parenthesized2() {
final RuntimeException <warning descr="Local variable 't' is redundant">t</warning> = new RuntimeException();
throw (t);
}
void parenthesized3(int i) {
int <warning descr="Local variable 'j' is redundant">j</warning> = (i);
}
void parenthesized4(int k) {
final int <warning descr="Local variable 'j' is redundant">j</warning> = 1;
k = (j);
}
void parenthesized5() {
final int <warning descr="Local variable 'j' is redundant">j</warning> = 1;
int <warning descr="Local variable 'k' is redundant">k</warning> = (j);
System.out.println(k);
}
void usedIn8Inner(int j) {
for (int i = 0; i < 7; i++) {
int k = i;
int <warning descr="Local variable 'n' is redundant">n</warning> = 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);
}
};
}
}
@@ -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);
}
};
}
}
@@ -1,128 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>C.java</file>
<line>3</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;s1&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>4</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;s2&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>7</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;r1&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>15</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;s2&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>15</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;s3&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>30</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;a&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>31</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;b&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>36</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;b&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>41</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;b&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>47</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;b&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>55</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;value&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>94</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;i&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>99</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;t&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>108</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;j&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>104</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;j&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>113</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;j&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>114</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;k&lt;/code&gt; is redundant #loc</description>
</problem>
<problem>
<file>C.java</file>
<line>121</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant local variable</problem_class>
<description>Local variable &lt;code&gt;n&lt;/code&gt; is redundant #loc</description>
</problem>
</problems>
@@ -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(<error descr="Variable 'object' might not have been initialized">object</error>);
object = null;
}
}
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -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(<warning descr="Static field 'StaticVariableUninitializedUse.s' used before initialization">StaticVariableUninitializedUse.s</warning>);
}
public static void main(String[] args) {
if (s instanceof Object) {}
if (i == 42) {
if (<warning descr="Static field 'i' used before initialization">i</warning> == 42) {
System.out.println("Unbelievable");
}
System.out.println("only warn once in a method" + i);
}
static int foo() {
return i;
return <warning descr="Static field 'i' used before initialization">i</warning>;
}
}
@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>StaticVariableUninitializedUse.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Static field used before initialization</problem_class>
<description>Static field &lt;code&gt;StaticVariableUninitializedUse.s&lt;/code&gt; used before initialization #loc</description>
</problem>
<problem>
<file>StaticVariableUninitializedUse.java</file>
<line>13</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Static field used before initialization</problem_class>
<description>Static field &lt;code&gt;i&lt;/code&gt; used before initialization #loc</description>
</problem>
<problem>
<file>StaticVariableUninitializedUse.java</file>
<line>20</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Static field used before initialization</problem_class>
<description>Static field &lt;code&gt;i&lt;/code&gt; used before initialization #loc</description>
</problem>
</problems>
@@ -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"); }
}
@@ -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"); }
}
@@ -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"); }
}