IG: don't report static equals() methods as covariant (IDEA-165075)

This commit is contained in:
Bas Leijdekkers
2016-12-23 12:29:10 +01:00
parent 62e17777ad
commit b727e0d7c8
3 changed files with 16 additions and 5 deletions
@@ -50,7 +50,9 @@ public class CovariantEqualsInspection extends BaseInspection {
@Override
public void visitMethod(@NotNull PsiMethod method) {
// note: no call to super
if (method.hasModifierProperty(PsiModifier.STATIC)) {
return;
}
final String name = method.getName();
if (!HardcodedMethodConstants.EQUALS.equals(name)) {
return;
@@ -74,7 +76,7 @@ public class CovariantEqualsInspection extends BaseInspection {
return;
}
}
if (SuperMethodsSearch.search(method, null, true, false).findFirst() != null) {
if (MethodUtils.hasSuper(method)) {
return;
}
registerMethodError(method);
@@ -1,8 +1,8 @@
<html>
<body>
Reports a class having a <b>equals()</b>
method taking an argument other than <b>java.lang.Object</b>, if the class does not have a <b>equals()</b> method
which does take <b>java.lang.Object</b> as its argument. Normally, this is a mistake.
Reports <b>equals()</b> methods taking an argument type other than <b>java.lang.Object</b>.
Only reports if the containing class does not have another <b>equals()</b> method
which does take <b>java.lang.Object</b> as its argument type. Normally, this is a mistake.
<!-- tooltip end -->
<p>
@@ -33,4 +33,13 @@ class E {
boolean <warning descr="'equals()' should take 'Object' as its argument">equals</warning>(E e) {
return false;
}
}
abstract class Condition {
static Condition equals(String value) {
return new Condition() {
// some implementation here
};
}
// more abstract methods
}