Java inspection: Don't offer to replace this.quals() and super.equals() with Objects.equals() (IDEA-161707)

This commit is contained in:
Pavel Dolgov
2016-09-26 17:51:51 +03:00
parent d1f2f472dd
commit f1c87220b3
3 changed files with 32 additions and 1 deletions
@@ -123,6 +123,10 @@ public class EqualsReplaceableByObjectsCallInspection extends BaseInspection {
if (!HardcodedMethodConstants.EQUALS.equals(methodName)) {
return;
}
final PsiExpression qualifierExpression = getQualifierExpression(expression);
if (qualifierExpression instanceof PsiThisExpression || qualifierExpression instanceof PsiSuperExpression) {
return;
}
final PsiElement maybeBinary = PsiTreeUtil.skipParentsOfType(expression, PsiParenthesizedExpression.class, PsiPrefixExpression.class);
if (maybeBinary instanceof PsiBinaryExpression) {
if (processNotNullCheck((PsiBinaryExpression)maybeBinary)) {
@@ -130,7 +134,6 @@ public class EqualsReplaceableByObjectsCallInspection extends BaseInspection {
}
}
if (!checkNotNull) {
final PsiExpression qualifierExpression = getQualifierExpression(expression);
if (qualifierExpression == null) {
return;
}
@@ -35,4 +35,18 @@ class EqualsReplaceableByObjectsCall {
String s;
T copy() { T t = new T(); t.s = s; return t; }
}
static class X extends T {
public boolean equals(Object o) {
return super.equals(o);
}
boolean same(T t) {
return this == t || this != null && this.equals(t);
}
boolean different(T t) {
return <warning descr="'t != this && (t == null || !t.equals(this))' replaceable by 'Objects.equals()' expression">t != this && (t == null || !t.equals(this))</warning>;
}
}
}
@@ -35,4 +35,18 @@ class EqualsReplaceableByObjectsCall {
String s;
T copy() { T t = new T(); t.s = s; return t; }
}
static class X extends T {
public boolean equals(Object o) {
return super.equals(o);
}
boolean same(T t) {
return this == t || this != null && this.equals(t);
}
boolean different(T t) {
return <warning descr="'t != this && (t == null || !t.equals(this))' replaceable by 'Objects.equals()' expression">t != this && (t == null || !t.equals(this))</warning>;
}
}
}