Source:
private <T> void processCreatorAnnotation(final ClassModelBuilder<T> classModelBuilder) { Class<T> clazz = classModelBuilder.getType(); CreatorExecutable<T> creatorExecutable = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { if (isPublic(constructor.getModifiers())) { for (Annotation annotation : constructor.getDeclaredAnnotations()) { if (annotation.annotationType().equals(Creator.class)) { creatorExecutable = new CreatorExecutable<T>(clazz, (Constructor<T>) constructor); break; } } } } if (creatorExecutable == null) { for (Method method : clazz.getDeclaredMethods()) { if (isStatic(method.getModifiers())) { for (Annotation annotation : method.getDeclaredAnnotations()) { if (annotation.annotationType().equals(Creator.class)) { creatorExecutable = new CreatorExecutable<T>(clazz, method); break; } } } } } if (creatorExecutable != null) { List<Property> properties = creatorExecutable.getProperties(); List<Class<?>> parameterTypes = creatorExecutable.getParameterTypes(); if (properties.size() != parameterTypes.size()) { throw creatorExecutable.getError("All parameters must be annotated with a @Property"); } for (int i = 0; i < properties.size(); i++) { Property property = properties.get(i); Class<?> parameterType = parameterTypes.get(i); PropertyModelBuilder<?> propertyModelBuilder = classModelBuilder.getProperty(property.value()); if (propertyModelBuilder == null) { throw creatorExecutable.getError(format("Missing Property with the value: '%s'", property.value())); } else if (propertyModelBuilder.getTypeData().getType() != parameterType) { throw creatorExecutable.getError(format("Invalid Property type for '%s'. Expected %s, found %s.", property.value(), propertyModelBuilder.getTypeData().getType(), parameterType)); } } classModelBuilder.instanceCreatorFactory(new InstanceCreatorFactoryImpl<T>(creatorExecutable)); } }

Target:
private <T> void processCreatorAnnotation(final ClassModelBuilder<T> classModelBuilder) { Class<T> clazz = classModelBuilder.getType(); CreatorExecutable<T> creatorExecutable = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { if (isPublic(constructor.getModifiers())) { for (Annotation annotation : constructor.getDeclaredAnnotations()) { if (annotation.annotationType().equals(BsonCreator.class)) { creatorExecutable = new CreatorExecutable<T>(clazz, (Constructor<T>) constructor); break; } } } } for (Method method : clazz.getDeclaredMethods()) { if (isStatic(method.getModifiers())) { for (Annotation annotation : method.getDeclaredAnnotations()) { if (annotation.annotationType().equals(BsonCreator.class)) { if (creatorExecutable != null) { throw new CodecConfigurationException("Found multiple constructors / methods annotated with @BsonCreator"); } else if (!clazz.isAssignableFrom(method.getReturnType())) { throw new CodecConfigurationException( format("Invalid method annotated with @BsonCreator. Returns '%s', expected %s", method.getReturnType(), clazz)); } creatorExecutable = new CreatorExecutable<T>(clazz, method); break; } } } } if (creatorExecutable != null) { List<BsonProperty> properties = creatorExecutable.getProperties(); List<Class<?>> parameterTypes = creatorExecutable.getParameterTypes(); if (properties.size() != parameterTypes.size()) { throw creatorExecutable.getError("All parameters must be annotated with a @Property"); } for (int i = 0; i < properties.size(); i++) { BsonProperty bsonProperty = properties.get(i); Class<?> parameterType = parameterTypes.get(i); PropertyModelBuilder<?> propertyModelBuilder = classModelBuilder.getProperty(bsonProperty.value()); if (propertyModelBuilder == null) { addCreatorPropertyToClassModelBuilder(classModelBuilder, bsonProperty.value(), parameterType); } else if (propertyModelBuilder.getTypeData().getType() != parameterType) { throw creatorExecutable.getError(format("Invalid Property type for '%s'. Expected %s, found %s.", bsonProperty.value(), propertyModelBuilder.getTypeData().getType(), parameterType)); } } classModelBuilder.instanceCreatorFactory(new InstanceCreatorFactoryImpl<T>(creatorExecutable)); } }