In my plugin I have a DocumentListener which I use to record changes happening to documents for later post-processing. I'd like to detect if a given Document is actually a file copy for completion purposes, either from the Document itself or from the VirtualFile. I know I can do this by checking psiFile.originalFile, but if I call PsiDocumentManager.getPsiFile(), then that will cause the PSI to be parsed on every document modification.
Currently I'm calling PsiDocumentManager.getCachedPsiFile(), and if that returns non-null then I use the originalFile check as above, and otherwise I assume the Document is not a completion copy. This seems to work, but I'm unsure if it's a reliable method. Is there a better way to do this?