Companions and class path
Two helpers around types: the companion object of a Scala class, and an index of annotations over a package.
From a class to its object
companionClass finds the class Name$, companionInstance its MODULE$ instance, checked against the expected type. Both return null when there is none.
json-mapper finds an entity's schema this way: the companion that implements SchemaProvider. Because companionInstance checks the type, a companion of another kind comes back as null instead of failing later.
An annotation index
process loads every class below a package prefix and indexes the annotations on classes, constructors, their parameters, fields and methods. findAnnotation returns each annotation with the element that carries it.
ClassPathResolver is also a CDI extension. Registered in META-INF/services, it collects every type the container discovers and builds the same index after deployment.
findAnnotation throws NoSuchElementException for an annotation that was never indexed. Run process, or let the CDI extension run, before looking anything up.