You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/01/12 11:02:05 UTC

[1/2] camel git commit: Prepare for apt compiler plugin to output @AsPredicate information

Repository: camel
Updated Branches:
  refs/heads/master d22d0ca06 -> 0d02e9e3c


Prepare for apt compiler plugin to output @AsPredicate information


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a9d0d9bc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a9d0d9bc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a9d0d9bc

Branch: refs/heads/master
Commit: a9d0d9bc0b439b8a8cb09b968accc91599854e0a
Parents: d22d0ca
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 12 11:09:00 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 12 11:09:00 2017 +0100

----------------------------------------------------------------------
 .../tools/apt/CoreEipAnnotationProcessor.java   | 126 ++++++++++---------
 .../tools/apt/EndpointAnnotationProcessor.java  |  15 ++-
 .../tools/apt/SpringAnnotationProcessor.java    |  25 ++--
 .../tools/apt/helper/JsonSchemaHelper.java      |   7 +-
 4 files changed, 102 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a9d0d9bc/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
index 04505b0..2ae503c 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
@@ -187,7 +187,8 @@ public class CoreEipAnnotationProcessor {
             String doc = entry.getDocumentation();
             doc = sanitizeDescription(doc, false);
             buffer.append(JsonSchemaHelper.toJson(entry.getName(), entry.getKind(), entry.isRequired(), entry.getType(), entry.getDefaultValue(), doc,
-                    entry.isDeprecated(), false, null, null, entry.isEnumType(), entry.getEnums(), entry.isOneOf(), entry.getOneOfTypes(), null, null, false));
+                    entry.isDeprecated(), false, null, null, entry.isEnumType(), entry.getEnums(), entry.isOneOf(), entry.getOneOfTypes(),
+                    entry.isAsPredicate(), null, null, false));
         }
         buffer.append("\n  }");
 
