This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9dfa4657983d8de0751f5b0fa47a5e386fa5d8e8 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Thu Jun 30 13:13:35 2022 +0200 (chores) camel-route-parser: remove duplicated code for finding the root method the Java DSL parser --- .../helper/CamelJavaRestDslParserHelper.java | 26 ++++++---------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaRestDslParserHelper.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaRestDslParserHelper.java index 08a7d24b525..e4d8e7a14b9 100644 --- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaRestDslParserHelper.java +++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaRestDslParserHelper.java @@ -155,30 +155,13 @@ public final class CamelJavaRestDslParserHelper { } private boolean isRestConfiguration(Expression exp) { - String rootMethodName = null; - - // find out if this is from a Camel route (eg from, route etc.) - Expression sub = exp; - while (sub instanceof MethodInvocation) { - sub = ((MethodInvocation) sub).getExpression(); - if (sub instanceof MethodInvocation) { - Expression parent = ((MethodInvocation) sub).getExpression(); - if (parent == null) { - break; - } - } - } - if (sub instanceof MethodInvocation) { - rootMethodName = ((MethodInvocation) sub).getName().getIdentifier(); - } else if (sub instanceof SimpleName) { - rootMethodName = ((SimpleName) sub).getIdentifier(); - } + final String rootMethodName = findRootMethodName(exp); // must be from rest configuration return "restConfiguration".equals(rootMethodName); } - private boolean isRest(Expression exp) { + private String findRootMethodName(Expression exp) { String rootMethodName = null; // find out if this is from a Camel route (eg from, route etc.) @@ -197,6 +180,11 @@ public final class CamelJavaRestDslParserHelper { } else if (sub instanceof SimpleName) { rootMethodName = ((SimpleName) sub).getIdentifier(); } + return rootMethodName; + } + + private boolean isRest(Expression exp) { + final String rootMethodName = findRootMethodName(exp); // must be from rest return "rest".equals(rootMethodName);
