LanguageLevel () { if (myOriginalFile instanceof PsiJavaFile) { return ((PsiJavaFile)myOriginalFile).getLanguageLevel(); } LanguageLevel forcedLanguageLevel = getUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY); if (forcedLanguageLevel != null) return forcedLanguageLevel; VirtualFile virtualFile = getVirtualFile(); if (virtualFile == null) virtualFile = getViewProvider().getVirtualFile(); String sourceLevel = null; try { CharSequence contents = getViewProvider().getContents(); int lineBound = Strings.indexOf(contents, "\n"); CharSequence line = lineBound > 0 ? contents.subSequence(0, lineBound) : contents; if (Strings.startsWith(line, 0,"#!")) { List<String> params = ParametersListUtil.parse(line.toString()); int srcIdx = params.indexOf("--source"); if (srcIdx > 0 && srcIdx + 1 < params.size()) { sourceLevel = params.get(srcIdx + 1); LanguageLevel sheBangLevel = LanguageLevel.parse(sourceLevel); if (sheBangLevel != null) { return sheBangLevel; } } } } catch (Throwable ignored) { } finally { if (!Objects.equals(sourceLevel, virtualFile.getUserData(SHEBANG_SOURCE_LEVEL)) && virtualFile.isInLocalFileSystem()) { virtualFile.putUserData(SHEBANG_SOURCE_LEVEL, sourceLevel); VirtualFile file = virtualFile; ApplicationManager.getApplication().invokeLater(() -> FileContentUtilCore.reparseFiles(file), ModalityState.nonModal(), ApplicationManager.getApplication().getDisposed()); } } return JavaPsiImplementationHelper.getInstance(getProject()).getEffectiveLanguageLevel(virtualFile); }