PsiFileImpl (FileElement treeElementClone) { PsiFileImpl clone = (PsiFileImpl)super.clone(); clone.setTreeElementPointer(treeElementClone); // should not use setTreeElement here because cloned file still have VirtualFile (SCR17963) treeElementClone.setPsi(clone); return clone; }