use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getProperties.
@Test
public void getProperties() {
Set<Field> fields = IntrospectionUtils.getFieldsWithGetters(SomePojo.class, reflectionCache);
Type somePojo = typeSupplier.apply(SomePojo.class);
List<FieldElement> fieldsWithGetters = IntrospectionUtils.getFieldsWithGetters(somePojo);
assertThat(fieldsWithGetters.size(), is(fields.size()));
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getPagingProviderImplementationTypes.
@Test
public void getPagingProviderImplementationTypes() {
ResolvableType pagingProvider = ResolvableType.forClass(TestPagingProvider.class);
Pair<Type, Type> pagingProviderTypes = getPagingProviderTypes(new TypeWrapper(pagingProvider, TYPE_LOADER));
assertThat(pagingProviderTypes.getFirst().getDeclaringClass().get(), equalTo(Object.class));
assertThat(pagingProviderTypes.getSecond().getDeclaringClass().get(), equalTo(Result.class));
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class BackPressureDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration sourceDeclaration) {
BackPressureStrategyModelProperty property;
Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (extensionTypeDescriptorModelProperty.isPresent()) {
Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
sourceDeclaration.addModelProperty(property);
if (property.getSupportedModes().size() > 1) {
addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
}
}
}
}.walk(extensionDeclaration);
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class OperationModelLoaderDelegate method processPagingTx.
private void processPagingTx(OperationDeclarer operation, MethodElement method) {
checkArgument(method != null, "Can't introspect a null method");
Type returnTypeElement = method.getReturnType();
List<TypeGeneric> generics = returnTypeElement.getGenerics();
if (!generics.isEmpty()) {
operation.transactional(generics.get(0).getConcreteType().isAssignableTo(TransactionalConnection.class));
} else {
operation.transactional(false);
}
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class OperationModelLoaderDelegate method processNonBlockingOperation.
static void processNonBlockingOperation(OperationDeclarer operation, MethodElement operationMethod, boolean allowStreaming) {
List<ExtensionParameter> callbackParameters = operationMethod.getParameters().stream().filter(p -> p.getType().isSameType(CompletionCallback.class)).collect(toList());
checkDefinition(!callbackParameters.isEmpty(), format("Operation '%s' does not declare a '%s' parameter. One is required for a non-blocking operation", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
checkDefinition(callbackParameters.size() <= 1, format("Operation '%s' defines more than one %s parameters. Only one is allowed", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
checkDefinition(isVoid(operationMethod), format("Operation '%s' has a parameter of type %s but is not void. " + "Non-blocking operations have to be declared as void and the " + "return type provided through the callback", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
ExtensionParameter callbackParameter = callbackParameters.get(0);
List<MetadataType> genericTypes = callbackParameter.getType().getGenerics().stream().map(generic -> generic.getConcreteType().asMetadataType()).collect(toList());
if (genericTypes.isEmpty()) {
// This is an invalid state, but is better to fail when executing the Extension Model Validators
genericTypes.add(ANY_TYPE);
genericTypes.add(ANY_TYPE);
}
operation.withOutput().ofType(genericTypes.get(0));
operation.withOutputAttributes().ofType(genericTypes.get(1));
operation.blocking(false);
if (allowStreaming) {
handleByteStreaming(operationMethod, operation, genericTypes.get(0));
} else {
operation.supportsStreaming(false);
}
}
Aggregations