Java inspection: fixed test data for TooBroadScopeInspection (IDEA-157727)

This commit is contained in:
Pavel Dolgov
2016-07-08 22:28:59 +03:00
parent 5a4808daae
commit f03a147fe3
3 changed files with 95 additions and 26 deletions
@@ -8,7 +8,7 @@ public class TooBroadScope
public void test() {
// Example #1
{
Collection<Integer> <warning descr="Scope of variable 'list' is too broad">list</warning> = null; //scope too broad
Collection<Integer> list = null; //scope too broad
{
list = new ArrayList<Integer>();
list.add(new Integer(0));
@@ -18,7 +18,7 @@ public class TooBroadScope
// Example #2
{
Collection<Integer> <warning descr="Scope of variable 'list' is too broad">list</warning>; // scope too broad
Collection<Integer> list; // scope too broad
list = new ArrayList<Integer>();
list.add(new Integer(0));
}
@@ -26,14 +26,14 @@ public class TooBroadScope
// Example #3
{
Collection<Integer> <warning descr="Scope of variable 'list' is too broad">list</warning> = null; // nope
Collection<Integer> list = null; // nope
list = new ArrayList<Integer>();
list.add(new Integer(0));
}
}
public void join() {
String <warning descr="Scope of variable 'test' is too broad">test</warning>;
String test;
test = "asdf";
}
@@ -112,7 +112,7 @@ public class TooBroadScope
}
void forLoop() {
int <warning descr="Scope of variable 'i' is too broad">i</warning> = 0;
int i = 0;
for ( ; i < 10; i++) {
System.out.println(i);
}
@@ -134,7 +134,7 @@ public class TooBroadScope
}
void useConstant() {
int <warning descr="Scope of variable 'yes' is too broad">yes</warning> = NON_STATIC_CONSTANT;
int yes = NON_STATIC_CONSTANT;
System.out.println();
System.out.println();
System.out.println();
@@ -152,27 +152,27 @@ public class TooBroadScope
private final String[] EMPTY = {};
private final String[] ONE = {"one"};
void abc() {
String[] <warning descr="Scope of variable 'strings' is too broad">strings</warning> = EMPTY;
String[] strings = EMPTY;
System.out.println();
System.out.println();
System.out.println(strings);
List<String> <warning descr="Scope of variable 'list' is too broad">list</warning> = new ArrayList<>(Arrays.asList(EMPTY));
List<String> list = new ArrayList<>(Arrays.asList(EMPTY));
System.out.println();
System.out.println();
System.out.println(list);
String[] <warning descr="Scope of variable 'ss' is too broad">ss</warning> = new String[10];
String[] ss = new String[10];
System.out.println();
System.out.println();
System.out.println(ss);
String[] <warning descr="Scope of variable 'ss2' is too broad">ss2</warning> = new String[] {""};
String[] ss2 = new String[] {""};
System.out.println();
System.out.println();
System.out.println(ss2);
String[] <warning descr="Scope of variable 'ss3' is too broad">ss3</warning> = {};
String[] ss3 = {};
System.out.println();
System.out.println();
System.out.println(ss3);
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>TooBroadScope.java</file>
<line>11</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;list&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>21</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;list&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>29</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;list&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>36</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;test&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>115</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;i&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>137</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;yes&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>155</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;strings&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>160</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;list&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>165</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;ss&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>170</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;ss2&lt;/code&gt; is too broad #loc</description>
</problem>
<problem>
<file>TooBroadScope.java</file>
<line>175</line>
<problem_class>Scope of variable is too broad</problem_class>
<description>Scope of variable &lt;code&gt;ss3&lt;/code&gt; is too broad #loc</description>
</problem>
</problems>
@@ -1,22 +1,10 @@
package com.siyeh.ig.dataflow;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.IGInspectionTestCase;
import com.siyeh.ig.LightInspectionTestCase;
public class TooBroadScopeInspectionTest extends LightInspectionTestCase {
public class TooBroadScopeInspectionTest extends IGInspectionTestCase {
public void testTooBroadScope() {
doTest();
}
@Override
protected InspectionProfileEntry getInspection() {
return new TooBroadScopeInspection();
}
@Override
protected String getBasePath() {
return "/plugins/InspectionGadgets/test/com/siyeh/igtest/dataflow/scope";
final TooBroadScopeInspection inspection = new TooBroadScopeInspection();
doTest("com/siyeh/igtest/dataflow/scope", inspection);
}
}