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 2020/09/16 13:42:55 UTC
[camel] 01/02: CAMEL-15478: Add method signatures to generated
source code.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch api
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 16e2bc761569c4311d9159d7dd5df02b8a8ba403
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Sep 16 15:36:08 2020 +0200
CAMEL-15478: Add method signatures to generated source code.
---
.../java/org/apache/camel/spi/ApiMethod.java | 4 ++--
.../camel/support/component/ApiMethodParser.java | 13 +++++++++---
.../component/ArgumentSubstitutionParser.java | 8 +-------
.../apache/camel/tooling/model/ApiMethodModel.java | 11 ++++++++++
.../org/apache/camel/tooling/model/JsonMapper.java | 7 +++++++
.../maven/AbstractApiMethodGeneratorMojo.java | 24 ++++++++++++++++++++--
.../packaging/EndpointSchemaGeneratorMojo.java | 3 +++
.../main/java/org/apache/camel/spi/ApiMethod.java | 4 ++--
8 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
index 2eaead7..535f169 100644
--- a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
@@ -36,8 +36,8 @@ public @interface ApiMethod {
String methodName();
/**
- * Returns the method signature(s) of this api method. A method may have one or more signatures, such as for
- * overloaded methhods.
+ * Returns the method signature(s) of this api method. A method may have one or more signatures due to overloaded
+ * methods.
* <p/>
* This is used for documentation and tooling only.
*/
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
index 751f1a5..762accfa 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodParser.java
@@ -200,7 +200,7 @@ public abstract class ApiMethodParser<T> {
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Method not found [" + signature + "] in type " + proxyType.getName());
}
- result.add(new ApiMethodModel(name, resultType, arguments, method, descriptions.get(name)));
+ result.add(new ApiMethodModel(name, resultType, arguments, method, descriptions.get(name), signature));
}
// allow derived classes to post process
@@ -339,26 +339,29 @@ public abstract class ApiMethodParser<T> {
private final List<ApiMethodArg> arguments;
private final Method method;
private final String description;
+ private final String signature;
private String uniqueName;
protected ApiMethodModel(String name, Class<?> resultType, List<ApiMethodArg> arguments, Method method,
- String description) {
+ String description, String signature) {
this.name = name;
this.resultType = resultType;
this.arguments = arguments;
this.method = method;
this.description = description;
+ this.signature = signature;
}
protected ApiMethodModel(String uniqueName, String name, Class<?> resultType, List<ApiMethodArg> arguments,
- Method method, String description) {
+ Method method, String description, String signature) {
this.name = name;
this.uniqueName = uniqueName;
this.resultType = resultType;
this.arguments = arguments;
this.method = method;
this.description = description;
+ this.signature = signature;
}
public String getUniqueName() {
@@ -386,6 +389,10 @@ public abstract class ApiMethodParser<T> {
return description;
}
+ public String getSignature() {
+ return signature;
+ }
+
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/ArgumentSubstitutionParser.java b/core/camel-support/src/main/java/org/apache/camel/support/component/ArgumentSubstitutionParser.java
index fe62702..6e8ebbb 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/ArgumentSubstitutionParser.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/ArgumentSubstitutionParser.java
@@ -131,7 +131,7 @@ public class ArgumentSubstitutionParser<T> extends ApiMethodParser<T> {
model = new ApiMethodModel(
model.getUniqueName(), model.getName(), model.getResultType(),
- updatedArguments, model.getMethod(), model.getDescription());
+ updatedArguments, model.getMethod(), model.getDescription(), model.getSignature());
}
}
@@ -188,12 +188,6 @@ public class ArgumentSubstitutionParser<T> extends ApiMethodParser<T> {
/**
* Create a substitution for a specific argument type and flag to indicate whether the replacement uses
- *
- * @param method
- * @param argName
- * @param argType
- * @param replacement
- * @param replaceWithType
*/
public Substitution(String method, String argName, String argType, String replacement, boolean replaceWithType) {
this(method, argName, argType, replacement);
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
index d2d57d0..c5b6f39 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
@@ -18,11 +18,14 @@ package org.apache.camel.tooling.model;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
public final class ApiMethodModel {
private String name;
private String description;
+ private final Set<String> signatures = new TreeSet<>();
private final List<ComponentModel.ApiOptionModel> options = new ArrayList<>();
public String getName() {
@@ -41,6 +44,14 @@ public final class ApiMethodModel {
this.description = description;
}
+ public Set<String> getSignatures() {
+ return signatures;
+ }
+
+ public void addSignature(String signature) {
+ this.signatures.add(signature);
+ }
+
public List<ComponentModel.ApiOptionModel> getOptions() {
return options;
}
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
index 4cd06f4..01ba69a 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
@@ -111,6 +111,10 @@ public final class JsonMapper {
for (Map.Entry<String, Object> mentry : mprap.entrySet()) {
JsonObject mmp = (JsonObject) mentry.getValue();
ApiMethodModel amm = am.newMethod(mmp.getString("apiMethodName"));
+ Collection<String> signatures = mmp.getCollection("signatures");
+ if (signatures != null && !signatures.isEmpty()) {
+ signatures.forEach(amm::addSignature);
+ }
amm.setDescription(mmp.getString("description"));
JsonObject properties = (JsonObject) obj.get("properties");
if (properties != null) {
@@ -423,6 +427,9 @@ public final class JsonMapper {
if (m.getDescription() != null) {
mJson.put("description", m.getDescription());
}
+ if (!m.getSignatures().isEmpty()) {
+ mJson.put("signatures", new JsonArray(m.getSignatures()));
+ }
mJson.put("properties", asJsonObject(m.getOptions()));
methods.put(m.getName(), mJson);
});
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
index 72a7e46..38b1f92 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
@@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringJoiner;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -415,7 +416,6 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
public String getApiMethods(List<ApiMethodParser.ApiMethodModel> models) {
// TODO: we should include alias information as well
- // TODO: and signature as well
models.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
@@ -428,11 +428,19 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
ApiMethodParser.ApiMethodModel model = models.get(i);
String name = model.getName();
if (names.add(name)) {
- String desc = model.getDescription();
sb.append("@ApiMethod(methodName = \"").append(model.getName()).append("\"");
+ String desc = model.getDescription();
if (ObjectHelper.isNotEmpty(desc)) {
sb.append(", description=\"").append(desc).append("\"");
}
+ List<String> signatures = getSignatures(models, name);
+ if (!signatures.isEmpty()) {
+ sb.append(", signatures={");
+ StringJoiner sj = new StringJoiner(", ");
+ signatures.forEach(s -> sj.add("\"" + s + "\""));
+ sb.append(sj.toString());
+ sb.append("}");
+ }
sb.append(")");
if (i < models.size() - 1) {
sb.append(", ");
@@ -443,6 +451,18 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
return sb.toString();
}
+ private List<String> getSignatures(List<ApiMethodParser.ApiMethodModel> models, String methodName) {
+ List<String> list = new ArrayList<>();
+ for (ApiMethodParser.ApiMethodModel model : models) {
+ if (model.getName().equals(methodName)) {
+ if (model.getSignature() != null) {
+ list.add(model.getSignature());
+ }
+ }
+ }
+ return list;
+ }
+
public static String getDefaultArgValue(Class<?> aClass) {
if (aClass.isPrimitive()) {
// lookup default primitive value string
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
index 973ecb9..d9e8e58 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
@@ -1140,6 +1140,9 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
for (ApiMethod m : apiParams.apiMethods()) {
if (m.methodName().equals(method.methodName())) {
apiMethod.setDescription(m.description());
+ for (String sig : m.signatures()) {
+ apiMethod.addSignature(sig);
+ }
break;
}
}
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
index 2eaead7..535f169 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
@@ -36,8 +36,8 @@ public @interface ApiMethod {
String methodName();
/**
- * Returns the method signature(s) of this api method. A method may have one or more signatures, such as for
- * overloaded methhods.
+ * Returns the method signature(s) of this api method. A method may have one or more signatures due to overloaded
+ * methods.
* <p/>
* This is used for documentation and tooling only.
*/