@Nullable
  public static PsiClass findEnclosingInstanceInScope(@NotNull PsiClass aClass,
                                                      PsiElement scope,
                                                      @NotNull Condition<? super PsiClass> isSuperClassAccepted,
                                                      boolean isTypeParamsAccepted) {
    PsiManager manager = aClass.getManager();
    PsiElement place = scope;
    while (place != null && !(place instanceof PsiFile)) {
      if (place instanceof PsiClass) {
        if (isSuperClassAccepted.value((PsiClass)place)) {
          if (isInheritorOrSelf((PsiClass)place, aClass, true)) return (PsiClass)place;
        }
        else {
          if (manager.areElementsEquivalent(place, aClass)) return aClass;
        }
        if (isTypeParamsAccepted && place instanceof PsiTypeParameter) {
          return (PsiClass)place;
        }
      }
      if (place instanceof PsiModifierListOwner) {
        final PsiModifierList modifierList = ((PsiModifierListOwner)place).getModifierList();
        if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC)) {
          return null;
        }
      }
      place = place.getParent();
    }
    return null;
  }
@Nullable
  public static PsiClass findEnclosingInstanceInScope(@NotNull PsiClass aClass,
                                                      PsiElement scope,
                                                      @NotNull Condition<? super PsiClass> isSuperClassAccepted,
                                                      boolean isTypeParamsAccepted)