use of com.cognifide.apm.core.actions.ParameterDescriptor.NamedParameterDescriptor in project APM by Cognifide.
the class MapperDescriptorFactory method create.
private Optional<MappingDescriptor> create(Mapper mapper, Method method) {
Mapping mapping = method.getAnnotation(Mapping.class);
if (mapping == null) {
return Optional.empty();
}
if (!Action.class.equals(method.getReturnType())) {
throw new InvalidActionMapperException("Mapping method must have return type " + Action.class.getName());
}
List<ParameterDescriptor> parameterDescriptors = Lists.newArrayList();
Type[] types = method.getGenericParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
int requiredIndex = 0;
for (int i = 0; i < types.length; i++) {
Type type = types[i];
Annotation[] parameterAnnotations = annotations[i];
Class<? extends ApmType> apmType = getApmType(type);
ParameterDescriptor parameterDescriptor = null;
if (containsAnnotation(parameterAnnotations, Named.class)) {
Named namedAnnotation = getAnnotation(parameterAnnotations, Named.class);
parameterDescriptor = new NamedParameterDescriptor(apmType, namedAnnotation);
} else if (containsAnnotation(parameterAnnotations, Flags.class)) {
Flags flagsAnnotation = getAnnotation(parameterAnnotations, Flags.class);
parameterDescriptor = new FlagsParameterDescriptor(apmType, flagsAnnotation.value());
} else if (containsAnnotation(parameterAnnotations, Flag.class)) {
Flag flagAnnotation = getAnnotation(parameterAnnotations, Flag.class);
parameterDescriptor = new FlagParameterDescriptor(apmType, flagAnnotation);
} else {
Required requiredAnnotation = getAnnotation(parameterAnnotations, Required.class);
parameterDescriptor = new RequiredParameterDescriptor(apmType, requiredIndex, requiredAnnotation);
requiredIndex++;
}
parameterDescriptors.add(parameterDescriptor);
}
return Optional.of(new MappingDescriptor(method, mapper, mapping, ImmutableList.copyOf(parameterDescriptors)));
}
Aggregations