Vladsz83 commented on code in PR #13461:
URL: https://github.com/apache/ignite/pull/13461#discussion_r3758484763


##########
modules/codegen/src/main/java/org/apache/ignite/internal/MessageMarshallerGenerator.java:
##########
@@ -1156,18 +1156,78 @@ private enum MarshalledKind {
             return null;
         }
 
+        MarshalledKind res;
+
         if (map)
-            return MarshalledKind.MAP;
+            res = MarshalledKind.MAP;
+        else {
+            TypeMirror wire = requireEnclosed(enclosed, ann.value(), 
"@Marshalled").asType();

Review Comment:
   Just a notise. Annotation here look as something important. Important to 
search. But is onle for the error.



##########
modules/codegen/src/main/java/org/apache/ignite/internal/MessageMarshallerGenerator.java:
##########
@@ -1156,18 +1156,78 @@ private enum MarshalledKind {
             return null;
         }
 
+        MarshalledKind res;
+
         if (map)
-            return MarshalledKind.MAP;
+            res = MarshalledKind.MAP;
+        else {
+            TypeMirror wire = requireEnclosed(enclosed, ann.value(), 
"@Marshalled").asType();
+
+            if (wire.getKind() == TypeKind.ARRAY) {
+                res = ((ArrayType)wire).getComponentType().getKind() == 
TypeKind.BYTE
+                    ? MarshalledKind.BLOB
+                    : MarshalledKind.ELEMENTS;
+            }
+            else
+                res = MarshalledKind.ELEMENT_BLOBS;
+        }
+
+        /*
+         * Ensures that field annotated with {@link Marshalled} doesn't 
perform {@code Message} -> {@code byte[]} transformation
+         * which escapes {@link Order} and other rules implemented on top of 
communication {@code MessageWriter, MessageReader} logic.
+         */
+        if (foundMessageToBytesTransformation(field.asType(), field, ann)) {
+            env.getMessager().printMessage(Diagnostic.Kind.ERROR,
+                "Message must be written by dedicated message serializers. " +
+                    "Remove @" + Marshalled.class.getSimpleName() + " 
annotation and remove companion field.", field);
+        }
+
+        return res;
+    }
+
+    /**
+     * Recursively checks no {@code Message} -> {@code byte[]} transformation.
+     * @return {@code True} in case error transformation found.
+     */
+    private boolean foundMessageToBytesTransformation(TypeMirror type, 
VariableElement field, Marshalled ann) {
+        if (assignableFrom(type, msgType))
+            return true;
+        else if (isCollection(type)) {

Review Comment:
   Nexy line and not `else`



##########
modules/codegen/src/main/java/org/apache/ignite/internal/MessageMarshallerGenerator.java:
##########
@@ -1156,18 +1156,78 @@ private enum MarshalledKind {
             return null;
         }
 
+        MarshalledKind res;
+
         if (map)
-            return MarshalledKind.MAP;
+            res = MarshalledKind.MAP;
+        else {
+            TypeMirror wire = requireEnclosed(enclosed, ann.value(), 
"@Marshalled").asType();
+
+            if (wire.getKind() == TypeKind.ARRAY) {
+                res = ((ArrayType)wire).getComponentType().getKind() == 
TypeKind.BYTE
+                    ? MarshalledKind.BLOB
+                    : MarshalledKind.ELEMENTS;
+            }
+            else
+                res = MarshalledKind.ELEMENT_BLOBS;
+        }
+
+        /*
+         * Ensures that field annotated with {@link Marshalled} doesn't 
perform {@code Message} -> {@code byte[]} transformation
+         * which escapes {@link Order} and other rules implemented on top of 
communication {@code MessageWriter, MessageReader} logic.
+         */
+        if (foundMessageToBytesTransformation(field.asType(), field, ann)) {
+            env.getMessager().printMessage(Diagnostic.Kind.ERROR,
+                "Message must be written by dedicated message serializers. " +
+                    "Remove @" + Marshalled.class.getSimpleName() + " 
annotation and remove companion field.", field);
+        }
+
+        return res;
+    }
+
+    /**
+     * Recursively checks no {@code Message} -> {@code byte[]} transformation.
+     * @return {@code True} in case error transformation found.
+     */
+    private boolean foundMessageToBytesTransformation(TypeMirror type, 
VariableElement field, Marshalled ann) {

Review Comment:
   Suggestion: Not `found...`. `search...`, `find...`, `ceck...` or even 
simplier `messageToBytesTransformation()`



##########
modules/codegen/src/main/java/org/apache/ignite/internal/MessageMarshallerGenerator.java:
##########
@@ -1156,18 +1156,78 @@ private enum MarshalledKind {
             return null;
         }
 
+        MarshalledKind res;
+
         if (map)
-            return MarshalledKind.MAP;
+            res = MarshalledKind.MAP;
+        else {
+            TypeMirror wire = requireEnclosed(enclosed, ann.value(), 
"@Marshalled").asType();
+
+            if (wire.getKind() == TypeKind.ARRAY) {
+                res = ((ArrayType)wire).getComponentType().getKind() == 
TypeKind.BYTE
+                    ? MarshalledKind.BLOB
+                    : MarshalledKind.ELEMENTS;
+            }
+            else
+                res = MarshalledKind.ELEMENT_BLOBS;
+        }
+
+        /*
+         * Ensures that field annotated with {@link Marshalled} doesn't 
perform {@code Message} -> {@code byte[]} transformation
+         * which escapes {@link Order} and other rules implemented on top of 
communication {@code MessageWriter, MessageReader} logic.
+         */
+        if (foundMessageToBytesTransformation(field.asType(), field, ann)) {
+            env.getMessager().printMessage(Diagnostic.Kind.ERROR,
+                "Message must be written by dedicated message serializers. " +
+                    "Remove @" + Marshalled.class.getSimpleName() + " 
annotation and remove companion field.", field);
+        }
+
+        return res;
+    }
+
+    /**
+     * Recursively checks no {@code Message} -> {@code byte[]} transformation.
+     * @return {@code True} in case error transformation found.
+     */
+    private boolean foundMessageToBytesTransformation(TypeMirror type, 
VariableElement field, Marshalled ann) {
+        if (assignableFrom(type, msgType))
+            return true;
+        else if (isCollection(type)) {
+            DeclaredType colType = (DeclaredType)type;
 
-        TypeMirror wire = requireEnclosed(enclosed, ann.value(), 
"@Marshalled").asType();
+            List<? extends TypeMirror> typeArgs = colType.getTypeArguments();
 
-        if (wire.getKind() == TypeKind.ARRAY) {
-            return ((ArrayType)wire).getComponentType().getKind() == 
TypeKind.BYTE
-                ? MarshalledKind.BLOB
-                : MarshalledKind.ELEMENTS;
+            if (typeArgs.size() != 1) {
+                env.getMessager().printMessage(Diagnostic.Kind.ERROR, "Raw 
collection not supported.", field);
+
+                return false;
+            }
+
+            return foundMessageToBytesTransformation(typeArgs.get(0), field, 
ann);
         }
+        else if (type.getKind() == TypeKind.ARRAY)

Review Comment:
   Same. No need of else`s.



-- 
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