Pankraz76 commented on code in PR #11284:
URL: https://github.com/apache/maven/pull/11284#discussion_r2436883747
##########
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);
Review Comment:
dry having 2 times the same fragile impl. is really crazy.
##########
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(
Review Comment:
high cohesion, low coupling (yes its now coupled but telling low not no so
this is the only way if considering SSOT)
##########
impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java:
##########
@@ -292,38 +290,18 @@ public int hashCode() {
@Override
public String toString() {
try {
- StringWriter writer = new StringWriter();
- XmlService.write(this, writer);
- return writer.toString();
- } catch (IOException e) {
- return toStringObject();
- }
- }
-
- public String toStringObject() {
- StringBuilder sb = new StringBuilder();
- sb.append("XmlNode[");
- boolean w = false;
- w = addToStringField(sb, prefix, o -> !o.isEmpty(), "prefix", w);
Review Comment:
dry having 2 times the same fragile impl. is really crazy.
--
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]