This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf-xjc-utils.git


The following commit(s) were added to refs/heads/main by this push:
     new 7641ced  Normalize whitespace in multiline XSD documentation for 
javadoc (#304)
7641ced is described below

commit 7641cedf10dbee25108fbe3bf4beacec2cbcab96
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Apr 4 00:54:45 2026 +0200

    Normalize whitespace in multiline XSD documentation for javadoc (#304)
    
    When XSD documentation spans multiple lines with indentation, the
    generated javadoc preserved the leading whitespace on continuation
    lines, producing sloppy output. Trim each line individually so that
    multiline documentation renders cleanly in javadoc comments.
    
    Closes #6
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../apache/cxf/xjc/javadoc/PropertyJavadoc.java    | 17 ++++++-
 .../cxf/xjc/javadoc/PropertyJavadocTest.java       | 53 ++++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)

diff --git 
a/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java 
b/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java
index 4ecc890..6783d7f 100644
--- a/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java
+++ b/javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java
@@ -63,7 +63,7 @@ public class PropertyJavadoc {
         if (documentation == null || "".equals(documentation.trim())) {
             return;
         }
-        setJavadoc(documentation.trim());
+        setJavadoc(trimLines(documentation));
     }
 
     private XSComponent getDocumentedComponent(CPropertyInfo propertyInfo) {
@@ -77,6 +77,21 @@ public class PropertyJavadoc {
         }
     }
 
+    static String trimLines(String text) {
+        String[] lines = text.split("\n");
+        StringBuilder sb = new StringBuilder();
+        for (String line : lines) {
+            String trimmed = line.trim();
+            if (!trimmed.isEmpty()) {
+                if (sb.length() > 0) {
+                    sb.append('\n');
+                }
+                sb.append(trimmed);
+            }
+        }
+        return sb.toString();
+    }
+
     private void setJavadoc(String documentation) {
         setJavadocToField(documentation);
         setJavadocToGetter(documentation);
diff --git 
a/javadoc/src/test/java/org/apache/cxf/xjc/javadoc/PropertyJavadocTest.java 
b/javadoc/src/test/java/org/apache/cxf/xjc/javadoc/PropertyJavadocTest.java
new file mode 100644
index 0000000..76992de
--- /dev/null
+++ b/javadoc/src/test/java/org/apache/cxf/xjc/javadoc/PropertyJavadocTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.cxf.xjc.javadoc;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PropertyJavadocTest {
+
+    @Test
+    public void trimLinesSingleLine() {
+        assertEquals("hello", PropertyJavadoc.trimLines("  hello  "));
+    }
+
+    @Test
+    public void trimLinesMultiline() {
+        assertEquals("Multiline documentation of\nattribute",
+                PropertyJavadoc.trimLines("\n                    Multiline 
documentation of\n"
+                        + "                    attribute\n                "));
+    }
+
+    @Test
+    public void trimLinesPreservesInternalSpaces() {
+        assertEquals("hello   world", PropertyJavadoc.trimLines("  hello   
world  "));
+    }
+
+    @Test
+    public void trimLinesSkipsBlankLines() {
+        assertEquals("line one\nline two", PropertyJavadoc.trimLines("  line 
one  \n\n  line two  "));
+    }
+
+    @Test
+    public void trimLinesEmpty() {
+        assertEquals("", PropertyJavadoc.trimLines("   \n   \n   "));
+    }
+}

Reply via email to