/** * Method similar to {@link #construct}, 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 aintr, MixInResolver mir) { List<Class<?>> empty = Collections.emptyList(); AnnotatedClass ac = new AnnotatedClass(cls, empty, aintr, mir, null); ac.resolveClassAnnotations(); return ac; }
/** * Helper method for adding any mix-in annotations specified * class might have. */ protected void _addClassMixIns(AnnotationMap annotations, Class<?> toMask) { if (_mixInResolver != null) { _addClassMixIns(annotations, toMask, _mixInResolver.findMixInClassFor(toMask)); } }
for (Constructor<?> ctor : declaredCtors) { if (ctor.getParameterTypes().length == 0) { _defaultConstructor = _constructConstructor(ctor, true); } else { if (includeAll) { _constructors = new ArrayList<AnnotatedConstructor>(Math.max(10, declaredCtors.length)); _constructors.add(_constructConstructor(ctor, false)); _addConstructorMixIns(_primaryMixIn); _creatorMethods = new ArrayList<AnnotatedMethod>(8); _creatorMethods.add(_constructCreatorMethod(m)); _addFactoryMixIns(_primaryMixIn);
_addFields(fields, parent); for (Field f : c.getDeclaredFields()) { if (!_isIncludableField(f)) { continue; fields.put(f.getName(), _constructField(f)); Class<?> mixin = _mixInResolver.findMixInClassFor(c); if (mixin != null) { _addFieldMixIns(parent, mixin, fields);
protected void _addMethodMixIns(Class<?> targetClass, MethodFilter methodFilter, AnnotatedMethodMap methods, Class<?> mixInCls, AnnotatedMethodMap mixIns) { List<Class<?>> parents = new ArrayList<Class<?>>(); parents.add(mixInCls); ClassUtil.findSuperTypes(mixInCls, targetClass, parents); for (Class<?> mixin : parents) { for (Method m : mixin.getDeclaredMethods()) { if (!_isIncludableMethod(m, methodFilter)) { 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(m, am); /* 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)); } } } }
_addMethodMixIns(cls, methodFilter, methods, mixInCls, mixIns); if (!_isIncludableMethod(m, methodFilter)) { continue; AnnotatedMethod newM = _constructMethod(m); methods.add(newM); _addMixOvers(old.getAnnotated(), newM, false); _addMixUnders(m, old);
AnnotatedMethodMap mixins = new AnnotatedMethodMap(); _addMemberMethods(_class, methodFilter, _memberMethods, _primaryMixIn, mixins); _addMemberMethods(cls, methodFilter, _memberMethods, mixin, mixins); Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class); if (mixin != null) { _addMethodMixIns(_class, methodFilter, _memberMethods, mixin, mixins); Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getParameterClasses()); if (m != null) { AnnotatedMethod am = _constructMethod(m); _addMixOvers(mixIn.getAnnotated(), am, false); _memberMethods.add(am);
protected void _addConstructorMixIns(Class<?> mixin) { MemberKey[] ctorKeys = null; int ctorCount = (_constructors == null) ? 0 : _constructors.size(); for (Constructor<?> ctor : mixin.getDeclaredConstructors()) { if (ctor.getParameterTypes().length == 0) { if (_defaultConstructor != null) { _addMixOvers(ctor, _defaultConstructor, false); } } else { if (ctorKeys == null) { ctorKeys = new MemberKey[ctorCount]; for (int i = 0; i < ctorCount; ++i) { ctorKeys[i] = new MemberKey(_constructors.get(i).getAnnotated()); } } MemberKey key = new MemberKey(ctor); for (int i = 0; i < ctorCount; ++i) { if (!key.equals(ctorKeys[i])) { continue; } _addMixOvers(ctor, _constructors.get(i), true); break; } } } }
/** * Method that will collect all member (non-static) fields * that are either public, or have at least a single annotation * associated with them. * * @since 1.9 */ public void resolveFields() { LinkedHashMap<String,AnnotatedField> foundFields = new LinkedHashMap<String,AnnotatedField>(); _addFields(foundFields, _class); if (foundFields.isEmpty()) { _fields = Collections.emptyList(); } else { _fields = new ArrayList<AnnotatedField>(foundFields.size()); _fields.addAll(foundFields.values()); } }
@Override public AnnotatedClass withAnnotations(AnnotationMap ann) { return new AnnotatedClass(_class, _superTypes, _annotationIntrospector, _mixInResolver, ann); }
_addMethodMixIns(cls, methodFilter, methods, mixInCls, mixIns); if (!_isIncludableMethod(m, methodFilter)) { continue; AnnotatedMethod newM = _constructMethod(m); methods.add(newM); _addMixOvers(old.getAnnotated(), newM, false); _addMixUnders(m, old);
_addFields(fields, parent); for (Field f : c.getDeclaredFields()) { if (!_isIncludableField(f)) { continue; fields.put(f.getName(), _constructField(f)); Class<?> mixin = _mixInResolver.findMixInClassFor(c); if (mixin != null) { _addFieldMixIns(parent, mixin, fields);
AnnotatedMethodMap mixins = new AnnotatedMethodMap(); _addMemberMethods(_class, methodFilter, _memberMethods, _primaryMixIn, mixins); _addMemberMethods(cls, methodFilter, _memberMethods, mixin, mixins); Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class); if (mixin != null) { _addMethodMixIns(_class, methodFilter, _memberMethods, mixin, mixins); Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getParameterClasses()); if (m != null) { AnnotatedMethod am = _constructMethod(m); _addMixOvers(mixIn.getAnnotated(), am, false); _memberMethods.add(am);
protected void _addMethodMixIns(Class<?> targetClass, MethodFilter methodFilter, AnnotatedMethodMap methods, Class<?> mixInCls, AnnotatedMethodMap mixIns) { List<Class<?>> parents = new ArrayList<Class<?>>(); parents.add(mixInCls); ClassUtil.findSuperTypes(mixInCls, targetClass, parents); for (Class<?> mixin : parents) { for (Method m : mixin.getDeclaredMethods()) { if (!_isIncludableMethod(m, methodFilter)) { 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(m, am); /* 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)); } } } }
protected void _addFactoryMixIns(Class<?> mixin) { MemberKey[] methodKeys = null; int methodCount = _creatorMethods.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(_creatorMethods.get(i).getAnnotated()); } } MemberKey key = new MemberKey(m); for (int i = 0; i < methodCount; ++i) { if (!key.equals(methodKeys[i])) { continue; } _addMixOvers(m, _creatorMethods.get(i), true); break; } } }
/** * Method that will collect all member (non-static) fields * that are either public, or have at least a single annotation * associated with them. * * @since 1.9 */ public void resolveFields() { LinkedHashMap<String,AnnotatedField> foundFields = new LinkedHashMap<String,AnnotatedField>(); _addFields(foundFields, _class); if (foundFields.isEmpty()) { _fields = Collections.emptyList(); } else { _fields = new ArrayList<AnnotatedField>(foundFields.size()); _fields.addAll(foundFields.values()); } }
@Override public AnnotatedClass withAnnotations(AnnotationMap ann) { return new AnnotatedClass(_class, _superTypes, _annotationIntrospector, _mixInResolver, ann); }
_addMethodMixIns(methodFilter, methods, mixInCls, mixIns); if (!_isIncludableMethod(m, methodFilter)) { continue; AnnotatedMethod newM = _constructMethod(m); methods.add(newM); _addMixOvers(old.getAnnotated(), newM, false); _addMixUnders(m, old);
_addFields(fields, parent); for (Field f : c.getDeclaredFields()) { if (!_isIncludableField(f)) { continue; fields.add(_constructField(f)); Class<?> mixin = _mixInResolver.findMixInClassFor(c); if (mixin != null) { _addFieldMixIns(mixin, fields);
AnnotatedMethodMap mixins = new AnnotatedMethodMap(); _addMemberMethods(_class, methodFilter, _memberMethods, _primaryMixIn, mixins); _addMemberMethods(cls, methodFilter, _memberMethods, mixin, mixins); Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class); if (mixin != null) { _addMethodMixIns(_class, methodFilter, _memberMethods, mixin, mixins); Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getParameterClasses()); if (m != null) { AnnotatedMethod am = _constructMethod(m); _addMixOvers(mixIn.getAnnotated(), am, false); _memberMethods.add(am);