Repository: camel Updated Branches: refs/heads/master 1eb932eee -> 013f508bd
CAMEL-7999: apt compiler should sort eip properties in order that feels more natural Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/013f508b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/013f508b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/013f508b Branch: refs/heads/master Commit: 013f508bdbad0221770ed9d1e0c9fbc2f2ca9cb9 Parents: 1eb932e Author: Claus Ibsen <[email protected]> Authored: Fri Jan 30 07:42:47 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Fri Jan 30 08:08:11 2015 +0100 ---------------------------------------------------------------------- .../camel/tools/apt/EipAnnotationProcessor.java | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/013f508b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java ---------------------------------------------------------------------- diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java index 92a6993..9e882d6 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java @@ -17,6 +17,8 @@ package org.apache.camel.tools.apt; import java.io.PrintWriter; +import java.util.Collections; +import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -149,7 +151,7 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor { EipModel eipModel = findEipModelProperties(roundEnv, classElement, javaTypeName, name); // get endpoint information which is divided into paths and options (though there should really only be one path) - Set<EipOption> eipOptions = new LinkedHashSet<EipOption>(); + Set<EipOption> eipOptions = new TreeSet<EipOption>(new EipOptionComparator(eipModel)); findClassProperties(writer, roundEnv, eipOptions, classElement, classElement, ""); // after we have found all the options then figure out if the model accepts input/output @@ -932,4 +934,41 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor { } } + private static class EipOptionComparator implements Comparator<EipOption> { + + private final EipModel model; + + private EipOptionComparator(EipModel model) { + this.model = model; + } + + @Override + public int compare(EipOption o1, EipOption o2) { + int weigth = weigth(o1); + int weigth2 = weigth(o2); + + if (weigth == weigth2) { + // keep the current order + return 1; + } else { + // sort according to weight + return weigth2 - weigth; + } + } + + private int weigth(EipOption o) { + String name = o.getName(); + // these should be last + if ("description".equals(name)) { + return -10; + } else if ("id".equals(name)) { + return -9; + } else if ("pattern".equals(name) && "to".equals(model.getName())) { + // and pattern only for the to model + return -8; + } + return 0; + } + } + } \ No newline at end of file
