PsiFile (@NotNull PsiFile file) { if (file.isValid()) return file; VirtualFile virtualFile = file.getVirtualFile(); if (!virtualFile.isValid()) return null; FileViewProvider provider = file.getManager().findViewProvider(virtualFile); if (provider == null) return null; Language language = file.getLanguage(); return provider.hasLanguage(language) ? provider.getPsi(language) : provider.getPsi(provider.getBaseLanguage()); }