Extension to ParentElemApi that makes querying for sub-types of the element type easy.
Extension to ParentElemApi that makes querying for sub-types of the element type easy.
The query methods of this trait take a sub-type as first value parameter. It is intentional that this is a value parameter, and not a second type parameter, since it is conceptually the most important parameter of these query methods. (If it were a second type parameter instead, the article http://hacking-scala.org/post/73854628325/advanced-type-constraints-with-type-classes would show how to make that solution robust, using some @NotNothing annotation.)
The sub-type parameter could have been a java.lang.Class
object, except that type erasure would make it less attractive
(when doing pattern matching against that type). Hence the use of a ClassTag
parameter, which undoes type erasure
for non-generic types, if available implicitly. So ClassTag
is used as a better java.lang.Class
, yet without
polluting the public API with an implicit ClassTag
parameter. (Instead, the ClassTag is made implicit inside the
method implementations.)
Default implementation of SubtypeAwareParentElemApi.
Query traits that resemble ParentElemApi and ParentElemLike, but offering query support for object hierarchies.
For example, XML Schema can be modeled with an object hierarchy, starting with some XsdElem super-type which mixes in trait SubtypeAwareParentElemApi, among other query traits. The object hierarchy could contain sub-classes of XsdElem such as XsdRootElem, GlobalElementDeclaration, etc. Then the SubtypeAwareParentElemApi trait makes it easy to query for all or some global element declarations, etc.
There is no magic in these traits: it is just ParentElemApi and ParentElemLike underneath. It is only the syntactic convenience that makes the difference.