Esempio n. 1
0
 protected void _addClassMixIns(AnnotationMap annotations, Class<?> toMask, Class<?> mixin) {
   if (mixin == null) {
     return;
   }
   // Ok, first: annotations from mix-in class itself:
   for (Annotation a : mixin.getDeclaredAnnotations()) {
     if (_annotationIntrospector.isHandled(a)) {
       annotations.addIfNotPresent(a);
     }
   }
   /* And then from its supertypes, if any. But note that we will
    *  only consider super-types up until reaching the masked
    * class (if found); this because often mix-in class
    * is a sub-class (for convenience reasons). And if so, we
    * absolutely must NOT include super types of masked class,
    * as that would inverse precedence of annotations.
    */
   for (Class<?> parent : ClassUtil.findSuperTypes(mixin, toMask)) {
     for (Annotation a : parent.getDeclaredAnnotations()) {
       if (_annotationIntrospector.isHandled(a)) {
         annotations.addIfNotPresent(a);
       }
     }
   }
 }
Esempio n. 2
0
  /**
   * Initialization method that will recursively collect Jackson annotations for this class and all
   * super classes and interfaces.
   *
   * <p>Starting with 1.2, it will also apply mix-in annotations, as per [JACKSON-76]
   */
  protected void resolveClassAnnotations() {
    _classAnnotations = new AnnotationMap();
    // add mix-in annotations first (overrides)
    if (_primaryMixIn != null) {
      _addClassMixIns(_classAnnotations, _class, _primaryMixIn);
    }
    // first, annotations from the class itself:
    for (Annotation a : _class.getDeclaredAnnotations()) {
      if (_annotationIntrospector.isHandled(a)) {
        _classAnnotations.addIfNotPresent(a);
      }
    }

    // and then from super types
    for (Class<?> cls : _superTypes) {
      // and mix mix-in annotations in-between
      _addClassMixIns(_classAnnotations, cls);
      for (Annotation a : cls.getDeclaredAnnotations()) {
        if (_annotationIntrospector.isHandled(a)) {
          _classAnnotations.addIfNotPresent(a);
        }
      }
    }

    /* and finally... any annotations there might be for plain
     * old Object.class: separate because for all other purposes
     * it is just ignored (not included in super types)
     */
    /* 12-Jul-2009, tatu: Should this be done for interfaces too?
     *   For now, yes, seems useful for some cases, and not harmful
     *   for any?
     */
    _addClassMixIns(_classAnnotations, Object.class);
  }
Esempio n. 3
0
 protected AnnotationMap _collectRelevantAnnotations(Annotation[] anns) {
   AnnotationMap annMap = new AnnotationMap();
   if (anns != null) {
     for (Annotation a : anns) {
       if (_annotationIntrospector.isHandled(a)) {
         annMap.add(a);
       }
     }
   }
   return annMap;
 }
Esempio n. 4
0
 @Override
 public <A extends Annotation> A getAnnotation(Class<A> acls) {
   if (_classAnnotations == null) {
     return null;
   }
   return _classAnnotations.get(acls);
 }
Esempio n. 5
0
 public boolean hasAnnotations() {
   return _classAnnotations.size() > 0;
 }