use of org.mule.metadata.api.model.VoidType in project mule by mulesoft.
the class IntrospectionUtils method getMethodReturnAttributesType.
/**
* Returns a {@link MetadataType} representing the {@link Result#getAttributes()} that will be set after executing the given
* {@code method}.
* <p>
* If the {@code method} returns a {@link Result}, then it returns the type of the {@code Attributes} generic. In any other case
* (including raw uses of {@link Result}) it will return a {@link VoidType}
* <p>
* If the {@code method} returns a collection or a {@link PagingProvider} of {@link Result}, then this will return
* {@link VoidType} since the messages in the main output already contain an attributes for each item.
*
* @param method the {@link Method} being introspected
* @return a {@link MetadataType}
* @throws IllegalArgumentException is method is {@code null}
*/
public static MetadataType getMethodReturnAttributesType(MethodElement method) {
Type returnType = method.getReturnType();
Type attributesType = null;
if (returnType.isAssignableTo(Result.class)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.size() == 2) {
Type genericType = generics.get(1).getConcreteType();
if (genericType != null) {
if (genericType.isAnyType()) {
return typeBuilder().anyType().build();
} else {
attributesType = genericType;
}
} else {
return typeBuilder().anyType().build();
}
} else {
return typeBuilder().anyType().build();
}
}
if (isPagingProvider(returnType)) {
Type second = getPagingProviderTypes(returnType).getSecond();
if (second.isSameType(Result.class)) {
attributesType = null;
}
}
if (isCollection(returnType)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.size() > 0) {
Type genericType = generics.get(0).getConcreteType();
if (genericType.isAssignableTo(Result.class)) {
attributesType = null;
}
}
}
return attributesType != null ? attributesType.asMetadataType() : typeBuilder().voidType().build();
}
Aggregations