use of org.mule.metadata.api.model.AnyType in project mule by mulesoft.
the class IntrospectionUtils method getReturnType.
private static MetadataType getReturnType(Type returnType) {
Type type = returnType;
if (returnType.isAssignableTo(Result.class)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.isEmpty()) {
return typeBuilder().anyType().build();
}
Type payloadType = generics.get(0).getConcreteType();
if (!payloadType.isAnyType()) {
type = payloadType;
} else {
type = null;
}
}
if (isPagingProvider(returnType)) {
Type itemType = getPagingProviderTypes(returnType).getSecond();
if (itemType.isSameType(Result.class)) {
return returnListOfMessagesType(returnType, itemType);
} else {
return typeBuilder().arrayType().of(itemType.asMetadataType()).with(returnType.getClassInformation()).build();
}
}
if (returnType.isAssignableTo(ParameterResolver.class) || returnType.isAssignableTo(TypedValue.class) || returnType.isAssignableTo(Literal.class)) {
type = returnType.getGenerics().get(0).getConcreteType();
}
if (isCollection(returnType) && !returnType.getGenerics().isEmpty()) {
Type itemType = returnType.getGenerics().get(0).getConcreteType();
if (itemType.isAssignableTo(Result.class)) {
return returnListOfMessagesType(returnType, itemType);
}
}
return type != null ? type.asMetadataType() : typeBuilder().anyType().build();
}
use of org.mule.metadata.api.model.AnyType 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();
}
use of org.mule.metadata.api.model.AnyType in project mule by mulesoft.
the class IntrospectionUtils method returnListOfMessagesType.
private static MetadataType returnListOfMessagesType(Type returnType, Type resultType) {
if (resultType.getGenerics().isEmpty()) {
AnyType anyType = typeBuilder().anyType().build();
return getListOfMessageType(returnType, anyType, anyType);
} else {
TypeGeneric genericType = resultType.getGenerics().get(0);
Type payloadType = genericType.getConcreteType();
MetadataType outputType;
if (payloadType.isAnyType()) {
outputType = typeBuilder().anyType().build();
} else {
if (payloadType.isAssignableTo(TypedValue.class)) {
payloadType = payloadType.getGenerics().get(0).getConcreteType();
}
outputType = payloadType.asMetadataType();
}
Type attributesType = resultType.getGenerics().get(1).getConcreteType();
MetadataType attributesOutputType = attributesType.isAnyType() ? typeBuilder().anyType().build() : attributesType.asMetadataType();
return getListOfMessageType(returnType, outputType, attributesOutputType);
}
}
Aggregations