Annotations
Every element of the model is Annotated. The difference between annotations and declaredAnnotations is where the search stops, and scala-universe looks further than plain reflection.
findAnnotation
findAnnotation returns the annotation of exactly that type, or null. findDeclaredAnnotation looks only at the element itself.
Where annotations travel
annotations follows the hierarchy for every kind of element. This is independent of Java's @Inherited, which only applies to class annotations of superclasses.
- ResolvedClass
- Its own plus those of every superclass and interface.
- ResolvedMethod
- Its own plus those of every method it overrides.
- ResolvedField
- Its own plus those of the fields it hides.
- ResolvedParameter
- Its own plus those of the same parameter in overridden methods.
- AbstractProperty
- Those of its field, getter and setter together.
Which annotations exist at runtime
Only Java annotations with RetentionPolicy.RUNTIME reach the class file in a form reflection can read. Scala annotations extending StaticAnnotation are invisible here.
A Scala var or val is a field plus accessors. @field, @getter and @setter say which of them carries the annotation; properties find it either way, because they merge field and accessors.