This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6a98e0bbad0fb601d7a906e01884464aa1426d0a
Author: jpoth <poth.j...@gmail.com>
AuthorDate: Fri Aug 31 11:17:46 2018 +0200

    Lets make the camel-api-component-maven-plugin handle generic methods with 
non generic return types
---
 .../org/apache/camel/util/component/ApiMethodParser.java    | 13 +++++++++----
 .../util/component/ArgumentSubstitutionParserTest.java      |  9 ++++++++-
 .../java/org/apache/camel/util/component/TestProxy.java     |  4 ++++
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git 
a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java 
b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
index 70013c8..62850ab 100644
--- 
a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
+++ 
b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
@@ -40,7 +40,7 @@ public abstract class ApiMethodParser<T> {
 
     private static final String METHOD_PREFIX = 
"^(\\s*(public|final|synchronized|native)\\s+)*(\\s*<[^>]>)?\\s*(\\S+)\\s+([^\\(]+\\s*)\\(";
     private static final Pattern METHOD_PATTERN = 
Pattern.compile("\\s*([^<\\s]+)?\\s*(<[^>]+>)?(<(?<genericTypeParameterName>\\S+)\\s+extends\\s+"
-            + 
"(?<genericTypeParameterUpperBound>\\S+)>\\s+\\k<genericTypeParameterName>)?\\s+(\\S+)\\s*\\(\\s*(?<signature>[\\S\\s,]*)\\)\\s*;?\\s*");
+            + 
"(?<genericTypeParameterUpperBound>\\S+)>\\s+(?<returnType>\\S+))?\\s+(\\S+)\\s*\\(\\s*(?<signature>[\\S\\s,]*)\\)\\s*;?\\s*");
 
     private static final String JAVA_LANG = "java.lang.";
     private static final Map<String, Class<?>> PRIMITIVE_TYPES;
@@ -120,16 +120,21 @@ public abstract class ApiMethodParser<T> {
             // handle generic methods with single bounded type parameters
             String genericTypeParameterName = null;
             String genericTypeParameterUpperBound = null;
+            String returnType = null;
             try {
                 genericTypeParameterName = 
methodMatcher.group("genericTypeParameterName");
                 genericTypeParameterUpperBound = 
methodMatcher.group("genericTypeParameterUpperBound");
+                returnType = methodMatcher.group("returnType");
+                if (returnType != null && 
returnType.equals(genericTypeParameterName)) {
+                    returnType = genericTypeParameterUpperBound;
+                }
             } catch (IllegalArgumentException e) {
                 // ignore
             }
 
-            final Class<?> resultType = genericTypeParameterName != null ? 
forName(genericTypeParameterUpperBound) : forName(methodMatcher.group(1));
-            final String name = methodMatcher.group(6);
-            final String argSignature = methodMatcher.group(7);
+            final Class<?> resultType = returnType != null ? 
forName(returnType) : forName(methodMatcher.group(1));
+            final String name = methodMatcher.group(7);
+            final String argSignature = methodMatcher.group(8);
 
             final List<ApiMethodArg> arguments = new ArrayList<>();
             final List<Class<?>> argTypes = new ArrayList<>();
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
 
b/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
index 05515e6..092ef08 100644
--- 
a/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.util.component;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import org.apache.camel.util.component.ArgumentSubstitutionParser.Substitution;
@@ -51,10 +52,16 @@ public class ArgumentSubstitutionParserTest {
         signatures.add("public final String 
greetInnerChild(org.apache.camel.util.component.TestProxy.InnerChild child);");
         signatures.add("public final <T extends java.util.Date> T 
sayHiResource(java.util.Set<T> resourceType, String resourceId);");
         signatures.add("public final <T extends java.util.Date> T with(T 
theDate);");
+        signatures.add("public final <T extends java.util.Date> String 
withDate(T theDate, Class<? extends java.util.Date> dateClass, Class<T> 
parameter, T parameters);");
+
         parser.setSignatures(signatures);
 
         final List<ApiMethodParser.ApiMethodModel> methodModels = 
parser.parse();
-        assertEquals(11, methodModels.size());
+        assertEquals(12, methodModels.size());
+
+        final ApiMethodParser.ApiMethodModel withDate = methodModels.get(11);
+        assertEquals(String.class, withDate.getResultType());
+        assertEquals(Date.class, withDate.getArguments().get(0).getType());
 
         final ApiMethodParser.ApiMethodModel sayHi1 = methodModels.get(8);
         assertEquals(PERSON, sayHi1.getArguments().get(0).getName());
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java 
b/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
index 00bf1c2..0ca09f0 100644
--- a/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
+++ b/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
@@ -82,6 +82,10 @@ class TestProxy {
         return null;
     }
 
+    public final <T extends java.util.Date> String withDate(T theDate, Class<? 
extends java.util.Date> dateClass, Class<T> parameter, T parameters) {
+        return null;
+    }
+
     public final String greetInnerChild(InnerChild child) {
         return sayHi(child.getName());
     }

Reply via email to