@@ -345,19 +346,21 @@ public class CoreEipAnnotationProcessor {
         boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
         if (isEnum) {
             TypeElement enumClass = findTypeElement(processingEnv, roundEnv, fieldTypeElement.asType().toString());
-            // find all the enum constants which has the possible enum value that can be used
-            List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
-            for (VariableElement var : fields) {
-                if (var.getKind() == ElementKind.ENUM_CONSTANT) {
-                    String val = var.toString();
-                    enums.add(val);
+            if (enumClass != null) {
+                // find all the enum constants which has the possible enum value that can be used
+                List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
+                for (VariableElement var : fields) {
+                    if (var.getKind() == ElementKind.ENUM_CONSTANT) {
+                        String val = var.toString();
+                        enums.add(val);
+                    }
                 }
             }
         }
 
         boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-        EipOption ep = new EipOption(name, "attribute", fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, false, null);
+        EipOption ep = new EipOption(name, "attribute", fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, false, null, false);
         eipOptions.add(ep);
 
         return false;
@@ -390,7 +393,7 @@ public class CoreEipAnnotationProcessor {
 
         boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-        EipOption ep = new EipOption(name, "value", fieldTypeName, required, defaultValue, docComment, deprecated, false, null, false, null);
+        EipOption ep = new EipOption(name, "value", fieldTypeName, required, defaultValue, docComment, deprecated, false, null, false, null, false);
         eipOptions.add(ep);
     }
 
@@ -423,16 +426,20 @@ public class CoreEipAnnotationProcessor {
             boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
             if (isEnum) {
                 TypeElement enumClass = findTypeElement(processingEnv, roundEnv, fieldTypeElement.asType().toString());
-                // find all the enum constants which has the possible enum value that can be used
-                List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
-                for (VariableElement var : fields) {
-                    if (var.getKind() == ElementKind.ENUM_CONSTANT) {
-                        String val = var.toString();
-                        enums.add(val);
+                if (enumClass != null) {
+                    // find all the enum constants which has the possible enum value that can be used
+                    List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
+                    for (VariableElement var : fields) {
+                        if (var.getKind() == ElementKind.ENUM_CONSTANT) {
+                            String val = var.toString();
+                            enums.add(val);
+                        }
                     }
                 }
             }
 
+            boolean asPredicate = false;
+
             // gather oneOf expression/predicates which uses language
             Set<String> oneOfTypes = new TreeSet<String>();
             boolean isOneOf = ONE_OF_TYPE_NAME.equals(fieldTypeName);
@@ -442,15 +449,15 @@ public class CoreEipAnnotationProcessor {
                 for (String language : ONE_OF_LANGUAGES) {
                     fieldTypeName = language;
                     TypeElement languages = findTypeElement(processingEnv, roundEnv, language);
-                    String superClassName = canonicalClassName(languages.toString());
-                    // find all classes that has that superClassName
-                    Set<TypeElement> children = new LinkedHashSet<TypeElement>();
-                    findTypeElementChildren(processingEnv, roundEnv, children, superClassName);
-                    for (TypeElement child : children) {
-                        XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
-                        if (rootElement != null) {
-                            String childName = rootElement.name();
-                            if (childName != null) {
+                    if (languages != null) {
+                        String superClassName = canonicalClassName(languages.toString());
+                        // find all classes that has that superClassName
+                        Set<TypeElement> children = new LinkedHashSet<TypeElement>();
+                        findTypeElementChildren(processingEnv, roundEnv, children, superClassName);
+                        for (TypeElement child : children) {
+                            XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
+                            if (rootElement != null) {
+                                String childName = rootElement.name();
                                 oneOfTypes.add(childName);
                             }
                         }
@@ -465,7 +472,7 @@ public class CoreEipAnnotationProcessor {
 
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, isOneOf, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, isOneOf, oneOfTypes, asPredicate);
             eipOptions.add(ep);
         }
     }
@@ -497,7 +504,7 @@ public class CoreEipAnnotationProcessor {
                 oneOfTypes.add(child);
             }
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -509,52 +516,52 @@ public class CoreEipAnnotationProcessor {
 
         // group
         String docComment = findJavaDoc(elementUtils, null, "group", null, classElement, true);
-        EipOption ep = new EipOption("group", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        EipOption ep = new EipOption("group", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // group
         docComment = findJavaDoc(elementUtils, null, "streamCache", null, classElement, true);
-        ep = new EipOption("streamCache", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("streamCache", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // trace
         docComment = findJavaDoc(elementUtils, null, "trace", null, classElement, true);
-        ep = new EipOption("trace", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("trace", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // trace
         docComment = findJavaDoc(elementUtils, null, "messageHistory", null, classElement, true);
-        ep = new EipOption("messageHistory", "attribute", "java.lang.String", false, "true", docComment, false, false, null, false, null);
+        ep = new EipOption("messageHistory", "attribute", "java.lang.String", false, "true", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // trace
         docComment = findJavaDoc(elementUtils, null, "handleFault", null, classElement, true);
-        ep = new EipOption("handleFault", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("handleFault", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // delayer
         docComment = findJavaDoc(elementUtils, null, "delayer", null, classElement, true);
-        ep = new EipOption("delayer", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("delayer", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // autoStartup
         docComment = findJavaDoc(elementUtils, null, "autoStartup", null, classElement, true);
-        ep = new EipOption("autoStartup", "attribute", "java.lang.String", false, "true", docComment, false, false, null, false, null);
+        ep = new EipOption("autoStartup", "attribute", "java.lang.String", false, "true", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // startupOrder
         docComment = findJavaDoc(elementUtils, null, "startupOrder", null, classElement, true);
-        ep = new EipOption("startupOrder", "attribute", "java.lang.Integer", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("startupOrder", "attribute", "java.lang.Integer", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // errorHandlerRef
         docComment = findJavaDoc(elementUtils, null, "errorHandlerRef", null, classElement, true);
-        ep = new EipOption("errorHandlerRef", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("errorHandlerRef", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // routePolicyRef
         docComment = findJavaDoc(elementUtils, null, "routePolicyRef", null, classElement, true);
-        ep = new EipOption("routePolicyRef", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("routePolicyRef", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // shutdownRoute
@@ -562,7 +569,7 @@ public class CoreEipAnnotationProcessor {
         enums.add("Default");
         enums.add("Defer");
         docComment = findJavaDoc(elementUtils, null, "shutdownRoute", "Default", classElement, true);
-        ep = new EipOption("shutdownRoute", "attribute", "org.apache.camel.ShutdownRoute", false, "", docComment, false, true, enums, false, null);
+        ep = new EipOption("shutdownRoute", "attribute", "org.apache.camel.ShutdownRoute", false, "", docComment, false, true, enums, false, null, false);
         eipOptions.add(ep);
 
         // shutdownRunningTask
@@ -570,14 +577,14 @@ public class CoreEipAnnotationProcessor {
         enums.add("CompleteCurrentTaskOnly");
         enums.add("CompleteAllTasks");
         docComment = findJavaDoc(elementUtils, null, "shutdownRunningTask", "CompleteCurrentTaskOnly", classElement, true);
-        ep = new EipOption("shutdownRunningTask", "attribute", "org.apache.camel.ShutdownRunningTask", false, "", docComment, false, true, enums, false, null);
+        ep = new EipOption("shutdownRunningTask", "attribute", "org.apache.camel.ShutdownRunningTask", false, "", docComment, false, true, enums, false, null, false);
         eipOptions.add(ep);
 
         // inputs
         Set<String> oneOfTypes = new TreeSet<String>();
         oneOfTypes.add("from");
         docComment = findJavaDoc(elementUtils, null, "inputs", null, classElement, true);
-        ep = new EipOption("inputs", "element", "java.util.List<org.apache.camel.model.FromDefinition>", true, "", docComment, false, false, null, true, oneOfTypes);
+        ep = new EipOption("inputs", "element", "java.util.List<org.apache.camel.model.FromDefinition>", true, "", docComment, false, false, null, true, oneOfTypes, false);
         eipOptions.add(ep);
 
         // outputs
@@ -592,9 +599,7 @@ public class CoreEipAnnotationProcessor {
             XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
             if (rootElement != null) {
                 String childName = rootElement.name();
-                if (childName != null) {
-                    oneOfTypes.add(childName);
-                }
+                oneOfTypes.add(childName);
             }
         }
 
@@ -602,7 +607,7 @@ public class CoreEipAnnotationProcessor {
         oneOfTypes.remove("route");
 
         docComment = findJavaDoc(elementUtils, null, "outputs", null, classElement, true);
-        ep = new EipOption("outputs", "element", "java.util.List<org.apache.camel.model.ProcessorDefinition<?>>", true, "", docComment, false, false, null, true, oneOfTypes);
+        ep = new EipOption("outputs", "element", "java.util.List<org.apache.camel.model.ProcessorDefinition<?>>", true, "", docComment, false, false, null, true, oneOfTypes, false);
         eipOptions.add(ep);
     }
 
@@ -616,19 +621,19 @@ public class CoreEipAnnotationProcessor {
 
         // id
         String docComment = findJavaDoc(elementUtils, null, "id", null, classElement, true);
-        EipOption ep = new EipOption("id", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+        EipOption ep = new EipOption("id", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // description
         docComment = findJavaDoc(elementUtils, null, "description", null, classElement, true);
-        ep = new EipOption("description", "element", "org.apache.camel.model.DescriptionDefinition", false, "", docComment, false, false, null, false, null);
+        ep = new EipOption("description", "element", "org.apache.camel.model.DescriptionDefinition", false, "", docComment, false, false, null, false, null, false);
         eipOptions.add(ep);
 
         // lets skip custom id as it has no value for end users to configure
         if (!skipUnwanted) {
             // custom id
             docComment = findJavaDoc(elementUtils, null, "customId", null, classElement, true);
-            ep = new EipOption("customId", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null);
+            ep = new EipOption("customId", "attribute", "java.lang.String", false, "", docComment, false, false, null, false, null, false);
             eipOptions.add(ep);
         }
     }
@@ -646,7 +651,7 @@ public class CoreEipAnnotationProcessor {
             Set<String> oneOfTypes = new TreeSet<String>();
             oneOfTypes.add("route");
 
-            EipOption ep = new EipOption("routes", "element", fieldTypeName, false, "", "Contains the Camel routes", false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption("routes", "element", fieldTypeName, false, "", "Contains the Camel routes", false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -664,7 +669,7 @@ public class CoreEipAnnotationProcessor {
             Set<String> oneOfTypes = new TreeSet<String>();
             oneOfTypes.add("rest");
 
-            EipOption ep = new EipOption("rests", "element", fieldTypeName, false, "", "Contains the rest services defined using the rest-dsl", false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption("rests", "element", fieldTypeName, false, "", "Contains the rest services defined using the rest-dsl", false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -695,16 +700,14 @@ public class CoreEipAnnotationProcessor {
                 XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
                 if (rootElement != null) {
                     String childName = rootElement.name();
-                    if (childName != null) {
-                        oneOfTypes.add(childName);
-                    }
+                    oneOfTypes.add(childName);
                 }
             }
 
             // remove some types which are not intended as an output in eips
             oneOfTypes.remove("route");
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", "", false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", "", false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -746,7 +749,7 @@ public class CoreEipAnnotationProcessor {
                 }
             }
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", docComment, false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", docComment, false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -772,6 +775,8 @@ public class CoreEipAnnotationProcessor {
             // find javadoc from original class as it will override the setExpression method where we can provide the javadoc for the given EIP
             String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, originalClassType, true);
 
+            boolean asPredicate = false;
+
             // gather oneOf expression/predicates which uses language
             Set<String> oneOfTypes = new TreeSet<String>();
             for (String language : ONE_OF_LANGUAGES) {
@@ -793,7 +798,7 @@ public class CoreEipAnnotationProcessor {
 
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", docComment, deprecated, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", docComment, deprecated, false, null, true, oneOfTypes, asPredicate);
             eipOptions.add(ep);
         }
     }
@@ -823,7 +828,10 @@ public class CoreEipAnnotationProcessor {
             Set<String> oneOfTypes = new HashSet<String>();
             oneOfTypes.add("when");
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, false, "", docComment, deprecated, false, null, true, oneOfTypes);
+            // when is predicate
+            boolean asPredicate = true;
+
+            EipOption ep = new EipOption(name, kind, fieldTypeName, false, "", docComment, deprecated, false, null, true, oneOfTypes, asPredicate);
             eipOptions.add(ep);
         }
     }
@@ -1010,9 +1018,10 @@ public class CoreEipAnnotationProcessor {
         private Set<String> enums;
         private boolean oneOf;
         private Set<String> oneOfTypes;
+        private boolean asPredicate;
 
         private EipOption(String name, String kind, String type, boolean required, String defaultValue, String documentation, boolean deprecated,
-                          boolean enumType, Set<String> enums, boolean oneOf, Set<String> oneOfTypes) {
+                          boolean enumType, Set<String> enums, boolean oneOf, Set<String> oneOfTypes, boolean asPredicate) {
             this.name = name;
             this.kind = kind;
             this.type = type;
@@ -1024,6 +1033,7 @@ public class CoreEipAnnotationProcessor {
             this.enums = enums;
             this.oneOf = oneOf;
             this.oneOfTypes = oneOfTypes;
+            this.asPredicate = asPredicate;
         }
 
         public String getName() {
@@ -1070,6 +1080,10 @@ public class CoreEipAnnotationProcessor {
             return oneOfTypes;
         }
 
+        public boolean isAsPredicate() {
+            return asPredicate;
+        }
+
         @Override
         public boolean equals(Object o) {
             if (this == o) {

http://git-wip-us.apache.org/repos/asf/camel/blob/a9d0d9bc/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
index 82bab2d..63d7090 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
@@ -310,10 +310,11 @@ public class EndpointAnnotationProcessor extends AbstractProcessor {
             String optionalPrefix = "";
             String prefix = "";
             boolean multiValue = false;
+            boolean asPredicate = false;
 
             buffer.append(JsonSchemaHelper.toJson(entry.getName(), "property", required, entry.getType(), defaultValue, doc,
-                    entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(), false, null,
-                    optionalPrefix, prefix, multiValue));
+                entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(),
+                false, null, asPredicate, optionalPrefix, prefix, multiValue));
         }
         buffer.append("\n  },");
 
@@ -361,10 +362,11 @@ public class EndpointAnnotationProcessor extends AbstractProcessor {
             String optionalPrefix = "";
             String prefix = "";
             boolean multiValue = false;
+            boolean asPredicate = false;
 
             buffer.append(JsonSchemaHelper.toJson(entry.getName(), "path", required, entry.getType(), defaultValue, doc,
-                    entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(), false, null,
-                    optionalPrefix, prefix, multiValue));
+                entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(),
+                false, null, asPredicate, optionalPrefix, prefix, multiValue));
         }
 
         // sort the endpoint options in the standard order we prefer
@@ -406,10 +408,11 @@ public class EndpointAnnotationProcessor extends AbstractProcessor {
             String optionalPrefix = entry.getOptionalPrefix();
             String prefix = entry.getPrefix();
             boolean multiValue = entry.isMultiValue();
+            boolean asPredicate = false;
 
             buffer.append(JsonSchemaHelper.toJson(entry.getName(), "parameter", required, entry.getType(), defaultValue,
-                    doc, entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(), false, null,
-                    optionalPrefix, prefix, multiValue));
+                doc, entry.isDeprecated(), entry.isSecret(), entry.getGroup(), entry.getLabel(), entry.isEnumType(), entry.getEnums(),
+                false, null, asPredicate, optionalPrefix, prefix, multiValue));
         }
         buffer.append("\n  }");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a9d0d9bc/tooling/apt/src/main/java/org/apache/camel/tools/apt/SpringAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/SpringAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/SpringAnnotationProcessor.java
index e6ea40c..081d845 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/SpringAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/SpringAnnotationProcessor.java
@@ -143,11 +143,14 @@ public class SpringAnnotationProcessor {
                 buffer.append(",");
             }
             buffer.append("\n    ");
+
             // as its json we need to sanitize the docs
             String doc = entry.getDocumentation();
             doc = sanitizeDescription(doc, false);
+
             buffer.append(JsonSchemaHelper.toJson(entry.getName(), entry.getKind(), entry.isRequired(), entry.getType(), entry.getDefaultValue(), doc,
-                    entry.isDeprecated(), false, null, null, entry.isEnumType(), entry.getEnums(), entry.isOneOf(), entry.getOneOfTypes(), null, null, false));
+                    entry.isDeprecated(), false, null, null, entry.isEnumType(), entry.getEnums(), entry.isOneOf(), entry.getOneOfTypes(), entry.isAsPredicate(),
+                null, null, false));
         }
         buffer.append("\n  }");
 
@@ -294,7 +297,7 @@ public class SpringAnnotationProcessor {
             }
         }
 
-        EipOption ep = new EipOption(name, "attribute", fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, false, null);
+        EipOption ep = new EipOption(name, "attribute", fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, false, null, false);
         eipOptions.add(ep);
 
         return false;
@@ -312,7 +315,7 @@ public class SpringAnnotationProcessor {
         Set<String> oneOfTypes = new TreeSet<String>();
         oneOfTypes.add("route");
 
-        EipOption ep = new EipOption("route", "element", fieldTypeName, false, "", "Contains the Camel routes", false, false, null, true, oneOfTypes);
+        EipOption ep = new EipOption("route", "element", fieldTypeName, false, "", "Contains the Camel routes", false, false, null, true, oneOfTypes, false);
         eipOptions.add(ep);
     }
 
@@ -328,7 +331,7 @@ public class SpringAnnotationProcessor {
         Set<String> oneOfTypes = new TreeSet<String>();
         oneOfTypes.add("rest");
 
-        EipOption ep = new EipOption("rest", "element", fieldTypeName, false, "", "Contains the rest services defined using the rest-dsl", false, false, null, true, oneOfTypes);
+        EipOption ep = new EipOption("rest", "element", fieldTypeName, false, "", "Contains the rest services defined using the rest-dsl", false, false, null, true, oneOfTypes, false);
         eipOptions.add(ep);
     }
 
@@ -406,8 +409,9 @@ public class SpringAnnotationProcessor {
             boolean oneOf = !oneOfTypes.isEmpty();
 
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
+            boolean asPredicate = false;
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, oneOf, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, oneOf, oneOfTypes, asPredicate);
             eipOptions.add(ep);
         }
     }
@@ -442,8 +446,7 @@ public class SpringAnnotationProcessor {
                 String child = element.name();
                 oneOfTypes.add(child);
             }
-
-            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue, docComment, false, false, null, true, oneOfTypes, false);
             eipOptions.add(ep);
         }
     }
@@ -562,9 +565,10 @@ public class SpringAnnotationProcessor {
         private Set<String> enums;
         private boolean oneOf;
         private Set<String> oneOfTypes;
+        private boolean asPredicate;
 
         private EipOption(String name, String kind, String type, boolean required, String defaultValue, String documentation, boolean deprecated,
-                          boolean enumType, Set<String> enums, boolean oneOf, Set<String> oneOfTypes) {
+                          boolean enumType, Set<String> enums, boolean oneOf, Set<String> oneOfTypes, boolean asPredicate) {
             this.name = name;
             this.kind = kind;
             this.type = type;
@@ -576,6 +580,7 @@ public class SpringAnnotationProcessor {
             this.enums = enums;
             this.oneOf = oneOf;
             this.oneOfTypes = oneOfTypes;
+            this.asPredicate = asPredicate;
         }
 
         public String getName() {
@@ -622,6 +627,10 @@ public class SpringAnnotationProcessor {
             return oneOfTypes;
         }
 
+        public boolean isAsPredicate() {
+            return asPredicate;
+        }
+
         @Override
         public boolean equals(Object o) {
             if (this == o) {

http://git-wip-us.apache.org/repos/asf/camel/blob/a9d0d9bc/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
index 228d3d3..c595b0e 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
@@ -42,7 +42,7 @@ public final class JsonSchemaHelper {
 
     public static String toJson(String name, String kind, Boolean required, String type, String defaultValue, String description,
                                 Boolean deprecated, Boolean secret, String group, String label, boolean enumType, Set<String> enums,
-                                boolean oneOfType, Set<String> oneOffTypes, String optionalPrefix, String prefix, boolean multiValue) {
+                                boolean oneOfType, Set<String> oneOffTypes, boolean asPredicate, String optionalPrefix, String prefix, boolean multiValue) {
         String typeName = JsonSchemaHelper.getType(type, enumType);
 
         StringBuilder sb = new StringBuilder();
@@ -129,6 +129,11 @@ public final class JsonSchemaHelper {
             sb.append(Strings.doubleQuote(text));
         }
 
+        if (asPredicate) {
+            sb.append(", \"asPredicate\": ");
+            sb.append(Strings.doubleQuote("true"));
+        }
+
         if (!Strings.isNullOrEmpty(description)) {
             sb.append(", \"description\": ");
             String text = sanitizeDescription(description, false);


[2/2] camel git commit: Apt compiler plugin to output @AsPredicate information

Posted by da...@apache.org.
Apt compiler plugin to output @AsPredicate information


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0d02e9e3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0d02e9e3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0d02e9e3

Branch: refs/heads/master
Commit: 0d02e9e3c7ad6c0d3280a252f893f266f33aedd7
Parents: a9d0d9b
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 12 12:00:56 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 12 12:00:56 2017 +0100

----------------------------------------------------------------------
 .../tools/apt/CoreEipAnnotationProcessor.java   | 22 ++++++++++++++------
 .../tools/apt/helper/JsonSchemaHelper.java      | 10 +++++++--
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0d02e9e3/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
index 2ae503c..fee000c 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessor.java
@@ -40,6 +40,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlValue;
 
+import org.apache.camel.spi.AsPredicate;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.tools.apt.helper.JsonSchemaHelper;
 import org.apache.camel.tools.apt.helper.Strings;
@@ -421,6 +422,12 @@ public class CoreEipAnnotationProcessor {
             // metadata may overrule element required
             required = findRequired(fieldElement, required);
 
+            // is it used as predicate (check field first and then fallback to its class)
+            boolean asPredicate = fieldElement.getAnnotation(AsPredicate.class) != null;
+            if (!asPredicate) {
+                asPredicate = classElement.getAnnotation(AsPredicate.class) != null;
+            }
+
             // gather enums
             Set<String> enums = new LinkedHashSet<String>();
             boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
@@ -438,8 +445,6 @@ public class CoreEipAnnotationProcessor {
                 }
             }
 
-            boolean asPredicate = false;
-
             // gather oneOf expression/predicates which uses language
             Set<String> oneOfTypes = new TreeSet<String>();
             boolean isOneOf = ONE_OF_TYPE_NAME.equals(fieldTypeName);
@@ -775,7 +780,14 @@ public class CoreEipAnnotationProcessor {
             // find javadoc from original class as it will override the setExpression method where we can provide the javadoc for the given EIP
             String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, originalClassType, true);
 
-            boolean asPredicate = false;
+            // is it used as predicate (check field first and then fallback to its class / original class)
+            boolean asPredicate = fieldElement.getAnnotation(AsPredicate.class) != null;
+            if (!asPredicate) {
+                asPredicate = classElement.getAnnotation(AsPredicate.class) != null;
+            }
+            if (!asPredicate) {
+                asPredicate = originalClassType.getAnnotation(AsPredicate.class) != null;
+            }
 
             // gather oneOf expression/predicates which uses language
             Set<String> oneOfTypes = new TreeSet<String>();
@@ -789,9 +801,7 @@ public class CoreEipAnnotationProcessor {
                     XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
                     if (rootElement != null) {
                         String childName = rootElement.name();
-                        if (childName != null) {
-                            oneOfTypes.add(childName);
-                        }
+                        oneOfTypes.add(childName);
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/0d02e9e3/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
index c595b0e..3cea5a0 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java
@@ -129,9 +129,15 @@ public final class JsonSchemaHelper {
             sb.append(Strings.doubleQuote(text));
         }
 
-        if (asPredicate) {
+        // for expressions we want to know if it must be used as predicate or not
+        boolean predicate = "expression".equals(kind) || asPredicate;
+        if (predicate) {
             sb.append(", \"asPredicate\": ");
-            sb.append(Strings.doubleQuote("true"));
+            if (asPredicate) {
+                sb.append(Strings.doubleQuote("true"));
+            } else {
+                sb.append(Strings.doubleQuote("false"));
+            }
         }
 
         if (!Strings.isNullOrEmpty(description)) {