LanguageLevel (@NotNull PsiElement element) { if (element instanceof PsiDirectory) { return JavaDirectoryService.getInstance().getLanguageLevel((PsiDirectory)element); } PsiFile file = element.getContainingFile(); 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; }