IG: try to make inspection non-quadratic
[idea/community.git] / plugins / InspectionGadgets / InspectionGadgetsAnalysis / src / com / siyeh / ig / naming / LambdaUnfriendlyMethodOverloadInspectionBase.java
index 3a717ada5d1010ee93dc8da829a19955fa6c043b..cc5a6dbe7c6e09709ef5cea752092e7b20c00407 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.siyeh.ig.naming;
 
  */
 package com.siyeh.ig.naming;
 
+import com.intellij.openapi.util.Key;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiSuperMethodUtil;
 import com.siyeh.InspectionGadgetsBundle;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiSuperMethodUtil;
 import com.siyeh.InspectionGadgetsBundle;
@@ -52,9 +53,14 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
 
   private static class LambdaUnfriendlyMethodOverloadVisitor extends BaseInspectionVisitor {
 
 
   private static class LambdaUnfriendlyMethodOverloadVisitor extends BaseInspectionVisitor {
 
+    private static final Key<Boolean> SKIP_MARKER = new Key<>("skip marker for lambda unfriendly method overload inspection");
+
     @Override
     public void visitMethod(PsiMethod method) {
       super.visitMethod(method);
     @Override
     public void visitMethod(PsiMethod method) {
       super.visitMethod(method);
+      if (method.getUserData(SKIP_MARKER) == Boolean.TRUE) {
+        return;
+      }
       final PsiParameterList parameterList = method.getParameterList();
       final int parametersCount = parameterList.getParametersCount();
       if (parametersCount == 0) {
       final PsiParameterList parameterList = method.getParameterList();
       final int parametersCount = parameterList.getParametersCount();
       if (parametersCount == 0) {
@@ -77,6 +83,7 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
         return;
       }
       final String name = method.getName();
         return;
       }
       final String name = method.getName();
+      boolean problemFound = false;
       for (PsiMethod sameNameMethod : containingClass.findMethodsByName(name, true)) {
         if (method.equals(sameNameMethod) || PsiSuperMethodUtil.isSuperMethod(method, sameNameMethod)) {
           continue;
       for (PsiMethod sameNameMethod : containingClass.findMethodsByName(name, true)) {
         if (method.equals(sameNameMethod) || PsiSuperMethodUtil.isSuperMethod(method, sameNameMethod)) {
           continue;
@@ -95,10 +102,16 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
         }
 
         if (areSameShapeFunctionalTypes(functionalType, otherFunctionalType)) {
         }
 
         if (areSameShapeFunctionalTypes(functionalType, otherFunctionalType)) {
-          registerMethodError(method, method);
-          return;
+          problemFound = true;
+          if (containingClass.equals(sameNameMethod.getContainingClass())) {
+            registerMethodError(sameNameMethod, sameNameMethod);
+            sameNameMethod.putUserData(SKIP_MARKER, Boolean.TRUE);
+          }
         }
       }
         }
       }
+      if (problemFound) {
+        registerMethodError(method, method);
+      }
     }
 
     private static boolean areSameShapeFunctionalTypes(PsiType one, PsiType two) {
     }
 
     private static boolean areSameShapeFunctionalTypes(PsiType one, PsiType two) {