use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.
the class MuleExtensionAnnotationParser method parseRepeatableAnnotation.
public static <T extends Annotation> List<AnnotationValueFetcher<T>> parseRepeatableAnnotation(Type extensionType, Class<T> annotation, Function<Annotation, T[]> containerConsumer) {
List<AnnotationValueFetcher<T>> annotationDeclarations = ImmutableList.of();
Repeatable repeatableContainer = annotation.getAnnotation(Repeatable.class);
if (repeatableContainer != null) {
Optional<? extends AnnotationValueFetcher<? extends Annotation>> container = extensionType.getValueFromAnnotation(repeatableContainer.value());
if (container.isPresent()) {
annotationDeclarations = container.get().getInnerAnnotations((Function) containerConsumer);
}
}
Optional<AnnotationValueFetcher<T>> singleDeclaration = extensionType.getValueFromAnnotation(annotation);
if (singleDeclaration.isPresent()) {
annotationDeclarations = Collections.singletonList(singleDeclaration.get());
}
return annotationDeclarations;
}
use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.
the class SubTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = declarer.getDeclaration();
Optional<ExtensionTypeDescriptorModelProperty> implementingType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!implementingType.isPresent()) {
return;
}
Type type = implementingType.get().getType();
List<AnnotationValueFetcher<SubTypeMapping>> typeMappings = parseRepeatableAnnotation(type, SubTypeMapping.class, c -> ((SubTypesMapping) c).value());
if (!typeMappings.isEmpty()) {
declareSubTypesMapping(declarer, typeMappings, extensionDeclaration.getName());
}
}
use of org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher in project mule by mulesoft.
the class ImportedTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!extensionType.isPresent()) {
return;
}
Type type = extensionType.get().getType();
final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
if (!importTypes.isEmpty()) {
if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
}
importTypes.forEach(imported -> {
MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
if (!(importedType instanceof ObjectType)) {
throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
}
extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
});
}
}
Aggregations