You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/06/15 14:36:14 UTC
[camel] 01/03: (chores) camel-core-languages: cleanup duplicated code for appending class to the type
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 343321f3f77f45f34449b396212ed28f74eec16c
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Jun 15 09:15:52 2023 +0200
(chores) camel-core-languages: cleanup duplicated code for appending class to the type
---
.../simple/ast/SimpleFunctionExpression.java | 43 ++++++++--------------
1 file changed, 15 insertions(+), 28 deletions(-)
diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index f14dee8105c..e93a78125fc 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -660,10 +660,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
if (remainder != null) {
String type = StringHelper.before(remainder, ")");
remainder = StringHelper.after(remainder, ")");
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder);
@@ -915,10 +912,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
if (type == null) {
throw new SimpleParserException("Valid syntax: ${bodyAs(type)} was: " + function, token.getIndex());
}
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
remainder = StringHelper.after(remainder, ")");
@@ -989,10 +983,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
if (type == null) {
throw new SimpleParserException("Valid syntax: ${mandatoryBodyAs(type)} was: " + function, token.getIndex());
}
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
remainder = StringHelper.after(remainder, ")");
@@ -1075,10 +1066,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
}
key = StringHelper.removeQuotes(key);
key = key.trim();
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
index = StringHelper.removeQuotes(index);
@@ -1113,10 +1101,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
}
key = StringHelper.removeQuotes(key);
key = key.trim();
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
return "headerAs(message, \"" + key + "\", " + type + ")" + ognlCodeMethods(remainder, type);
@@ -1219,10 +1204,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
}
key = StringHelper.removeQuotes(key);
key = key.trim();
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
index = StringHelper.removeQuotes(index);
@@ -1260,10 +1242,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
}
key = StringHelper.removeQuotes(key);
key = key.trim();
- type = StringHelper.removeQuotes(type);
- if (!type.endsWith(".class")) {
- type = type + ".class";
- }
+ type = appendClass(type);
type = type.replace('$', '.');
type = type.trim();
return "exchangePropertyAs(exchange, \"" + key + "\", " + type + ")" + ognlCodeMethods(remainder, type);
@@ -1315,6 +1294,14 @@ public class SimpleFunctionExpression extends LiteralExpression {
return null;
}
+ private static String appendClass(String type) {
+ type = StringHelper.removeQuotes(type);
+ if (!type.endsWith(".class")) {
+ type = type + ".class";
+ }
+ return type;
+ }
+
private String createCodeFileExpression(String remainder) {
if (ObjectHelper.equal(remainder, "name")) {
return "fileName(message)";