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

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x-build-tools.git


The following commit(s) were added to refs/heads/develop by this push:
     new c0bfadc  feat: use some modern language features
c0bfadc is described below

commit c0bfadc4927c4a13220da6bbc61993fdd64ddd54
Author: Sebastian Rühl <sru...@apache.org>
AuthorDate: Mon Sep 1 10:16:29 2025 +0200

    feat: use some modern language features
---
 .../types/fields/FieldConversions.java             | 18 ++++--------
 .../types/references/TypeReference.java            |  3 +-
 .../plugins/codegenerator/types/terms/Term.java    | 34 +++++++++++++---------
 3 files changed, 28 insertions(+), 27 deletions(-)

diff --git 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/fields/FieldConversions.java
 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/fields/FieldConversions.java
index 65c6747..1d7bb7d 100644
--- 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/fields/FieldConversions.java
+++ 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/fields/FieldConversions.java
@@ -351,12 +351,10 @@ public interface FieldConversions {
      * is instance of {@link ManualArrayField} with {@link 
ManualArrayField.LoopType}{@code .COUNT}
      */
     default boolean isCountArrayField() {
-        if (this instanceof ArrayField) {
-            ArrayField arrayField = (ArrayField) this;
+        if (this instanceof ArrayField arrayField) {
             return arrayField.getLoopType() == ArrayField.LoopType.COUNT;
         }
-        if (this instanceof ManualArrayField) {
-            ManualArrayField arrayField = (ManualArrayField) this;
+        if (this instanceof ManualArrayField arrayField) {
             return arrayField.getLoopType() == ManualArrayField.LoopType.COUNT;
         }
         return false;
@@ -367,12 +365,10 @@ public interface FieldConversions {
      * is instance of {@link ManualArrayField} with {@link 
ManualArrayField.LoopType}{@code .LENGTH}
      */
     default boolean isLengthArrayField() {
-        if (this instanceof ArrayField) {
-            ArrayField arrayField = (ArrayField) this;
+        if (this instanceof ArrayField arrayField) {
             return arrayField.getLoopType() == ArrayField.LoopType.LENGTH;
         }
-        if (this instanceof ManualArrayField) {
-            ManualArrayField arrayField = (ManualArrayField) this;
+        if (this instanceof ManualArrayField arrayField) {
             return arrayField.getLoopType() == 
ManualArrayField.LoopType.LENGTH;
         }
         return false;
@@ -383,12 +379,10 @@ public interface FieldConversions {
      * is instance of {@link ManualArrayField} with {@link 
ManualArrayField.LoopType}{@code .TERMINATED}
      */
     default boolean isTerminatedArrayField() {
-        if (this instanceof ArrayField) {
-            ArrayField arrayField = (ArrayField) this;
+        if (this instanceof ArrayField arrayField) {
             return arrayField.getLoopType() == ArrayField.LoopType.TERMINATED;
         }
-        if (this instanceof ManualArrayField) {
-            ManualArrayField arrayField = (ManualArrayField) this;
+        if (this instanceof ManualArrayField arrayField) {
             return arrayField.getLoopType() == 
ManualArrayField.LoopType.TERMINATED;
         }
         return false;
diff --git 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/references/TypeReference.java
 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/references/TypeReference.java
index 2ca0a8f..e058097 100644
--- 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/references/TypeReference.java
+++ 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/references/TypeReference.java
@@ -42,10 +42,9 @@ public interface TypeReference extends 
TypeReferenceConversions {
             return Optional.of(this);
         }
         // If we're accessing a child, then the root must be a complex type.
-        if (!(this instanceof ComplexTypeReference)) {
+        if (!(this instanceof ComplexTypeReference complexTypeReference)) {
             return Optional.empty();
         }
-        ComplexTypeReference complexTypeReference = (ComplexTypeReference) 
this;
         final ComplexTypeDefinition complexTypeDefinition = 
complexTypeReference.getTypeDefinition();
         VariableLiteral childVariableLiteral = 
variableLiteral.getChild().get();
         return 
complexTypeDefinition.getTypeReferenceForProperty(childVariableLiteral.getName())
diff --git 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/terms/Term.java
 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/terms/Term.java
index 8f3150b..b8f4729 100644
--- 
a/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/terms/Term.java
+++ 
b/code-generation/types-base/src/main/java/org/apache/plc4x/plugins/codegenerator/types/terms/Term.java
@@ -65,19 +65,27 @@ public interface Term extends TermConversions {
     default String getDiscriminatorName() {
         if (isLiteral()) {
             Literal literal = (Literal) this;
-            if (literal instanceof NullLiteral) {
-                return "null";
-            } else if (literal instanceof BooleanLiteral) {
-                return Boolean.toString(((BooleanLiteral) literal).getValue());
-            } else if (literal instanceof NumericLiteral) {
-                return ((NumericLiteral) literal).getNumber().toString();
-            } else if (literal instanceof HexadecimalLiteral) {
-                return ((HexadecimalLiteral) literal).getHexString();
-            } else if (literal instanceof StringLiteral) {
-                return ((StringLiteral) literal).getValue();
-            } else if (literal instanceof VariableLiteral) {
-                VariableLiteral variableLiteral = (VariableLiteral) literal;
-                return variableLiteral.getVariableLiteralName();
+            switch (literal) {
+                case NullLiteral nullLiteral -> {
+                    return "null";
+                }
+                case BooleanLiteral booleanLiteral -> {
+                    return Boolean.toString(booleanLiteral.getValue());
+                }
+                case NumericLiteral numericLiteral -> {
+                    return numericLiteral.getNumber().toString();
+                }
+                case HexadecimalLiteral hexadecimalLiteral -> {
+                    return hexadecimalLiteral.getHexString();
+                }
+                case StringLiteral stringLiteral -> {
+                    return stringLiteral.getValue();
+                }
+                case VariableLiteral variableLiteral -> {
+                    return variableLiteral.getVariableLiteralName();
+                }
+                default -> {
+                }
             }
         } else if (isUnaryTerm()) {
             UnaryTerm unaryTerm = (UnaryTerm) this;

Reply via email to