gnodet commented on code in PR #11284:
URL: https://github.com/apache/maven/pull/11284#discussion_r2438594373


##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java:
##########
@@ -21,10 +21,7 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.io.StringWriter;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;

Review Comment:
   ?



##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlService.java:
##########
@@ -164,9 +164,12 @@ public static XmlNode read(XMLStreamReader reader, 
@Nullable InputLocationBuilde
 
     /**
      * Writes an XML node to a writer.
+     *
+     * @return writer instance.
      */
-    public static void write(XmlNode node, Writer writer) throws IOException {
+    public static Writer write(XmlNode node, Writer writer) throws IOException 
{

Review Comment:
   ?



##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java:
##########
@@ -449,11 +446,11 @@ public Builder inputLocation(Object inputLocation) {
          * @return a new immutable XmlNode instance
          * @throws NullPointerException if name has not been set
          */
-        public XmlNode build() {
+        XmlNode build() {

Review Comment:
   ?



##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java:
##########
@@ -449,11 +446,11 @@ public Builder inputLocation(Object inputLocation) {
          * @return a new immutable XmlNode instance
          * @throws NullPointerException if name has not been set
          */
-        public XmlNode build() {
+        XmlNode build() {
             return new Impl(prefix, namespaceUri, name, value, attributes, 
children, inputLocation);
         }
 
-        private record Impl(
+        record Impl(

Review Comment:
   ?



##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java:
##########
@@ -463,7 +460,7 @@ private record Impl(
                 Object inputLocation)
                 implements XmlNode, Serializable {
 
-            private Impl {
+            Impl {

Review Comment:
   ?



##########
api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java:
##########
@@ -509,40 +506,45 @@ public int hashCode() {
             @Override
             public String toString() {
                 try {
-                    StringWriter writer = new StringWriter();
-                    XmlService.write(this, writer);
-                    return writer.toString();
-                } catch (IOException e) {
-                    return toStringObject();
+                    return XmlService.write(this, new 
StringWriter()).toString();
+                } catch (IOException ignored) {
+                    return addToStringField(
+                                    new StringJoiner(", ", "XmlNode[", "]"),
+                                    prefix,
+                                    namespaceUri,
+                                    name,
+                                    value,
+                                    attributes,
+                                    children,
+                                    inputLocation)
+                            .toString();
                 }
             }
 
-            private String toStringObject() {
-                StringBuilder sb = new StringBuilder();
-                sb.append("XmlNode[");
-                boolean w = false;
-                w = addToStringField(sb, prefix, o -> !o.isEmpty(), "prefix", 
w);
-                w = addToStringField(sb, namespaceUri, o -> !o.isEmpty(), 
"namespaceUri", w);
-                w = addToStringField(sb, name, o -> !o.isEmpty(), "name", w);
-                w = addToStringField(sb, value, o -> !o.isEmpty(), "value", w);
-                w = addToStringField(sb, attributes, o -> !o.isEmpty(), 
"attributes", w);
-                w = addToStringField(sb, children, o -> !o.isEmpty(), 
"children", w);
-                w = addToStringField(sb, inputLocation, Objects::nonNull, 
"inputLocation", w);
-                sb.append("]");
-                return sb.toString();
+            public static StringJoiner addToStringField(

Review Comment:
   public is wrong
   static is wrong, it will avoid passing all fields as arguments 



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