anton-vinogradov commented on code in PR #13095: URL: https://github.com/apache/ignite/pull/13095#discussion_r3559769700
########## modules/codegen/src/main/java/org/apache/ignite/internal/MessageGenerator.java: ########## @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; + +/** + * Base class for message code generators ({@link MessageSerializerGenerator}, {@link MessageMarshallerGenerator}, + * {@link MessageDeploymentGenerator}). + */ +public abstract class MessageGenerator { + /** Blank separator line in generated code. */ + public static final String EMPTY = ""; Review Comment: Because the accumulated entries are terminator-free lines: `buildClassCode` writes each as `line + NL`. A separator entry therefore has to be the empty string — using `NL` would render as a double blank line. ########## modules/codegen/src/main/java/org/apache/ignite/internal/MessageGenerator.java: ########## @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; + +/** + * Base class for message code generators ({@link MessageSerializerGenerator}, {@link MessageMarshallerGenerator}, + * {@link MessageDeploymentGenerator}). + */ +public abstract class MessageGenerator { + /** Blank separator line in generated code. */ + public static final String EMPTY = ""; + + /** Platform line separator used in generated code. */ + public static final String NL = System.lineSeparator(); + + /** Single indentation unit. */ + public static final String TAB = " "; + + /** Javadoc stub emitted on every generated {@code @Override} method. */ + public static final String METHOD_JAVADOC = "/** */"; + + /** Javadoc block emitted on every generated class. */ + public static final String CLS_JAVADOC = "/**" + NL + + " * This class is generated automatically." + NL + + " *" + NL + + " * @see org.apache.ignite.internal.MessageProcessor" + NL + Review Comment: Even better — it's a same-module class, so now it's `MessageProcessor.class.getName()`: survives renames instead of a frozen string. ########## modules/codegen/src/main/java/org/apache/ignite/internal/MessageGenerator.java: ########## @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; + +/** + * Base class for message code generators ({@link MessageSerializerGenerator}, {@link MessageMarshallerGenerator}, + * {@link MessageDeploymentGenerator}). + */ +public abstract class MessageGenerator { + /** Blank separator line in generated code. */ + public static final String EMPTY = ""; + + /** Platform line separator used in generated code. */ + public static final String NL = System.lineSeparator(); + + /** Single indentation unit. */ + public static final String TAB = " "; + + /** Javadoc stub emitted on every generated {@code @Override} method. */ + public static final String METHOD_JAVADOC = "/** */"; + + /** Javadoc block emitted on every generated class. */ + public static final String CLS_JAVADOC = "/**" + NL + + " * This class is generated automatically." + NL + + " *" + NL + + " * @see org.apache.ignite.internal.MessageProcessor" + NL + + " */"; + + /** */ + final ProcessingEnvironment env; + + /** */ + final Set<String> imports = new TreeSet<>(); + + /** */ + TypeElement type; + + /** Current indentation level. Set to the class-member level once in {@link #generate}; adjusted only by balanced shifts. */ + int indent; + + /** Dispatches cache-object-context resolution in both the marshaller and the deployment generators. */ + final TypeMirror cacheIdAwareMirror; + + /** */ + MessageGenerator(ProcessingEnvironment env) { + this.env = env; + + cacheIdAwareMirror = type("org.apache.ignite.plugin.extensions.communication.CacheIdAware"); Review Comment: Can't be a `Class` reference — `CacheIdAware` lives in core, which isn't on the codegen classpath (that's exactly why external types are looked up as FQN-string mirrors). And per the sibling thread in `MessageDeploymentGenerator` we've just unified all single-use type FQNs to plain strings, so a String constant would go against that. ########## modules/codegen/src/main/java/org/apache/ignite/internal/MessageGenerator.java: ########## @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; + +/** + * Base class for message code generators ({@link MessageSerializerGenerator}, {@link MessageMarshallerGenerator}, + * {@link MessageDeploymentGenerator}). + */ +public abstract class MessageGenerator { + /** Blank separator line in generated code. */ + public static final String EMPTY = ""; + + /** Platform line separator used in generated code. */ + public static final String NL = System.lineSeparator(); + + /** Single indentation unit. */ + public static final String TAB = " "; + + /** Javadoc stub emitted on every generated {@code @Override} method. */ + public static final String METHOD_JAVADOC = "/** */"; + + /** Javadoc block emitted on every generated class. */ + public static final String CLS_JAVADOC = "/**" + NL + + " * This class is generated automatically." + NL + + " *" + NL + + " * @see org.apache.ignite.internal.MessageProcessor" + NL + + " */"; + + /** */ + final ProcessingEnvironment env; Review Comment: Visibility here is "tightest that works": `public` only for what's genuinely used from another package (`NL`/`TAB` and the static helpers are imported by the `internal.idto` processors), package-private for everything the subclass generators and the processor need — they all share this package. `protected` would only widen access to hypothetical out-of-package subclasses. -- 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]
