Constructor constructor = (Constructor) accessibleObject;
methodAnnotations = constructor.getParameterAnnotations();
parameterNames = paranamer.lookupParameterNames(constructor);
parameterTargetTypes = constructor.getParameterTypes();
} else {
throw new ConstrettoException("Could not resolve parameter names ");
}
Object[] resolvedArguments = new Object[methodAnnotations.length];
int i = 0;
for (Annotation[] parameterAnnotations : methodAnnotations) {
Object defaultValue = null;
boolean required = true;
String expression = "";
Class<?> parameterTargetClass = parameterTargetTypes[i];
if (parameterAnnotations.length != 0) {
for (Annotation parameterAnnotation : parameterAnnotations) {
if (parameterAnnotation.annotationType() == Configuration.class) {
Configuration configurationAnnotation = (Configuration) parameterAnnotation;
expression = configurationAnnotation.value();
required = configurationAnnotation.required();
if (hasAnnotationDefaults(configurationAnnotation)) {
if (configurationAnnotation.defaultValueFactory().equals(Configuration.EmptyValueFactory.class)) {
defaultValue = ValueConverterRegistry.convert(parameterTargetClass, parameterTargetClass, new CPrimitive(configurationAnnotation.defaultValue()));
} else {
ConfigurationDefaultValueFactory valueFactory = configurationAnnotation.defaultValueFactory().newInstance();
defaultValue = valueFactory.getDefaultValue();
}
}
}
}
}
if (expression.equals("")) {
if (parameterNames == null) {
throw new ConstrettoException("Could not resolve the expression of the property to look up. " +
"The cause of this could be that the class is compiled without debug enabled. " +
"when a class is compiled without debug, the @Configuration with a value attribute is required " +
"to correctly resolve the property expression.");
} else {
expression = parameterNames[i];
}
}
if (hasValue(expression)) {
if (parameterTargetClass.isAssignableFrom(List.class)) {
Class<?> collectionParameterType = getCollectionParameterType(createMethodParameter(accessibleObject, i));
resolvedArguments[i] = evaluateToList(collectionParameterType, expression);
} else if (parameterTargetClass.isAssignableFrom(Map.class)) {
Class<?> mapKeyType = getMapKeyParameterType(createMethodParameter(accessibleObject, i));
Class<?> mapValueType = getMapValueParameterType(createMethodParameter(accessibleObject, i));
resolvedArguments[i] = evaluateToMap(mapKeyType, mapValueType, expression);
} else {
resolvedArguments[i] = processAndConvert(parameterTargetClass, expression);
}
} else {
if (defaultValue != null || !required) {
resolvedArguments[i] = defaultValue;
} else {
if(accessibleObject instanceof Constructor) {
Constructor constructor = (Constructor) accessibleObject;
throw new ConstrettoException("Missing value or default value for expression [" + expression + "], in annotated constructor in class [" + constructor.getClass().getName() + "], with tags " + currentTags + ".");
}
else {
Method method = (Method) accessibleObject;
throw new ConstrettoException("Missing value or default value for expression [" + expression + "], in method [" + method.getName() + "], in class [" + method.getClass().getName() + "], with tags " + currentTags + ".");
}
}
}