You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2019/06/06 07:04:57 UTC
[camel] 04/05: Hack a bit to allow chaining between the base and
the derived class
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch endpoint-dsl
in repository https://gitbox.apache.org/repos/asf/camel.git
commit d66a05629ff07f2068dc4350401a58a31d8c159d
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Jun 6 09:02:08 2019 +0200
Hack a bit to allow chaining between the base and the derived class
We are at the limit of what the source generation library can do here ;-)
---
.../apache/camel/maven/packaging/EndpointDslMojo.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java
index 14adb80..af905e2 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java
@@ -210,20 +210,22 @@ public class EndpointDslMojo extends AbstractMojo {
Map<String, JavaClass> enumClasses = new HashMap<>();
JavaClass commonClass = javaClass.addNestedType().setPublic().setStatic(true);
- commonClass.setName(name.replace("Endpoint", "Common"));
- commonClass.extendSuperType("EndpointConfiguration");
+ commonClass.setName(name.replace("Endpoint", "Common") + "<T extends EndpointConfiguration>");
+ commonClass.extendSuperType("EndpointConfiguration<T>");
generateDummyClass(commonClass.getCanonicalName());
JavaClass consumerClass = javaClass.addNestedType().setPublic().setStatic(true);
consumerClass.setName(name.replace("Endpoint", "Consumer"));
- consumerClass.extendSuperType(name.replace("Endpoint", "Common"));
+ consumerClass.extendSuperType(name.replace("Endpoint", "Common") + "<" + name.replace("Endpoint", "Consumer") + ">");
generateDummyClass(consumerClass.getCanonicalName());
JavaClass producerClass = javaClass.addNestedType().setPublic().setStatic(true);
producerClass.setName(name.replace("Endpoint", "Producer"));
- producerClass.extendSuperType(name.replace("Endpoint", "Common"));
+ producerClass.extendSuperType(name.replace("Endpoint", "Common") + "<" + name.replace("Endpoint", "Producer") + ">");
generateDummyClass(producerClass.getCanonicalName());
+ generateDummyClass(packageName + ".T");
+
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
if (!Strings.isBlank(model.getDescription())) {
doc = model.getDescription() + "\n\n" + doc;
@@ -256,11 +258,13 @@ public class EndpointDslMojo extends AbstractMojo {
Property prop = target.addProperty(gtype, option.getName());
+ String fluentBuilderTypeName = target == commonClass ? packageName + ".T" : target.getCanonicalName();
+ String fluentBuilderTypeShortName = target == commonClass ? "T" : target.getName();
Method fluent = target.addMethod().setPublic().setName(option.getName())
- .setReturnType(new GenericType(loadClass(target.getCanonicalName())))
+ .setReturnType(new GenericType(loadClass(fluentBuilderTypeName)) )
.addParameter(PRIMITIVEMAP.containsKey(ogtype.toString()) ? ogtype : gtype, option.getName())
.setBody("this." + option.getName() + " = " + option.getName() + ";\n" +
- "return (" + target.getName() + ") this;\n");
+ "return (" + fluentBuilderTypeShortName + ") this;\n");
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
prop.getAccessor().addAnnotation(Deprecated.class);
@@ -277,6 +281,8 @@ public class EndpointDslMojo extends AbstractMojo {
}
}
+ javaClass.removeImport("T");
+
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName, false);
}