Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package com.fasterxml.jackson.databind.introspect;
   
   import java.lang.reflect.*;
   import java.util.*;
   
  
  public final class AnnotatedClass
      extends Annotated
  {
      private final static AnnotationMap[] NO_ANNOTATION_MAPS = new AnnotationMap[0];
      
      /*
      /**********************************************************
      /* Configuration
      /**********************************************************
       */

    
Class for which annotations apply, and that owns other components (constructors, methods)
  
      final protected Class<?> _class;

    
Ordered set of super classes and interfaces of the class itself: included in order of precedence
  
      final protected List<Class<?>> _superTypes;

    
Filter used to determine which annotations to gather; used to optimize things so that unnecessary annotations are ignored.
  
      final protected AnnotationIntrospector _annotationIntrospector;

    
Object that knows mapping of mix-in classes (ones that contain annotations to add) with their target classes (ones that get these additional annotations "mixed in").
  
      final protected MixInResolver _mixInResolver;

    
Primary mix-in class; one to use for the annotated class itself. Can be null.
  
      final protected Class<?> _primaryMixIn;
  
      /*
      /**********************************************************
      /* Gathered information
      /**********************************************************
       */

    
Combined list of Jackson annotations that the class has, including inheritable ones from super classes and interfaces
  
      protected AnnotationMap _classAnnotations;

    
Flag to indicate whether creator information has been resolved or not.
  
      protected boolean _creatorsResolved = false;
    
    
Default constructor of the annotated class, if it has one.
  
      protected AnnotatedConstructor _defaultConstructor;

    
Single argument constructors the class has, if any.
  
      protected List<AnnotatedConstructor_constructors;

    
Single argument static methods that might be usable as factory methods
  
      protected List<AnnotatedMethod_creatorMethods;

    
Member methods of interest; for now ones with 0 or 1 arguments (just optimization, since others won't be used now)
  
      protected AnnotatedMethodMap  _memberMethods;

    
Member fields of interest: ones that are either public, or have at least one annotation.
  
      protected List<AnnotatedField_fields;
     
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */

    
Constructor will not do any initializations, to allow for configuring instances differently depending on use cases
 
     private AnnotatedClass(Class<?> clsList<Class<?>> superTypes,
             AnnotationIntrospector aintrMixInResolver mir,
             AnnotationMap classAnnotations)
     {
          = cls;
          = superTypes;
          = aintr;
          = mir;
          = ( == null) ? null
             : .findMixInClassFor();
          = classAnnotations;
     }
 
     @Override
     public AnnotatedClass withAnnotations(AnnotationMap ann) {
         return new AnnotatedClass(,
                 ann);
     }
    
    
Factory method that instantiates an instance. Returned instance will only be initialized with class annotations, but not with any method information.
 
     public static AnnotatedClass construct(Class<?> cls,
             AnnotationIntrospector aintrMixInResolver mir)
     {
         return new AnnotatedClass(cls,
                 ClassUtil.findSuperTypes(clsnull), aintrmirnull);
     }

    
Method similar to construct(java.lang.Class,com.fasterxml.jackson.databind.AnnotationIntrospector,com.fasterxml.jackson.databind.introspect.ClassIntrospector.MixInResolver), but that will NOT include information from supertypes; only class itself and any direct mix-ins it may have.
 
     public static AnnotatedClass constructWithoutSuperTypes(Class<?> cls,
             AnnotationIntrospector aintrMixInResolver mir)
     {
         return new AnnotatedClass(cls,
                 Collections.<Class<?>>emptyList(), aintrmirnull);
     }
     
     /*
     /**********************************************************
     /* Annotated impl 
     /**********************************************************
      */
 
     @Override
     public Class<?> getAnnotated() { return ; }
 
     @Override
     public int getModifiers() { return .getModifiers(); }
 
     @Override
     public String getName() { return .getName(); }
 
     @Override
     public <A extends Annotation> A getAnnotation(Class<A> acls)
     {
         if ( == null) {
             resolveClassAnnotations();
         }
         return .get(acls);
     }
 
     @Override
     public Type getGenericType() {
         return ;
     }
 
     @Override
     public Class<?> getRawType() {
         return ;
     }
 
     @Override
     protected AnnotationMap getAllAnnotations() {
         if ( == null) {
             resolveClassAnnotations();
         }
         return ;
     }
     
     /*
     /**********************************************************
     /* Public API, generic accessors
     /**********************************************************
      */
 
     public Annotations getAnnotations() {
         if ( == null) {
             resolveClassAnnotations();
         }
         return ;
     }
     
     public boolean hasAnnotations() {
         if ( == null) {
             resolveClassAnnotations();
         }
         return .size() > 0;
     }
 
     {
         if (!) {
             resolveCreators();
         }
         return ;
     }
 
     {
         if (!) {
             resolveCreators();
         }
         return ;
     }
 
     {
         if (!) {
             resolveCreators();
         }
         return ;
     }
 
     {
         if ( == null) {
             resolveMemberMethods();
         }
         return ;
     }
 
     public int getMemberMethodCount()
     {
         if ( == null) {
             resolveMemberMethods();
         }
         return .size();
     }
 
     public AnnotatedMethod findMethod(String nameClass<?>[] paramTypes)
     {
         if ( == null) {
             resolveMemberMethods();
         }
         return .find(nameparamTypes);
     }
 
     public int getFieldCount() {
         if ( == null) {
             resolveFields();
         }
         return .size();
     }
 
     public Iterable<AnnotatedFieldfields()
     {
         if ( == null) {
             resolveFields();
         }
         return ;
     }
 
     /*
     /**********************************************************
     /* Public API, main-level resolution methods
     /**********************************************************
      */

    
Initialization method that will recursively collect Jackson annotations for this class and all super classes and interfaces.
 
     private void resolveClassAnnotations()
     {
          = new AnnotationMap();
         // [JACKSON-659] Should skip processing if annotation processing disabled
         if ( != null) {
             // add mix-in annotations first (overrides)
             if ( != null) {
                 _addClassMixIns();
             }
             // first, annotations from the class itself:
     
             // and then from super types
             for (Class<?> cls : ) {
                 // and mix mix-in annotations in-between
                 _addClassMixIns(cls);
                 _addAnnotationsIfNotPresent(cls.getDeclaredAnnotations());
             }
             /* 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(Object.class);
         }
     }
    
    
Initialization method that will find out all constructors and potential static factory methods the class has.
 
     private void resolveCreators()
     {
         // Then see which constructors we have
         List<AnnotatedConstructorconstructors = null;
         Constructor<?>[] declaredCtors = .getDeclaredConstructors();
         for (Constructor<?> ctor : declaredCtors) {
             if (ctor.getParameterTypes().length == 0) {
                  = _constructConstructor(ctortrue);
             } else {
                 if (constructors == null) {
                     constructors = new ArrayList<AnnotatedConstructor>(Math.max(10, declaredCtors.length));
                 }
                 constructors.add(_constructConstructor(ctorfalse));
             }
         }
         if (constructors == null) {
              = Collections.emptyList();
         } else {
              = constructors;
         }
         // and if need be, augment with mix-ins
         if ( != null) {
             if ( != null || !.isEmpty()) {
                 _addConstructorMixIns();
             }
         }
 
 
         /* And then... let's remove all constructors that are deemed
          * ignorable after all annotations have been properly collapsed.
          */
         // 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
         if ( != null) {
             if ( != null) {
                 if (.hasIgnoreMarker()) {
                      = null;
                 }
             }
             if ( != null) {
                 // count down to allow safe removal
                 for (int i = .size(); --i >= 0; ) {
                     if (.hasIgnoreMarker(.get(i))) {
                         .remove(i);
                     }
                 }
             }
         }
         List<AnnotatedMethodcreatorMethods = null;
         
         // Then static methods which are potential factory methods
         for (Method m : .getDeclaredMethods()) {
             if (!Modifier.isStatic(m.getModifiers())) {
                 continue;
             }
             // all factory methods are fine, as per [JACKSON-850]
             //int argCount = m.getParameterTypes().length;
             if (creatorMethods == null) {
                 creatorMethods = new ArrayList<AnnotatedMethod>(8);
             }
             creatorMethods.add(_constructCreatorMethod(m));
         }
         if (creatorMethods == null) {
              = Collections.emptyList();
         } else {
              = creatorMethods;
             // mix-ins to mix in?
             if ( != null) {
                 _addFactoryMixIns();
             }
             // anything to ignore at this point?
             if ( != null) {
                 // count down to allow safe removal
                 for (int i = .size(); --i >= 0; ) {
                     if (.hasIgnoreMarker(.get(i))) {
                         .remove(i);
                     }
                 }
             }
         }
          = true;
     }
    
    
Method for resolving member method information: aggregating all non-static methods and combining annotations (to implement method-annotation inheritance)

Parameters:
methodFilter Filter used to determine which methods to include
 
     private void resolveMemberMethods()
     {
          = new AnnotatedMethodMap();
         AnnotatedMethodMap mixins = new AnnotatedMethodMap();
         // first: methods from the class itself
         _addMemberMethods(mixins);
 
         // and then augment these with annotations from super-types:
         for (Class<?> cls : ) {
             Class<?> mixin = ( == null) ? null : .findMixInClassFor(cls);         
             _addMemberMethods(clsmixinmixins);
         }
         // Special case: mix-ins for Object.class? (to apply to ALL classes)
         if ( != null) {
             Class<?> mixin = .findMixInClassFor(Object.class);
             if (mixin != null) {
                 _addMethodMixIns(mixinmixins);
             }
         }
 
         /* Any unmatched mix-ins? Most likely error cases (not matching
          * any method); but there is one possible real use case:
          * exposing Object#hashCode (alas, Object#getClass can NOT be
          * exposed, see [JACKSON-140])
          */
         // 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
         if ( != null) {
             if (!mixins.isEmpty()) {
                 Iterator<AnnotatedMethodit = mixins.iterator();
                 while (it.hasNext()) {
                     AnnotatedMethod mixIn = it.next();
                     try {
                         Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getRawParameterTypes());
                         if (m != null) {
                             AnnotatedMethod am = _constructMethod(m);
                             _addMixOvers(mixIn.getAnnotated(), amfalse);
                             .add(am);
                         }
                     } catch (Exception e) { }
                 }
             }
         }
     }
    
    
Method that will collect all member (non-static) fields that are either public, or have at least a single annotation associated with them.
 
     private void resolveFields()
     {
         Map<String,AnnotatedFieldfoundFields = _findFields(null);
         if (foundFields == null || foundFields.size() == 0) {
              = Collections.emptyList();
         } else {
              = new ArrayList<AnnotatedField>(foundFields.size());
             .addAll(foundFields.values());
         }
     }
     
     /*
     /**********************************************************
     /* Helper methods for resolving class annotations
     /* (resolution consisting of inheritance, overrides,
     /* and injection of mix-ins as necessary)
     /**********************************************************
      */
    
    
Helper method for adding any mix-in annotations specified class might have.
 
     protected void _addClassMixIns(AnnotationMap annotationsClass<?> toMask)
     {
         if ( != null) {
             _addClassMixIns(annotationstoMask.findMixInClassFor(toMask));
         }
     }
 
     protected void _addClassMixIns(AnnotationMap annotationsClass<?> toMask,
                                    Class<?> mixin)
     {
         if (mixin == null) {
             return;
         }
         // Ok, first: annotations from mix-in class itself:
         _addAnnotationsIfNotPresent(annotationsmixin.getDeclaredAnnotations());
 
         /* 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(mixintoMask)) {
             _addAnnotationsIfNotPresent(annotationsparent.getDeclaredAnnotations());
         }
     }
 
     /*
     /**********************************************************
     /* Helper methods for populating creator (ctor, factory) information
     /**********************************************************
      */
 
     protected void _addConstructorMixIns(Class<?> mixin)
     {
         MemberKey[] ctorKeys = null;
         int ctorCount = ( == null) ? 0 : .size();
         for (Constructor<?> ctor : mixin.getDeclaredConstructors()) {
             if (ctor.getParameterTypes().length == 0) {
                 if ( != null) {
                     _addMixOvers(ctorfalse);
                 }
             } else {
                 if (ctorKeys == null) {
                     ctorKeys = new MemberKey[ctorCount];
                     for (int i = 0; i < ctorCount; ++i) {
                         ctorKeys[i] = new MemberKey(.get(i).getAnnotated());
                     }
                 }
                 MemberKey key = new MemberKey(ctor);
 
                 for (int i = 0; i < ctorCount; ++i) {
                     if (!key.equals(ctorKeys[i])) {
                         continue;
                     }
                     _addMixOvers(ctor.get(i), true);
                     break;
                 }
             }
         }
     }
 
     protected void _addFactoryMixIns(Class<?> mixin)
     {
         MemberKey[] methodKeys = null;
         int methodCount = .size();
 
         for (Method m : mixin.getDeclaredMethods()) {
             if (!Modifier.isStatic(m.getModifiers())) {
                 continue;
             }
             if (m.getParameterTypes().length == 0) {
                 continue;
             }
             if (methodKeys == null) {
                 methodKeys = new MemberKey[methodCount];
                 for (int i = 0; i < methodCount; ++i) {
                     methodKeys[i] = new MemberKey(.get(i).getAnnotated());
                 }
             }
             MemberKey key = new MemberKey(m);
             for (int i = 0; i < methodCount; ++i) {
                 if (!key.equals(methodKeys[i])) {
                     continue;
                 }
                 _addMixOvers(m.get(i), true);
                 break;
             }
         }
     }
 
     /*
     /**********************************************************
     /* Helper methods for populating method information
     /**********************************************************
      */
 
     protected void _addMemberMethods(Class<?> clsAnnotatedMethodMap methods,
             Class<?> mixInClsAnnotatedMethodMap mixIns)
     {
         // first, mixIns, since they have higher priority then class methods
         if (mixInCls != null) {
             _addMethodMixIns(clsmethodsmixInClsmixIns);
         }        
         if (cls == null) { // just so caller need not check when passing super-class
             return;
         }
 
         // then methods from the class itself
         for (Method m : cls.getDeclaredMethods()) {
             if (!_isIncludableMemberMethod(m)) {
                 continue;
             }
             AnnotatedMethod old = methods.find(m);
             if (old == null) {
                 AnnotatedMethod newM = _constructMethod(m);
                 methods.add(newM);
                 // Ok, but is there a mix-in to connect now?
                 old = mixIns.remove(m);
                 if (old != null) {
                     _addMixOvers(old.getAnnotated(), newMfalse);
                 }
             } else {
                 /* If sub-class already has the method, we only want to augment
                  * annotations with entries that are not masked by sub-class.
                  */
                 _addMixUnders(mold);
 
                 /* 06-Jan-2010, tatu: [JACKSON-450] Except that if method we saw first is
                  *   from an interface, and we now find a non-interface definition, we should
                  *   use this method, but with combination of annotations.
                  *   This helps (or rather, is essential) with JAXB annotations and
                  *   may also result in faster method calls (interface calls are slightly
                  *   costlier than regular method calls)
                  */
                 if (old.getDeclaringClass().isInterface() && !m.getDeclaringClass().isInterface()) {
                     methods.add(old.withMethod(m));
                 }
             }
         }
     }
 
     protected void _addMethodMixIns(Class<?> targetClassAnnotatedMethodMap methods,
             Class<?> mixInClsAnnotatedMethodMap mixIns)
     {
         List<Class<?>> parents = new ArrayList<Class<?>>();
         parents.add(mixInCls);
         ClassUtil.findSuperTypes(mixInClstargetClassparents);
         for (Class<?> mixin : parents) {
             for (Method m : mixin.getDeclaredMethods()) {
                 if (!_isIncludableMemberMethod(m)) {
                     continue;
                 }
                 AnnotatedMethod am = methods.find(m);
                 /* Do we already have a method to augment (from sub-class
                  * that will mask this mixIn)? If so, add if visible
                  * without masking (no such annotation)
                  */
                 if (am != null) {
                     _addMixUnders(mam);
                     /* Otherwise will have precedence, but must wait
                      * until we find the real method (mixIn methods are
                      * just placeholder, can't be called)
                      */
                 } else {
                     mixIns.add(_constructMethod(m));
                 }
             }
         }
     }
 
     /*
     /**********************************************************
     /* Helper methods for populating field information
     /**********************************************************
      */
 
     protected Map<String,AnnotatedField_findFields(Class<?> cMap<String,AnnotatedFieldfields)
     {
         /* First, a quick test: we only care for regular classes (not
          * interfaces, primitive types etc), except for Object.class.
          * A simple check to rule out other cases is to see if there
          * is a super class or not.
          */
         Class<?> parent = c.getSuperclass();
         if (parent != null) {
             // Let's add super-class' fields first, then ours.
             /* 21-Feb-2010, tatu: Need to handle masking: as per [JACKSON-226]
              *    we otherwise get into trouble...
              */
             fields = _findFields(parentfields);
             for (Field f : c.getDeclaredFields()) {
                 // static fields not included, nor transient
                 if (!_isIncludableField(f)) {
                     continue;
                 }
                 /* Ok now: we can (and need) not filter out ignorable fields
                  * at this point; partly because mix-ins haven't been
                  * added, and partly because logic can be done when
                  * determining get/settability of the field.
                  */
                 if (fields == null) {
                     fields = new LinkedHashMap<String,AnnotatedField>();
                 }
                 fields.put(f.getName(), _constructField(f));
             }
             // And then... any mix-in overrides?
             if ( != null) {
                 Class<?> mixin = .findMixInClassFor(c);
                 if (mixin != null) {
                     _addFieldMixIns(parentmixinfields);
                 }
             }
         }
         return fields;
     }

    
Method called to add field mix-ins from given mix-in class (and its fields) into already collected actual fields (from introspected classes and their super-classes)
 
     protected void _addFieldMixIns(Class<?> targetClassClass<?> mixInCls,
             Map<String,AnnotatedFieldfields)
     {
         List<Class<?>> parents = new ArrayList<Class<?>>();
         parents.add(mixInCls);
         ClassUtil.findSuperTypes(mixInClstargetClassparents);
         for (Class<?> mixin : parents) {
             for (Field mixinField : mixin.getDeclaredFields()) {
                 // there are some dummy things (static, synthetic); better ignore
                 if (!_isIncludableField(mixinField)) {
                     continue;
                 }
                 String name = mixinField.getName();
                 // anything to mask? (if not, quietly ignore)
                 AnnotatedField maskedField = fields.get(name);
                 if (maskedField != null) {
                     _addOrOverrideAnnotations(maskedFieldmixinField.getDeclaredAnnotations());
                 }
             }
         }
     }
 
     /*
     /**********************************************************
     /* Helper methods, constructing value types
     /**********************************************************
      */
 
     protected AnnotatedMethod _constructMethod(Method m)
     {
         /* note: parameter annotations not used for regular (getter, setter)
          * methods; only for creator methods (static factory methods)
          * -- at least not yet!
          */
         if ( == null) { // when annotation processing is disabled
             return new AnnotatedMethod(m_emptyAnnotationMap(), null);
         }
         return new AnnotatedMethod(m_collectRelevantAnnotations(m.getDeclaredAnnotations()), null);
     }
 
     protected AnnotatedConstructor _constructConstructor(Constructor<?> ctorboolean defaultCtor)
     {
         if ( == null) { // when annotation processing is disabled
             return new AnnotatedConstructor(ctor_emptyAnnotationMap(), _emptyAnnotationMaps(ctor.getParameterTypes().length));
         }
         if (defaultCtor) {
             return new AnnotatedConstructor(ctor_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), null);
         }
         Annotation[][] paramAnns = ctor.getParameterAnnotations();
         int paramCount = ctor.getParameterTypes().length;
         /* [JACKSON-701]: Looks like JDK has discrepancy, whereas annotations for implicit 'this'
          * (for non-static inner classes) are NOT included, but type is? Strange, sounds like
          * a bug. Alas, we can't really fix that...
          */
         // Also: [JACKSON-757] (enum value constructors)
         AnnotationMap[] resolvedAnnotations = null;
         if (paramCount != paramAnns.length) {
             // Limits of the work-around (to avoid hiding real errors):
             // first, only applicable for member classes and then either:
 
             Class<?> dc = ctor.getDeclaringClass();
             // (a) is enum, which have two extra hidden params (name, index)
             if (dc.isEnum() && (paramCount == paramAnns.length + 2)) {
                 Annotation[][] old = paramAnns;
                 paramAnns = new Annotation[old.length+2][];
                 System.arraycopy(old, 0, paramAnns, 2, old.length);
                 resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
             } else if (dc.isMemberClass()) {
                 // (b) non-static inner classes, get implicit 'this' for parameter, not  annotation
                 if (paramCount == (paramAnns.length + 1)) {
                     // hack attack: prepend a null entry to make things match
                     Annotation[][] old = paramAnns;
                     paramAnns = new Annotation[old.length+1][];
                     System.arraycopy(old, 0, paramAnns, 1, old.length);
                     resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
                 }
             }
             if (resolvedAnnotations == null) {
                 throw new IllegalStateException("Internal error: constructor for "+ctor.getDeclaringClass().getName()
                         +" has mismatch: "+paramCount+" parameters; "+paramAnns.length+" sets of annotations");
             }
         } else {
             resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
         }
         return new AnnotatedConstructor(ctor_collectRelevantAnnotations(ctor.getDeclaredAnnotations()),
                 resolvedAnnotations);
     }
 
     {
         if ( == null) { // when annotation processing is disabled
             return new AnnotatedMethod(m_emptyAnnotationMap(), _emptyAnnotationMaps(m.getParameterTypes().length));
         }
                                    _collectRelevantAnnotations(m.getParameterAnnotations()));
     }
 
     protected AnnotatedField _constructField(Field f)
     {
         if ( == null) { // when annotation processing is disabled
             return new AnnotatedField(f_emptyAnnotationMap());
         }
         return new AnnotatedField(f_collectRelevantAnnotations(f.getDeclaredAnnotations()));
     }
  
     private AnnotationMap _emptyAnnotationMap() {
         return new AnnotationMap();
     }
 
     private AnnotationMap[] _emptyAnnotationMaps(int count) {
         if (count == 0) {
             return ;
         }
         AnnotationMap[] maps = new AnnotationMap[count];
         for (int i = 0; i < count; ++i) {
             maps[i] = _emptyAnnotationMap();
         }
         return maps;
     }
     
     /*
     /**********************************************************
     /* Helper methods, inclusion filtering
     /**********************************************************
      */
 
     protected boolean _isIncludableMemberMethod(Method m)
     {
         if (Modifier.isStatic(m.getModifiers())) {
             return false;
         }
         /* 07-Apr-2009, tatu: Looks like generics can introduce hidden
          *   bridge and/or synthetic methods. I don't think we want to
          *   consider those...
          */
         if (m.isSynthetic() || m.isBridge()) {
             return false;
         }
         // also, for now we have no use for methods with 2 or more arguments:
         int pcount = m.getParameterTypes().length;
         return (pcount <= 2);
     }
 
     private boolean _isIncludableField(Field f)
     {
         /* I'm pretty sure synthetic fields are to be skipped...
          * (methods definitely are)
          */
         if (f.isSynthetic()) {
             return false;
         }
         // Static fields are never included, nor transient
         int mods = f.getModifiers();
         if (Modifier.isStatic(mods) || Modifier.isTransient(mods)) {
             return false;
         }
         return true;
     }
 
     /*
     /**********************************************************
     /* Helper methods, attaching annotations
     /**********************************************************
      */
 
     protected AnnotationMap[] _collectRelevantAnnotations(Annotation[][] anns)
     {
         int len = anns.length;
         AnnotationMap[] result = new AnnotationMap[len];
         for (int i = 0; i < len; ++i) {
             result[i] = _collectRelevantAnnotations(anns[i]);
         }
         return result;
     }
 
     {
         AnnotationMap annMap = new AnnotationMap();
         _addAnnotationsIfNotPresent(annMapanns);
         return annMap;
     }
     
     /* Helper method used to add all applicable annotations from given set.
      * Takes into account possible "annotation bundles" (meta-annotations to
      * include instead of main-level annotation)
      */
     private void _addAnnotationsIfNotPresent(AnnotationMap resultAnnotation[] anns)
     {
         if (anns != null) {
             List<Annotation[]> bundles = null;
             for (Annotation ann : anns) { // first: direct annotations
                 if (_isAnnotationBundle(ann)) {
                     if (bundles == null) {
                         bundles = new LinkedList<Annotation[]>();
                     }
                     bundles.add(ann.annotationType().getDeclaredAnnotations());
                 } else { // note: we will NOT filter out non-Jackson anns any more
                     result.addIfNotPresent(ann);
                 }
             }
             if (bundles != null) { // and secondarily handle bundles, if any found: precedence important
                 for (Annotation[] annotations : bundles) {
                     _addAnnotationsIfNotPresent(resultannotations);
                 }
             }
         }
     }
 
     private void _addAnnotationsIfNotPresent(AnnotatedMember targetAnnotation[] anns)
     {
         if (anns != null) {
             List<Annotation[]> bundles = null;
             for (Annotation ann : anns) { // first: direct annotations
                 if (_isAnnotationBundle(ann)) {
                     if (bundles == null) {
                         bundles = new LinkedList<Annotation[]>();
                     }
                     bundles.add(ann.annotationType().getDeclaredAnnotations());
                 } else { // note: we will NOT filter out non-Jackson anns any more
                     target.addIfNotPresent(ann);
                 }
             }
             if (bundles != null) { // and secondarily handle bundles, if any found: precedence important
                 for (Annotation[] annotations : bundles) {
                     _addAnnotationsIfNotPresent(targetannotations);
                 }
             }
         }
     }
     
     private void _addOrOverrideAnnotations(AnnotatedMember targetAnnotation[] anns)
     {
         if (anns != null) {
             List<Annotation[]> bundles = null;
             for (Annotation ann : anns) { // first: direct annotations
                 if (_isAnnotationBundle(ann)) {
                     if (bundles == null) {
                         bundles = new LinkedList<Annotation[]>();
                     }
                     bundles.add(ann.annotationType().getDeclaredAnnotations());
                 } else { // note: no filtering by jackson-annotations
                     target.addOrOverride(ann);
                 }
             }
             if (bundles != null) { // and then bundles, if any: important for precedence
                 for (Annotation[] annotations : bundles) {
                     _addOrOverrideAnnotations(targetannotations);
                 }
             }
         }
     }
    
    

Parameters:
addParamAnnotations Whether parameter annotations are to be added as well
 
     protected void _addMixOvers(Constructor<?> mixinAnnotatedConstructor target,
             boolean addParamAnnotations)
     {
         _addOrOverrideAnnotations(targetmixin.getDeclaredAnnotations());
         if (addParamAnnotations) {
             Annotation[][] pa = mixin.getParameterAnnotations();
             for (int i = 0, len = pa.lengthi < len; ++i) {
                 for (Annotation a : pa[i]) {
                     target.addOrOverrideParam(ia);
                 }
             }
         }
     }

    

Parameters:
addParamAnnotations Whether parameter annotations are to be added as well
 
     protected void _addMixOvers(Method mixinAnnotatedMethod target,
             boolean addParamAnnotations)
     {
         _addOrOverrideAnnotations(targetmixin.getDeclaredAnnotations());
         if (addParamAnnotations) {
             Annotation[][] pa = mixin.getParameterAnnotations();
             for (int i = 0, len = pa.lengthi < len; ++i) {
                 for (Annotation a : pa[i]) {
                     target.addOrOverrideParam(ia);
                 }
             }
         }
     }

    
Method that will add annotations from specified source method to target method, but only if target does not yet have them.
 
     protected void _addMixUnders(Method srcAnnotatedMethod target) {
         _addAnnotationsIfNotPresent(targetsrc.getDeclaredAnnotations());
    }
   private final boolean _isAnnotationBundle(Annotation ann)
   {
       return ( != null) && .isAnnotationBundle(ann);
   }
   
    /*
    /**********************************************************
    /* Other methods
    /**********************************************************
     */
    @Override
    public String toString()
    {
        return "[AnnotedClass "+.getName()+"]";
    }
New to GrepCode? Check out our FAQ X