Object (@Nullable RefEntity entity) { if (entity instanceof RefElement) { SmartPsiElementPointer<?> pointer = ((RefElement)entity).getPointer(); if (pointer != null) { VirtualFile file = pointer.getVirtualFile(); if (file != null) { return file; } } } return entity; }