anton-vinogradov commented on code in PR #13095:
URL: https://github.com/apache/ignite/pull/13095#discussion_r3664493489


##########
modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java:
##########
@@ -93,159 +60,69 @@ public class MessageSerializerGenerator {
     private static final String COMPRESSED_MSG_ERROR = "CompressedMessage 
should not be used explicitly. " +
         "To compress the required field use the @Compress annotation.";
 
-    /** Collection of lines for {@code writeTo} method. */
+    /** */
     private final List<String> write = new ArrayList<>();
 
-    /** Collection of lines for {@code readFrom} method. */
-    private final List<String> read = new ArrayList<>();
-
-    /** Collection of message-specific imports. */
-    private final Set<String> imports = new TreeSet<>();
-
-    /** Collection of Serializer class fields containing mappers for message 
enum fields. */
-    private final Set<String> fields = new TreeSet<>();
-
     /** */
-    private final ProcessingEnvironment env;
-
-    /** Stored type of the message being processed. */
-    private TypeElement type;
-
-    /** The marshallable message type. */
-    private final TypeMirror marshallableMsgType;
+    private final List<String> read = new ArrayList<>();
 
-    /** */
-    private int indent;
+    /** Class-field declarations (enum mappers/values, collection descriptors) 
emitted at the top of the generated class. */
+    private final Set<String> clsFields = new TreeSet<>();
 
     /** */
     MessageSerializerGenerator(ProcessingEnvironment env) {
-        this.env = env;
-
-        marshallableMsgType = 
env.getElementUtils().getTypeElement(MARSHALLABLE_MESSAGE_INTERFACE).asType();
+        super(env);
     }
 
-    /** */
-    void generate(TypeElement type, List<VariableElement> fields) throws 
Exception {
-        assert this.type == null : "Message serializer generator isn't 
stateless and is supposed to be single-use.";
-
-        this.type = type;
+    /** {@inheritDoc} */
+    @Override String typeSuffix() {
+        return "Serializer";
+    }
 
+    /** {@inheritDoc} */
+    @Override void generateBody(List<VariableElement> fields) throws Exception 
{
         generateMethods(fields);
 
+        // Include superclass types in imports so generated code can cast to 
them for inherited fields.
         SystemViewRowAttributeWalkerProcessor.superclasses(env, 
type).forEach(el -> imports.add(el.toString()));
-
-        String serClsName = type.getSimpleName() + (marshallableMessage() ? 
"Marshallable" : "") + "Serializer";
-        String serFqnClsName = env.getElementUtils().getPackageOf(type) + "." 
+ serClsName;
-        String serCode = generateSerializerCode(serClsName);
-
-        try {
-            JavaFileObject file = 
env.getFiler().createSourceFile(serFqnClsName);
-
-            try (Writer writer = file.openWriter()) {
-                writer.append(serCode);
-                writer.flush();
-            }
-        }
-        catch (FilerException e) {
-            // IntelliJ IDEA parses Ignite's pom.xml and configures itself to 
use this annotation processor on each Run.
-            // During a Run, it invokes the processor and may fail when 
attempting to generate sources that already exist.
-            // There is no a setting to disable this invocation. The IntelliJ 
community suggests a workaround — delegating
-            // all Run commands to Maven. However, this significantly slows 
down test startup time.
-            // This hack checks whether the content of a generating file is 
identical to already existed file, and skips
-            // handling this class if it is.
-            if (!identicalFileIsAlreadyGenerated(env, serCode, serFqnClsName)) 
{
-                env.getMessager().printMessage(
-                    Diagnostic.Kind.ERROR,
-                    "MessageSerializer " + serClsName + " is already 
generated. Try 'mvn clean install' to fix the issue.");
-
-                throw e;
-            }
-        }
     }
 
-    /** Generates full code for a serializer class. */
-    private String generateSerializerCode(String serClsName) throws 
IOException {
-        if (marshallableMessage()) {
-            fields.add("private final Marshaller marshaller;");
-            fields.add("private final ClassLoader clsLdr;");
-        }
-
+    /** {@inheritDoc} */
+    @Override String buildClassCode(String serClsName) throws IOException {
         try (Writer writer = new StringWriter()) {
-            writeClassHeader(writer, 
env.getElementUtils().getPackageOf(type).toString(), serClsName);
+            imports.add(type.toString());
+            
imports.add("org.apache.ignite.plugin.extensions.communication.MessageSerializer");

Review Comment:
   Same sweep here — 15 constants for the Ignite types, JDK ones через 
Class#getName() as this file already did for Throwable and Set.



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