@NotNull
  public static LanguageLevel getLanguageLevel(@NotNull PsiElement element) {
    if (element instanceof PsiDirectory) {
      return JavaDirectoryService.getInstance().getLanguageLevel((PsiDirectory)element);
    }

    PsiFile file = element.getContainingFile();
    // Could be non-physical 'light file' created by some JVM languages
    PsiFile navigationFile = file == null ? null : ObjectUtils.tryCast(file.getNavigationElement(), PsiFile.class);
    if (navigationFile != null) {
      file = navigationFile;
    }
    if (file instanceof PsiJavaFile) {
      return ((PsiJavaFile)file).getLanguageLevel();
    }

    if (file != null) {
      PsiElement context = file.getContext();
      if (context != null) {
        if (!context.isValid()) {
          throw new PsiInvalidElementAccessException(context, "Invalid context in " + file + " of " + file.getClass());
        }
        return getLanguageLevel(context);
      }
    }

    PsiResolveHelper instance = PsiResolveHelper.getInstance(element.getProject());
    return instance != null ? instance.getEffectiveLanguageLevel(getVirtualFile(file)) : LanguageLevel.HIGHEST;
  }
@NotNull
  public static LanguageLevel getLanguageLevel(@NotNull PsiElement element)