Add DOM.asOld(Element) to avoid NPEs

Calling cast() to convert a dom.Element into a user.Element can
introduce a NullPointerException when null elements are allowed.  To
remedy this and make the type safety slightly stronger, add a
DOM.asOld() helper method to cast from dom.Element to user.Element,
and replace as many calls to cast() with it as possible.

Rather than try to be clever and only convert cast()s where it would
actually make a difference, I adopted a strict rule of just converting
as many as possible.  In particular, this reverts all calls to cast()
that were introduced by d91ce52a.

Change-Id: I8c7a05be0c70d544006ae7f6356f7a05027fa1f3
13 files changed