boolean (@NotNull PsiElement element) { if (!element.isValid()) return true; Project project = element.getProject(); ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project); PsiFile file = element.getContainingFile(); if (file == null) return true; VirtualFile vFile = file.getVirtualFile(); Module module = vFile == null ? null : projectFileIndex.getModuleForFile(vFile); // element may be in library return module == null ? !projectFileIndex.isInLibraryClasses(vFile) : module.isDisposed(); }