void (@NotNull ImplementationViewSession session, @Nullable Object context) { PsiFile contextFile = null; if (context instanceof DataContext dataContext) { contextFile = CommonDataKeys.PSI_FILE.getData(dataContext); } if (context instanceof PsiElement psiElement) { contextFile = psiElement.getContainingFile(); } VirtualFile contextVirtualFile = contextFile != null ? contextFile.getVirtualFile() : null; VirtualFile sessionVirtualFile = session.getFile(); if (contextVirtualFile != null && contextVirtualFile.equals(sessionVirtualFile)) { PsiUtilCore.ensureValid(contextFile); } else if (sessionVirtualFile != null && !sessionVirtualFile.isValid()) { throw new InvalidVirtualFileAccessException(sessionVirtualFile); } }