identical if branches: duplicates should be treated according to their treatment to replace: do not delete if branch with another return value (IDEA-71539)

This commit is contained in:
anna
2011-06-29 14:35:37 +04:00
parent 2483e71fde
commit 7214e19e0c
3 changed files with 48 additions and 20 deletions

View File

@@ -176,7 +176,7 @@ public class IfStatementWithIdenticalBranchesInspection
return;
}
final Match match = finder.isDuplicate(branch, true);
if (match != null) {
if (match != null && match.getReturnValue() == null) {
registerStatementError(ifStatement, statement);
return;
}

View File

@@ -1,5 +1,9 @@
package com.siyeh.igtest.controlflow.if_statement_with_identical_branches;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class IfStatementWithIdenticalBranches {
void one() {
@@ -100,3 +104,27 @@ public class IfStatementWithIdenticalBranches {
}
}
}
class NotADup {
public String getElementDescription(Object element, Collection location, Dup d, Dup d1) {
if (location instanceof List) {
if (element instanceof String) {
return notNullize(element);
}
} else if (location instanceof Set) {
if (element instanceof String) {
return message(element);
}
}
return null;
}
private String notNullize(Object element) {
return null;
}
private String message(String element) {
return null;
}
}

View File

@@ -2,49 +2,35 @@
<problems>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>6</line>
<line>10</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>11</line>
<line>15</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>19</line>
<line>23</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>40</line>
<line>44</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>60</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>92</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>94</line>
<line>64</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
@@ -55,4 +41,18 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>98</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
<problem>
<file>IfStatementWithIdenticalBranches.java</file>
<line>100</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' statement with identical branches</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement with identical branches #loc</description>
</problem>
</problems>