FAQ
Repository: camel
Updated Branches:
   refs/heads/master 2e2e3fe68 -> 20466f8a5


CAMEL-8446: Component docs - Add support for @Metadata on component fields which is the common pattern.


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

Branch: refs/heads/master
Commit: 20466f8a53b5447522e9bdaf0b4493745beb3d26
Parents: 2e2e3fe
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 7 16:56:25 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 7 16:56:25 2015 +0200

----------------------------------------------------------------------
  .../camel/component/xslt/XsltComponent.java | 1 -
  .../tools/apt/AbstractAnnotationProcessor.java | 16 ++++++++++++++++
  .../tools/apt/EndpointAnnotationProcessor.java | 18 ++++++++++++------
  3 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/20466f8a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
index 427bed3..b0a06e0 100644
--- a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
@@ -39,7 +39,6 @@ public class XsltComponent extends UriEndpointComponent {
      private URIResolver uriResolver;
      @Metadata(defaultValue = "true")
      private boolean contentCache = true;
- @Metadata(defaultValue = "false")
      private boolean saxon;

      public XsltComponent() {

http://git-wip-us.apache.org/repos/asf/camel/blob/20466f8a/tooling/apt/src/main/java/org/apache/camel/tools/apt/AbstractAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/AbstractAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/AbstractAnnotationProcessor.java
index 71c9a6f..051b5e2 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/AbstractAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/AbstractAnnotationProcessor.java
@@ -33,6 +33,7 @@ import javax.lang.model.element.Element;
  import javax.lang.model.element.ExecutableElement;
  import javax.lang.model.element.PackageElement;
  import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
  import javax.lang.model.type.TypeKind;
  import javax.lang.model.util.ElementFilter;
  import javax.lang.model.util.Elements;
@@ -168,6 +169,21 @@ public abstract class AbstractAnnotationProcessor extends AbstractProcessor {
          return null;
      }

+ protected VariableElement findFieldElement(TypeElement classElement, String fieldName) {
+ if (isNullOrEmpty(fieldName)) {
+ return null;
+ }
+
+ List<VariableElement> fields = ElementFilter.fieldsIn(classElement.getEnclosedElements());
+ for (VariableElement field : fields) {
+ if (fieldName.equals(field.getSimpleName().toString())) {
+ return field;
+ }
+ }
+
+ return null;
+ }
+
      protected TypeElement findTypeElement(RoundEnvironment roundEnv, String className) {
          if (isNullOrEmpty(className) || "java.lang.Object".equals(className)) {
              return null;

http://git-wip-us.apache.org/repos/asf/camel/blob/20466f8a/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 55b32c9..00a35e7 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
@@ -466,12 +466,11 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
                  String fieldName = methodName.substring(3);
                  fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);

- ExecutableElement setter = method;
- String name = fieldName;
- name = prefix + name;
- TypeMirror fieldType = setter.getParameters().get(0).asType();
- String fieldTypeName = fieldType.toString();
- TypeElement fieldTypeElement = findTypeElement(roundEnv, fieldTypeName);
+ // we usually favor putting the @Metadata annotation on the field instead of the setter, so try to use it if its there
+ VariableElement field = findFieldElement(classElement, fieldName);
+ if (field != null && metadata == null) {
+ metadata = field.getAnnotation(Metadata.class);
+ }

                  String required = metadata != null ? metadata.required() : null;
                  String label = metadata != null ? metadata.label() : null;
@@ -481,6 +480,13 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
                  String defaultValue = metadata != null ? metadata.defaultValue() : null;
                  String defaultValueNote = null;

+ ExecutableElement setter = method;
+ String name = fieldName;
+ name = prefix + name;
+ TypeMirror fieldType = setter.getParameters().get(0).asType();
+ String fieldTypeName = fieldType.toString();
+ TypeElement fieldTypeElement = findTypeElement(roundEnv, fieldTypeName);
+
                  String docComment = findJavaDoc(elementUtils, method, fieldName, name, classElement, false);
                  if (isNullOrEmpty(docComment)) {
                      docComment = metadata != null ? metadata.description() : null;

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categoriescamel
postedSep 7, '15 at 2:57p
activeSep 7, '15 at 2:57p
posts1
users1
websitecamel.apache.org

1 user in discussion

Davsclaus: 1 post

People

Translate

site design / logo © 2018 Grokbase