@Nullable
  private static PsiMethod findMainMethod(final PsiMethod[] mainMethods, PsiClass aClass, boolean first) {
    List<@NotNull PsiMethod> candidates = new ArrayList<>();
    for (final PsiMethod mainMethod : mainMethods) {
      if (mainMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        continue;
      }
      if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) && !mainMethod.hasModifierProperty(PsiModifier.STATIC)) {
        continue;
      }
      PsiClass containingClass = mainMethod.getContainingClass();
      if (containingClass != null && containingClass != aClass) {
        if (containingClass.isInterface() && !instanceMainMethodsEnabled(containingClass)) {
          continue;
        }
        if (containingClass.isInterface() &&
            mainMethod.hasModifierProperty(PsiModifier.STATIC) &&
            !inheritedStaticMainEnabled(containingClass)) {
          continue;
        }
      }
      if (isMainMethod(mainMethod)) {
        if (first) {
          //fast exit
          return mainMethod;
        }
        candidates.add(mainMethod);
      }
    }
    if(candidates.isEmpty()) {
      return null;
    }
    candidates.sort(mainCandidateComparator);
    return candidates.get(0);
  }
@Nullable
  private static PsiMethod findMainMethod(final PsiMethod[] mainMethods, PsiClass aClass, boolean first)