valdar commented on a change in pull request #322:
URL: https://github.com/apache/camel-k-runtime/pull/322#discussion_r421567287



##########
File path: 
tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateYamlLoaderSupportClasses.java
##########
@@ -144,4 +154,93 @@ public final TypeSpec generateReifiers() {
 
         return type.build();
     }
+
+    public final TypeSpec generateResolver() {
+        Set<String> ids = new HashSet<>();
+
+        MethodSpec.Builder mb = MethodSpec.methodBuilder("resolve")
+            .addAnnotation(Override.class)
+            .addModifiers(Modifier.PUBLIC)
+            .addParameter(ClassName.get("org.apache.camel", "CamelContext"), 
"camelContext")
+            .addParameter(ClassName.get("java.lang", "String"), "id")
+            .returns(ClassName.get("org.apache.camel.k.loader.yaml.spi", 
"StepParser"));
+
+        mb.beginControlFlow("switch(id)");
+
+        // custom parsers
+        annotated(YAML_STEP_PARSER_ANNOTATION)
+            .sorted(Comparator.comparing(i -> i.name().toString()))
+            .forEach(
+                i -> {
+                    AnnotationValue value = 
i.classAnnotation(YAML_STEP_PARSER_ANNOTATION).value();
+                    for (String id: value.asStringArray()) {
+                        if (ids.add(id)) {
+                            mb.beginControlFlow("case $S:", id);
+                            mb.addStatement("return new $L()", 
i.name().toString());
+                            mb.endControlFlow();
+                        }
+                    }
+                }
+            );
+
+        // auto generated parsers
+        annotated(XMLROOTELEMENT_ANNOTATION_CLASS)
+            .forEach(
+                i -> {
+                    AnnotationInstance meta = 
i.classAnnotation(METADATA_ANNOTATION);
+                    AnnotationInstance root = 
i.classAnnotation(XMLROOTELEMENT_ANNOTATION_CLASS);
+
+                    if (meta != null && root != null) {
+                        AnnotationValue name = root.value("name");
+                        AnnotationValue label = meta.value("label");
+
+                        if (name != null && label != null) {
+                            // skip known definitions for which there is a 
custom
+                            // implementation
+                            switch (i.name().toString()) {
+                                case 
"org.apache.camel.model.Resilience4jConfigurationDefinition":
+                                case 
"org.apache.camel.model.HystrixConfigurationDefinition":
+                                case 
"org.apache.camel.model.config.StreamResequencerConfig":
+                                case 
"org.apache.camel.model.config.BatchResequencerConfig":
+                                case 
"org.apache.camel.model.OnFallbackDefinition":
+                                case "org.apache.camel.model.InOnlyDefinition":
+                                case "org.apache.camel.model.InOutDefinition":
+                                case 
"org.apache.camel.model.OtherwiseDefinition":
+                                case "org.apache.camel.model.WhenDefinition":
+                                    return;
+                                default:
+                                    break;
+                            }
+                            switch (i.name().prefix().toString()) {
+                                case "org.apache.camel.model.loadbalancer":

Review comment:
       LGTM




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to