Java: Don't cause endless recursive calls of the equals() method in the inspection...
[idea/community.git] / plugins / InspectionGadgets / src / com / siyeh / ig / equality / EqualityOperatorComparesObjectsInspection.java
index 57d00fc9dcfbadd871713c1711344b3cacf647d3..39d789872eaf0d130489fb6983cce864acf56129 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.*;
 import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.psi.util.TypeConversionUtil;
 import com.siyeh.InspectionGadgetsBundle;
@@ -208,6 +209,12 @@ public class EqualityOperatorComparesObjectsInspection extends BaseInspection {
       if (rhsType == null || rhsType instanceof PsiPrimitiveType || TypeConversionUtil.isEnumType(rhsType)) {
         return;
       }
+      if (lhs instanceof PsiThisExpression || rhs instanceof PsiThisExpression) {
+        final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
+        if (method != null && "equals".equals(method.getName())) {
+          return;
+        }
+      }
       final String operationText = expression.getOperationSign().getText();
       final String prefix = tokenType.equals(JavaTokenType.NE) ? "!" : "";
       registerError(expression, operationText, prefix);