mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
conditional expression with similar branches doesn't distinguish different constructors in PsiNewExpression (IDEA-149822)
This commit is contained in:
+6
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -775,6 +776,11 @@ public class EquivalenceChecker {
|
||||
if (!expressionsAreEquivalentDecision(arrayInitializer1, arrayInitializer2).getExactlyMatches()) {
|
||||
return EXACTLY_UN_MATCHES;
|
||||
}
|
||||
final PsiMethod constructor1 = newExpression1.resolveConstructor();
|
||||
final PsiMethod constructor2 = newExpression2.resolveConstructor();
|
||||
if (!Comparing.equal(constructor1, constructor2)) {
|
||||
return EXACTLY_UN_MATCHES;
|
||||
}
|
||||
final PsiExpression qualifier1 = newExpression1.getQualifier();
|
||||
final PsiExpression qualifier2 = newExpression2.getQualifier();
|
||||
if (!expressionsAreEquivalentDecision(qualifier1, qualifier2).getExactlyMatches()) {
|
||||
|
||||
+15
@@ -47,4 +47,19 @@ class ConditionalExpressionWithIdenticalBranches {
|
||||
int someMethod(String s, String s2) {
|
||||
return s.length();
|
||||
}
|
||||
|
||||
class Item {
|
||||
Item(String name) {
|
||||
}
|
||||
|
||||
Item(int value) {
|
||||
}
|
||||
|
||||
void v() {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -55,4 +55,11 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user