boolean (@NotNull PsiElement element, @NotNull PsiFile containingFile) { if (element.isPhysical()) return false; if (containingFile.isPhysical()) return true; // non-physical PSI in physical file, suspicious // in normal non-physical files there might also be fake PSI, so let's (expensively!) check we can find it by offset // hopefully in some future we'll prohibit such fake PSI TextRange range = element.getTextRange(); return range == null || PsiTreeUtil.findElementOfClassAtRange(containingFile, range.getStartOffset(), range.getEndOffset(), element.getClass()) != element; }