make IG test light

This commit is contained in:
Bas Leijdekkers
2016-02-12 21:30:29 +01:00
parent 6e43997abd
commit 829ae72879
3 changed files with 37 additions and 80 deletions
@@ -5,7 +5,7 @@ import java.util.Random;
class ConditionalExpressionWithIdenticalBranches {
int one(boolean b) {
return b ? 1 + 2 + 3 : 1 + 2 + 3;
return <warning descr="Conditional expression 'b ? 1 + 2 + 3 : 1 + 2 + 3' with identical or similar branches">b ? 1 + 2 + 3 : 1 + 2 + 3</warning>;
}
int two(boolean b) {
@@ -13,35 +13,35 @@ class ConditionalExpressionWithIdenticalBranches {
}
Class<String> three(boolean b) {
return b ? java.lang.String.class : String.class;
return <warning descr="Conditional expression 'b ? java.lang.String.class : String.class' with identical or similar branches">b ? java.lang.String.class : String.class</warning>;
}
int incomplete(boolean b) {
return b?
return b?<EOLError descr="Expression expected"></EOLError><EOLError descr="';' expected"></EOLError>
}
void fuzzy() {
String someString = new Random().nextBoolean() ? "2" + "q" + "1" : "2" + "qwe" + "1";
String someString = <warning descr="Conditional expression 'new Random().nextBoolean() ? \"2\" + \"q\" + \"1\" : \"2\" + \"qwe\" + \"1\"' with identical or similar branches">new Random().nextBoolean() ? "2" + "q" + "1" : "2" + "qwe" + "1"</warning>;
}
void fuzzy2() {
Object someString = new Random().nextBoolean() ? (Object) "1" : (Object) "2";
Object someString = <warning descr="Conditional expression 'new Random().nextBoolean() ? (Object) \"1\" : (Object) \"2\"' with identical or similar branches">new Random().nextBoolean() ? (Object) "1" : (Object) "2"</warning>;
}
void fuzzy3() {
Object someString = new Random().nextBoolean() ? "21" + (Object) "1" : "21" + (Object) "2";
Object someString = <warning descr="Conditional expression 'new Random().nextBoolean() ? \"21\" + (Object) \"1\" : \"21\" + (Object) \"2\"' with identical or similar branches">new Random().nextBoolean() ? "21" + (Object) "1" : "21" + (Object) "2"</warning>;
}
void fuzzy4(int[] ints) {
int i = new Random().nextBoolean() ? ints[3] : ints[4];
int i = <warning descr="Conditional expression 'new Random().nextBoolean() ? ints[3] : ints[4]' with identical or similar branches">new Random().nextBoolean() ? ints[3] : ints[4]</warning>;
}
void fuzzy5(String[] strings) {
String s = new Random().nextBoolean()? "asd" + strings[2] : "qwe" + strings[2];
String s = <warning descr="Conditional expression 'new Random().nextBoolean()? \"asd\" + strings[2] : \"qwe\" + strings[2]' with identical or similar branches">new Random().nextBoolean()? "asd" + strings[2] : "qwe" + strings[2]</warning>;
}
void fuzzy6() {
int j = new Random().nextBoolean() ? 6 + someMethod("123", "") : 6 + someMethod("321", "");
int j = <warning descr="Conditional expression 'new Random().nextBoolean() ? 6 + someMethod(\"123\", \"\") : 6 + someMethod(\"321\", \"\")' with identical or similar branches">new Random().nextBoolean() ? 6 + someMethod("123", "") : 6 + someMethod("321", "")</warning>;
}
int someMethod(String s, String s2) {
@@ -59,7 +59,7 @@ class ConditionalExpressionWithIdenticalBranches {
int i = 1;
Item item = (i == 1 ? new Item("1") : new Item(i)); // warning here
Item item1 = (i == 1 ? new Item("1") : new Item("2")); // warning here
Item item1 = (<warning descr="Conditional expression 'i == 1 ? new Item(\"1\") : new Item(\"2\")' with identical or similar branches">i == 1 ? new Item("1") : new Item("2")</warning>); // warning here
}
}
@@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>8</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;b ? 1 + 2 + 3 : 1 + 2 + 3&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>16</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;b ? java.lang.String.class : String.class&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>28</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean() ? (Object) &quot;1&quot; : (Object) &quot;2&quot;&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>32</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean() ? &quot;21&quot; + (Object) &quot;1&quot; : &quot;21&quot; + (Object) &quot;2&quot;&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>36</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean() ? ints[3] : ints[4]&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>40</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean()? &quot;asd&quot; + strings[2] : &quot;qwe&quot; + strings[2]&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>44</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean() ? 6 + someMethod(&quot;123&quot;, &quot;&quot;) : 6 + someMethod(&quot;321&quot;, &quot;&quot;)&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>24</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;new Random().nextBoolean() ? &quot;2&quot; + &quot;q&quot; + &quot;1&quot; : &quot;2&quot; + &quot;qwe&quot; + &quot;1&quot;&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
<problem>
<file>ConditionalExpressionWithIdenticalBranches.java</file>
<line>62</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Conditional expression with identical or similar branches</problem_class>
<description>Conditional expression &lt;code&gt;i == 1 ? new Item(&quot;1&quot;) : new Item(&quot;2&quot;)&lt;/code&gt; with identical or similar branches #loc</description>
</problem>
</problems>
@@ -1,11 +1,33 @@
/*
* Copyright 2000-2016 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.controlflow;
import com.siyeh.ig.IGInspectionTestCase;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import org.jetbrains.annotations.Nullable;
public class ConditionalExpressionWithIdenticalBranchesInspectionTest extends IGInspectionTestCase {
public class ConditionalExpressionWithIdenticalBranchesInspectionTest extends LightInspectionTestCase {
public void test() throws Exception {
doTest("com/siyeh/igtest/controlflow/conditional_expression_with_identical_branches",
new ConditionalExpressionWithIdenticalBranchesInspection());
public void testConditionalExpressionWithIdenticalBranches() {
doTest();
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new ConditionalExpressionWithIdenticalBranchesInspection();
}
}