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 2026/01/26 13:01:40 UTC
(camel) 02/41: (chores): modernize instanceof checks in camel-route-parser
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 0dec67585276c33ab85e7c49ac397f2fdd302b1e
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jan 26 10:25:55 2026 +0000
(chores): modernize instanceof checks in camel-route-parser
---
.../camel/parser/helper/CamelJavaParserHelper.java | 20 +++++------
.../helper/CamelJavaRestDslParserHelper.java | 40 +++++++++++-----------
.../parser/helper/CamelJavaTreeParserHelper.java | 40 +++++++++++-----------
.../apache/camel/parser/helper/CamelXmlHelper.java | 4 +--
.../apache/camel/parser/helper/ParserCommon.java | 8 ++---
5 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaParserHelper.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaParserHelper.java
index c283bf32c4d1..21541f0fef4e 100644
--- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaParserHelper.java
+++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaParserHelper.java
@@ -344,8 +344,8 @@ public final class CamelJavaParserHelper {
return;
}
}
- if (fields && arg instanceof SimpleName) {
- FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, (SimpleName) arg);
+ if (fields && arg instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, simplename);
if (field != null) {
// find the endpoint uri from the annotation
AnnotationSource<JavaClassSource> annotation = field.getAnnotation("org.apache.camel.EndpointInject");
@@ -360,8 +360,8 @@ public final class CamelJavaParserHelper {
} else {
// the field may be initialized using variables, so we need to evaluate those expressions
Object fi = field.getInternal();
- if (fi instanceof VariableDeclaration) {
- Expression exp = ((VariableDeclaration) fi).getInitializer();
+ if (fi instanceof VariableDeclaration variabledeclaration) {
+ Expression exp = (variabledeclaration).getInitializer();
String uri = CamelJavaParserHelper.getLiteralValue(clazz, block, exp);
if (!Strings.isNullOrEmpty(uri)) {
// we want the position of the field, and not in the route
@@ -444,8 +444,8 @@ public final class CamelJavaParserHelper {
if (list != null && list.size() == 1) {
ASTNode o = (ASTNode) list.get(0);
ASTNode p = o.getParent();
- if (p instanceof MethodInvocation) {
- String pName = ((MethodInvocation) p).getName().getIdentifier();
+ if (p instanceof MethodInvocation methodinvocation) {
+ String pName = (methodinvocation).getName().getIdentifier();
if (language.equals(pName)) {
// okay find the parent of the language which is the method that uses the language
parent = (Expression) p.getParent();
@@ -490,8 +490,8 @@ public final class CamelJavaParserHelper {
public static String getLiteralValue(JavaClassSource clazz, Block block, Expression expression) {
// unwrap parenthesis
- if (expression instanceof ParenthesizedExpression) {
- expression = ((ParenthesizedExpression) expression).getExpression();
+ if (expression instanceof ParenthesizedExpression parenthesizedexpression) {
+ expression = (parenthesizedexpression).getExpression();
}
if (expression instanceof StringLiteral stringLiteral) {
@@ -518,8 +518,8 @@ public final class CamelJavaParserHelper {
return "{{" + name + "}}";
}
- if (expression instanceof SimpleName) {
- FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, (SimpleName) expression);
+ if (expression instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, simplename);
if (field != null) {
// is the field annotated with a Camel endpoint
if (field.getAnnotations() != null) {
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 a03de3df2e39..b3ae8e7a211a 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
@@ -175,8 +175,8 @@ public final class CamelJavaRestDslParserHelper {
Expression sub = exp;
while (sub instanceof MethodInvocation methodInvocation) {
sub = methodInvocation.getExpression();
- if (sub instanceof MethodInvocation) {
- Expression parent = ((MethodInvocation) sub).getExpression();
+ if (sub instanceof MethodInvocation methodinvocation) {
+ Expression parent = (methodinvocation).getExpression();
if (parent == null) {
break;
}
@@ -420,10 +420,10 @@ public final class CamelJavaRestDslParserHelper {
// find out if this is from a Camel route (eg from, route etc.)
Expression sub = mi;
- while (sub instanceof MethodInvocation) {
- sub = ((MethodInvocation) sub).getExpression();
- if (sub instanceof MethodInvocation) {
- name = ((MethodInvocation) sub).getName().getIdentifier();
+ while (sub instanceof MethodInvocation methodinvocation) {
+ sub = methodinvocation.getExpression();
+ if (sub instanceof MethodInvocation mi2) {
+ name = mi2.getName().getIdentifier();
if (parentName.equals(name)) {
return true;
}
@@ -467,8 +467,8 @@ public final class CamelJavaRestDslParserHelper {
private static FieldSource<JavaClassSource> findFieldInBlock(JavaClassSource clazz, Block block, String fieldName) {
for (Object statement : block.statements()) {
// try local statements first in the block
- if (statement instanceof VariableDeclarationStatement) {
- final Type type = ((VariableDeclarationStatement) statement).getType();
+ if (statement instanceof VariableDeclarationStatement variabledeclarationstatement) {
+ final Type type = (variabledeclarationstatement).getType();
for (Object obj : ((VariableDeclarationStatement) statement).fragments()) {
if (obj instanceof VariableDeclarationFragment fragment) {
SimpleName name = fragment.getName();
@@ -507,16 +507,16 @@ public final class CamelJavaRestDslParserHelper {
public static String getLiteralValue(JavaClassSource clazz, Block block, Expression expression) {
// unwrap parenthesis
- if (expression instanceof ParenthesizedExpression) {
- expression = ((ParenthesizedExpression) expression).getExpression();
+ if (expression instanceof ParenthesizedExpression parenthesizedexpression) {
+ expression = (parenthesizedexpression).getExpression();
}
- if (expression instanceof StringLiteral) {
- return ((StringLiteral) expression).getLiteralValue();
- } else if (expression instanceof BooleanLiteral) {
- return String.valueOf(((BooleanLiteral) expression).booleanValue());
- } else if (expression instanceof NumberLiteral) {
- return ((NumberLiteral) expression).getToken();
+ if (expression instanceof StringLiteral stringliteral) {
+ return (stringliteral).getLiteralValue();
+ } else if (expression instanceof BooleanLiteral booleanliteral) {
+ return String.valueOf((booleanliteral).booleanValue());
+ } else if (expression instanceof NumberLiteral numberliteral) {
+ return (numberliteral).getToken();
} else if (expression instanceof TextBlock textBlock) {
return textBlock.getLiteralValue();
}
@@ -532,8 +532,8 @@ public final class CamelJavaRestDslParserHelper {
return qn.getName().getIdentifier();
}
- if (expression instanceof SimpleName) {
- FieldSource<JavaClassSource> field = getField(clazz, block, (SimpleName) expression);
+ if (expression instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = getField(clazz, block, simplename);
if (field != null) {
// is the field annotated with a Camel endpoint
if (field.getAnnotations() != null) {
@@ -629,8 +629,8 @@ public final class CamelJavaRestDslParserHelper {
private static boolean isNumericOperator(JavaClassSource clazz, Block block, Expression expression) {
if (expression instanceof NumberLiteral) {
return true;
- } else if (expression instanceof SimpleName) {
- FieldSource<JavaClassSource> field = getField(clazz, block, (SimpleName) expression);
+ } else if (expression instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = getField(clazz, block, simplename);
if (field != null) {
return field.getType().isType("int") || field.getType().isType("long")
|| field.getType().isType("Integer") || field.getType().isType("Long");
diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
index 457260319865..e426cc4b8663 100644
--- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
+++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
@@ -162,10 +162,10 @@ public final class CamelJavaTreeParserHelper {
// 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();
+ while (sub instanceof MethodInvocation methodinvocation) {
+ sub = methodinvocation.getExpression();
+ if (sub instanceof MethodInvocation mi2) {
+ Expression parent = mi2.getExpression();
if (parent == null) {
break;
}
@@ -272,23 +272,23 @@ public final class CamelJavaTreeParserHelper {
public static String getLiteralValue(JavaClassSource clazz, Block block, Expression expression) {
// unwrap parenthesis
- if (expression instanceof ParenthesizedExpression) {
- expression = ((ParenthesizedExpression) expression).getExpression();
+ if (expression instanceof ParenthesizedExpression parenthesizedexpression) {
+ expression = (parenthesizedexpression).getExpression();
}
- if (expression instanceof StringLiteral) {
- return ((StringLiteral) expression).getLiteralValue();
- } else if (expression instanceof BooleanLiteral) {
- return String.valueOf(((BooleanLiteral) expression).booleanValue());
- } else if (expression instanceof NumberLiteral) {
- return ((NumberLiteral) expression).getToken();
+ if (expression instanceof StringLiteral stringliteral) {
+ return (stringliteral).getLiteralValue();
+ } else if (expression instanceof BooleanLiteral booleanliteral) {
+ return String.valueOf((booleanliteral).booleanValue());
+ } else if (expression instanceof NumberLiteral numberliteral) {
+ return (numberliteral).getToken();
} else if (expression instanceof TextBlock textBlock) {
return textBlock.getLiteralValue();
}
// if it's a method invocation then add a dummy value assuming the method invocation will return a valid response
- if (expression instanceof MethodInvocation) {
- String name = ((MethodInvocation) expression).getName().getIdentifier();
+ if (expression instanceof MethodInvocation methodinvocation) {
+ String name = (methodinvocation).getName().getIdentifier();
return "{{" + name + "}}";
}
@@ -300,8 +300,8 @@ public final class CamelJavaTreeParserHelper {
return "{{" + name + "}}";
}
- if (expression instanceof SimpleName) {
- FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, (SimpleName) expression);
+ if (expression instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = ParserCommon.getField(clazz, block, simplename);
if (field != null) {
// is the field annotated with a Camel endpoint
if (field.getAnnotations() != null) {
@@ -309,10 +309,10 @@ public final class CamelJavaTreeParserHelper {
boolean valid = "org.apache.camel.EndpointInject".equals(ann.getQualifiedName());
if (valid) {
Expression exp = (Expression) ann.getInternal();
- if (exp instanceof SingleMemberAnnotation) {
- exp = ((SingleMemberAnnotation) exp).getValue();
- } else if (exp instanceof NormalAnnotation) {
- List<?> values = ((NormalAnnotation) exp).values();
+ if (exp instanceof SingleMemberAnnotation singlememberannotation) {
+ exp = (singlememberannotation).getValue();
+ } else if (exp instanceof NormalAnnotation normalannotation) {
+ List<?> values = (normalannotation).values();
for (Object value : values) {
MemberValuePair pair = (MemberValuePair) value;
if ("uri".equals(pair.getName().toString())) {
diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelXmlHelper.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelXmlHelper.java
index ec7e0bc4a988..b9e222f2085e 100644
--- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelXmlHelper.java
+++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelXmlHelper.java
@@ -188,8 +188,8 @@ public final class CamelXmlHelper {
Element selectedElement = null;
if (root != null) {
Node selectedNode = findCamelNodeInDocument(root, key);
- if (selectedNode instanceof Element) {
- selectedElement = (Element) selectedNode;
+ if (selectedNode instanceof Element element) {
+ selectedElement = element;
}
}
return selectedElement;
diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/ParserCommon.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/ParserCommon.java
index 3f3d97607a85..086d9cea93e0 100644
--- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/ParserCommon.java
+++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/ParserCommon.java
@@ -82,8 +82,8 @@ public final class ParserCommon {
if (node instanceof MethodDeclaration) {
node = node.getParent();
}
- if (node instanceof AnonymousClassDeclaration) {
- List<?> declarations = ((AnonymousClassDeclaration) node).bodyDeclarations();
+ if (node instanceof AnonymousClassDeclaration anonymousclassdeclaration) {
+ List<?> declarations = (anonymousclassdeclaration).bodyDeclarations();
for (Object dec : declarations) {
if (dec instanceof FieldDeclaration fd) {
final Type type = fd.getType();
@@ -118,8 +118,8 @@ public final class ParserCommon {
public static boolean isNumericOperator(JavaClassSource clazz, Block block, Expression expression) {
if (expression instanceof NumberLiteral) {
return true;
- } else if (expression instanceof SimpleName) {
- FieldSource<JavaClassSource> field = getField(clazz, block, (SimpleName) expression);
+ } else if (expression instanceof SimpleName simplename) {
+ FieldSource<JavaClassSource> field = getField(clazz, block, simplename);
if (field != null) {
return field.getType().isType("int") || field.getType().isType("long")
|| field.getType().isType("Integer") || field.getType().isType("Long");