private static @NotNull Function<PsiClass, MyResult> createSuitabilityCondition(final PsiElement position) {
    if (isExceptionPosition(position)) {
      PsiElement container = PsiTreeUtil.getParentOfType(position, PsiTryStatement.class, PsiMethod.class);
      List<PsiClass> thrownExceptions = new ArrayList<>();
      if (container != null) {
        PsiElement block = container instanceof PsiTryStatement ? ((PsiTryStatement)container).getTryBlock() : container;
        if (block != null) {
          for (PsiClassType type : ExceptionUtil.getThrownExceptions(block)) {
            ContainerUtil.addIfNotNull(thrownExceptions, type.resolve());
          }
        }
      }
      return psiClass -> {
        if (ContainerUtil.exists(thrownExceptions, t -> InheritanceUtil.isInheritorOrSelf(psiClass, t, true))) {
          return MyResult.verySuitableClass;
        }
        return PREFER_THROWABLE.apply(psiClass);
      };
    }
    else if (JavaSmartCompletionContributor.AFTER_THROW_NEW.accepts(position)) {
      return PREFER_THROWABLE;
    }

    if (IN_RESOURCE.accepts(position)) {
      return psiClass -> preferClassIf(InheritanceUtil.isInheritor(psiClass, CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE));
    }

    PsiElement parent = position.getParent();
    if (parent instanceof PsiJavaCodeReferenceElement) {
      PsiElement refParent = parent.getParent();
      if (refParent instanceof PsiAnnotation) {
        PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(((PsiAnnotation)refParent).getOwner());
        return psiClass -> preferClassIf(psiClass.isAnnotationType() && AnnotationTargetUtil.findAnnotationTarget(psiClass, targets) != null);
      }
      if (refParent instanceof PsiTypeElement) {
        List<PsiClass> bounds = getTypeBounds((PsiTypeElement)refParent);
        return psiClass -> preferClassIf(ContainerUtil.exists(bounds, bound -> InheritanceUtil.isInheritorOrSelf(psiClass, bound, true)));
      }
    }

    return aClass -> MyResult.classNameOrGlobalStatic;
  }
private static @NotNull Function<PsiClass, MyResult> createSuitabilityCondition(final PsiElement position)