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/06 10:38:41 UTC
[camel] 02/04: CAMEL-15478: Fix and improve java source parser to
work with inner classes and varargs/array types and whatnot. Migrated
camel-zendesk from javadoc to javasource parsing
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 529ca99cab9a25fa1dbfad73949cabcb46db05a4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Sep 6 11:04:20 2020 +0200
CAMEL-15478: Fix and improve java source parser to work with inner classes and varargs/array types and whatnot. Migrated camel-zendesk from javadoc to javasource parsing
---
.../org/apache/camel/maven/JavaSourceParser.java | 54 ++++++++++------------
1 file changed, 24 insertions(+), 30 deletions(-)
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
index 5ba600d..592e423 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
@@ -63,20 +63,7 @@ public class JavaSourceParser {
if (result == null || result.isEmpty()) {
result = "void";
}
- if (Character.isUpperCase(result.charAt(0))) {
- // okay so its maybe an inner class and has import so we need to resolve this more complex
- pos = result.lastIndexOf('.');
- if (pos != -1) {
- String base = result.substring(0, pos);
- String remainder = result.substring(pos + 1);
- base = clazz.resolveType(base);
- result = base + "$" + remainder;
- } else {
- result = result.replace('.', '$');
- // okay no package name so its a local inner class
- result = clazz.getPackage() + "." + result;
- }
- }
+ result = resolveType(clazz, result);
List<JavaDocTag> params = ms.getJavaDoc().getTags("@param");
@@ -87,22 +74,7 @@ public class JavaSourceParser {
for (int i = 0; i < list.size(); i++) {
ParameterSource ps = list.get(i);
String name = ps.getName();
- String type = ps.getType().getQualifiedNameWithGenerics();
- type = clazz.resolveType(type);
- if (Character.isUpperCase(type.charAt(0))) {
- // okay so its maybe an inner class and has import so we need to resolve this more complex
- pos = result.lastIndexOf('.');
- if (pos != -1) {
- String base = type.substring(0, pos);
- String remainder = type.substring(pos + 1);
- base = clazz.resolveType(base);
- type = base + "$" + remainder;
- } else {
- type = type.replace('.', '$');
- // okay no package name so its a local inner class
- type = clazz.getPackage() + "." + type;
- }
- }
+ String type = resolveType(clazz, ps.getType().getQualifiedNameWithGenerics());
if (type.startsWith("java.lang.")) {
type = type.substring(10);
}
@@ -135,6 +107,28 @@ public class JavaSourceParser {
}
}
+ private static String resolveType(JavaClassSource clazz, String type) {
+ if ("void".equals(type)) {
+ return "void";
+ }
+ type = clazz.resolveType(type);
+ int pos = type.lastIndexOf('.');
+ if (Character.isUpperCase(type.charAt(0))) {
+ // okay so its maybe an inner class and has import so we need to resolve this more complex
+ if (pos != -1) {
+ String base = type.substring(0, pos);
+ String remainder = type.substring(pos + 1);
+ base = clazz.resolveType(base);
+ type = base + "$" + remainder;
+ } else {
+ type = type.replace('.', '$');
+ // okay no package name so its a local inner class
+ type = clazz.getPackage() + "." + type;
+ }
+ }
+ return type;
+ }
+
private static String getJavadocValue(List<JavaDocTag> params, String name) {
for (JavaDocTag tag : params) {
String key = tag.getValue();