T1002281 class cast ex

Instead of doing an unsafe cast, an exception is thrown directly (or a conversion if possible).

Second commit contains cleanups.
IIUC, you really need a `RangePosition` there. Why not throw as well on `OffsetPosition`, rather than giving a `RangePosition` which has high chances of being false ( I expect callers will want the word at point) ?