tkalkirill commented on code in PR #4152:
URL: https://github.com/apache/ignite-3/pull/4152#discussion_r1696967972


##########
modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/serialization/MessageDeserializerGenerator.java:
##########
@@ -181,9 +186,33 @@ private CodeBlock readMessageCodeBlock(ExecutableElement 
getter) {
             varType = TypeName.get(getter.getReturnType());
         }
 
-        return CodeBlock.builder()
-                .add("$T tmp = reader.", varType)
-                .add(methodResolver.resolveReadMethod(getter))
-                .build();
+        if (typeUtils.isEnum(getter.getReturnType())) {
+            checkFromOrdinalMethodExists(getter.getReturnType());
+
+            return CodeBlock.builder()
+                    .add("int ordinal = reader.readInt($S);", 
getter.getSimpleName().toString())
+                    .add("\n")
+                    .add("$T tmp = ordinal <= 0 ? null : $T.$L(ordinal - 1)", 
varType, varType, FROM_ORDINAL_METHOD_NAME)
+                    .build();
+        } else {
+            return CodeBlock.builder()
+                    .add("$T tmp = reader.", varType)
+                    .add(methodResolver.resolveReadMethod(getter))
+                    .build();
+        }
+    }
+
+    private void checkFromOrdinalMethodExists(TypeMirror enumType) {
+        assert typeUtils.isEnum(enumType) : enumType;
+
+        typeUtils.types().asElement(enumType).getEnclosedElements().stream()
+                .filter(element -> element.getKind() == ElementKind.METHOD)
+                .filter(element -> 
element.getSimpleName().toString().equals(FROM_ORDINAL_METHOD_NAME))
+                .filter(element -> 
element.getModifiers().contains(Modifier.PUBLIC))
+                .filter(element -> 
element.getModifiers().contains(Modifier.STATIC))
+                .findAny()
+                .orElseThrow(() -> new ProcessingException(
+                        String.format("Missing public static method \"%s\" for 
enum %s", FROM_ORDINAL_METHOD_NAME, enumType)
+                ));
     }
-}
+}

Review Comment:
   fix it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to