mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IDEA-130024 (False warning 'if statement with identical branches')
This commit is contained in:
@@ -119,7 +119,7 @@ public class DuplicatesFinder {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Match isDuplicate(PsiElement element, boolean ignoreParameterTypesAndPostVariableUsages) {
|
||||
public Match isDuplicate(@NotNull PsiElement element, boolean ignoreParameterTypesAndPostVariableUsages) {
|
||||
annotatePattern();
|
||||
Match match = isDuplicateFragment(element, ignoreParameterTypesAndPostVariableUsages);
|
||||
deannotatePattern();
|
||||
@@ -174,7 +174,7 @@ public class DuplicatesFinder {
|
||||
|
||||
|
||||
@Nullable
|
||||
private Match isDuplicateFragment(PsiElement candidate, boolean ignoreParameterTypesAndPostVariableUsages) {
|
||||
private Match isDuplicateFragment(@NotNull PsiElement candidate, boolean ignoreParameterTypesAndPostVariableUsages) {
|
||||
if (isSelf(candidate)) return null;
|
||||
PsiElement sibling = candidate;
|
||||
ArrayList<PsiElement> candidates = new ArrayList<PsiElement>();
|
||||
@@ -215,7 +215,7 @@ public class DuplicatesFinder {
|
||||
return match;
|
||||
}
|
||||
|
||||
protected boolean isSelf(PsiElement candidate) {
|
||||
protected boolean isSelf(@NotNull PsiElement candidate) {
|
||||
for (PsiElement pattern : myPattern) {
|
||||
if (PsiTreeUtil.isAncestor(pattern, candidate, false)) {
|
||||
return true;
|
||||
@@ -621,6 +621,7 @@ public class DuplicatesFinder {
|
||||
if (resolveResult1 instanceof PsiMethod && resolveResult2 instanceof PsiMethod) {
|
||||
final PsiMethod method1 = (PsiMethod)resolveResult1;
|
||||
final PsiMethod method2 = (PsiMethod)resolveResult2;
|
||||
if (method1.hasModifierProperty(PsiModifier.STATIC) && !method1.equals(method2)) return false;
|
||||
if (ArrayUtil.find(method1.findSuperMethods(), method2) >= 0) return true;
|
||||
if (ArrayUtil.find(method2.findSuperMethods(), method1) >= 0) return true;
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
class C {
|
||||
Object foo(boolean b) {
|
||||
if (b) {
|
||||
<selection>return A.getInstance();</selection>
|
||||
} else {
|
||||
return B.getInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
class A {
|
||||
static A getInstance() {
|
||||
return new A();
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
static B getInstance() {
|
||||
return new B();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class C {
|
||||
Object foo(boolean b) {
|
||||
if (b) {
|
||||
<selection>return A.getInstance();</selection>
|
||||
} else {
|
||||
return B.getInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
class A {
|
||||
static A getInstance() {
|
||||
return new A();
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class C {
|
||||
Object foo(boolean b) {
|
||||
if (b) {
|
||||
return newMethod();
|
||||
} else {
|
||||
return newMethod();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Object newMethod() {
|
||||
return A.getInstance();
|
||||
}
|
||||
}
|
||||
class A {
|
||||
static A getInstance() {
|
||||
return new A();
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class C {
|
||||
Object foo(boolean b) {
|
||||
if (b) {
|
||||
return newMethod();
|
||||
} else {
|
||||
return B.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Object newMethod() {
|
||||
return A.getInstance();
|
||||
}
|
||||
}
|
||||
class A {
|
||||
static A getInstance() {
|
||||
return new A();
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
static B getInstance() {
|
||||
return new B();
|
||||
}
|
||||
}
|
||||
@@ -245,6 +245,14 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testClassReference() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testClassReference2() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testCodeDuplicates() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user