mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make IG test light
This commit is contained in:
+10
-10
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-65
@@ -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 <code>b ? 1 + 2 + 3 : 1 + 2 + 3</code> 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 <code>b ? java.lang.String.class : String.class</code> 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 <code>new Random().nextBoolean() ? (Object) "1" : (Object) "2"</code> 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 <code>new Random().nextBoolean() ? "21" + (Object) "1" : "21" + (Object) "2"</code> 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 <code>new Random().nextBoolean() ? ints[3] : ints[4]</code> 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 <code>new Random().nextBoolean()? "asd" + strings[2] : "qwe" + strings[2]</code> 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 <code>new Random().nextBoolean() ? 6 + someMethod("123", "") : 6 + someMethod("321", "")</code> 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 <code>new Random().nextBoolean() ? "2" + "q" + "1" : "2" + "qwe" + "1"</code> 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 <code>i == 1 ? new Item("1") : new Item("2")</code> with identical or similar branches #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+27
-5
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user