/** * Method called to override a method parameter annotation, * usually due to a mix-in * annotation masking or overriding an annotation 'real' method * has. */ public final void addOrOverrideParam(int paramIndex, Annotation a) { AnnotationMap old = _paramAnnotations[paramIndex]; if (old == null) { old = new AnnotationMap(); _paramAnnotations[paramIndex] = old; } old.add(a); }
/** * Method called to add specified annotation in the Map. */ public void add(Annotation ann) { _add(ann); }
_classAnnotations = new AnnotationMap(); _classAnnotations.addIfNotPresent(a); for (Annotation a : cls.getDeclaredAnnotations()) { if (_annotationIntrospector.isHandled(a)) { _classAnnotations.addIfNotPresent(a);
@Override public <A extends Annotation> A getAnnotation(Class<A> acls) { if (_classAnnotations == null) { return null; } return _classAnnotations.get(acls); }
public boolean hasAnnotations() { return _classAnnotations.size() > 0; }
/** * Method called to augment annotations, by adding specified * annotation if and only if it is not yet present in the * annotation map we have. */ public final void addIfNotPresent(Annotation a) { _annotations.addIfNotPresent(a); }
/** * Method called to override an annotation, usually due to a mix-in * annotation masking or overriding an annotation 'real' constructor * has. */ public void addOrOverride(Annotation a) { _annotations.add(a); }
private AnnotationMap _emptyAnnotationMap() { return new AnnotationMap(); }
private AnnotationMap _mergeAnnotations(int index, Node<? extends AnnotatedMember>... nodes) { AnnotationMap ann = nodes[index].value.getAllAnnotations(); ++index; for (; index < nodes.length; ++index) { if (nodes[index] != null) { return AnnotationMap.merge(ann, _mergeAnnotations(index, nodes)); } } return ann; }
@Override public final <A extends Annotation> A getAnnotation(Class<A> acls) { return _annotations.get(acls); }
public int getAnnotationCount() { return _annotations.size(); }
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); } } } }
/** * Method called to override a class annotation, usually due to a mix-in * annotation masking or overriding an annotation 'real' class */ public final void addOrOverride(Annotation a) { _annotations.add(a); }
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary) { if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) { return secondary; } if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) { return primary; } HashMap<Class<? extends Annotation>,Annotation> annotations = new HashMap<Class<? extends Annotation>,Annotation>(); // add secondary ones first for (Annotation ann : secondary._annotations.values()) { annotations.put(ann.annotationType(), ann); } // to be overridden by primary ones for (Annotation ann : primary._annotations.values()) { annotations.put(ann.annotationType(), ann); } return new AnnotationMap(annotations); }
/** * Fluent factory method that will construct a new instance that uses * annotations from specified {@link Annotated} as fallback annotations * * @since 1.9 */ public final Annotated withFallBackAnnotationsFrom(Annotated annotated) { return withAnnotations(AnnotationMap.merge(getAllAnnotations(), annotated.getAllAnnotations())); }
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; }
_classAnnotations = new AnnotationMap(); _classAnnotations.addIfNotPresent(a); for (Annotation a : cls.getDeclaredAnnotations()) { if (_annotationIntrospector.isHandled(a)) { _classAnnotations.addIfNotPresent(a);
/** * Accessor for annotations; all annotations associated with parameters * are properly passed and accessible. */ @Override public <A extends Annotation> A getAnnotation(Class<A> acls) { return _annotations.get(acls); }
public final int getAnnotationCount() { return _annotations.size(); }
/** * Method called to add specified annotation in the Map, but * only if it didn't yet exist. */ public void addIfNotPresent(Annotation ann) { if (_annotations == null || !_annotations.containsKey(ann.annotationType())) { _add(ann); } }