From 9ca83da878ab868de315b961e8b8e3387566ea48 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 Apr 2018 12:05:31 +0200 Subject: [PATCH] [doc] Surround the delimiter with spaces, so that the browser can wrap the default value of multi properties nicely. --- .../net/sourceforge/pmd/docs/RuleDocGenerator.java | 11 +++++++++-- pmd-doc/src/test/resources/expected/sample.md | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java index ba2cc61918..6fd710ec7e 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java @@ -28,6 +28,7 @@ import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; @@ -435,8 +436,14 @@ public class RuleDocGenerator { if (propertyDescriptor.defaultValue() != null) { if (propertyDescriptor.isMultiValue()) { @SuppressWarnings("unchecked") // multi valued properties are using a List - PropertyDescriptor> multiPropertyDescriptor = (PropertyDescriptor>) propertyDescriptor; + MultiValuePropertyDescriptor> multiPropertyDescriptor = (MultiValuePropertyDescriptor>) propertyDescriptor; defaultValue = multiPropertyDescriptor.asDelimitedString(multiPropertyDescriptor.defaultValue()); + + // surround the delimiter with spaces, so that the browser can wrap + // the value nicely + defaultValue = defaultValue.replaceAll(Pattern.quote( + String.valueOf(multiPropertyDescriptor.multiValueDelimiter())), + " " + multiPropertyDescriptor.multiValueDelimiter() + " "); } else { defaultValue = String.valueOf(propertyDescriptor.defaultValue()); } @@ -447,7 +454,7 @@ public class RuleDocGenerator { MultiValuePropertyDescriptor multiValuePropertyDescriptor = (MultiValuePropertyDescriptor) propertyDescriptor; multiValued = "yes. Delimiter is '" - + multiValuePropertyDescriptor.multiValueDelimiter() + "'"; + + multiValuePropertyDescriptor.multiValueDelimiter() + "'."; } lines.add("|" + propertyDescriptor.name() diff --git a/pmd-doc/src/test/resources/expected/sample.md b/pmd-doc/src/test/resources/expected/sample.md index 0a1a49c7d3..63d5b57f0d 100644 --- a/pmd-doc/src/test/resources/expected/sample.md +++ b/pmd-doc/src/test/resources/expected/sample.md @@ -63,7 +63,7 @@ public class JumbledIncrementerRule1 { |Name|Default Value|Description|Multivalued| |----|-------------|-----------|-----------| |sampleAdditionalProperty|the value|This is a additional property for tests|no| -|sampleMultiStringProperty|Value1\|Value2|Test property with multiple strings|yes. Delimiter is '\|'| +|sampleMultiStringProperty|Value1 \| Value2|Test property with multiple strings|yes. Delimiter is '\|'.| |sampleDeprecatedProperty|test|Deprecated This is a sample deprecated property for tests|no| **Use this rule by referencing it:** @@ -201,7 +201,7 @@ public class JumbledIncrementerRule1 { |Name|Default Value|Description|Multivalued| |----|-------------|-----------|-----------| |sampleAdditionalProperty|the value|This is a additional property for tests|no| -|sampleMultiStringProperty|Value1\|Value2|Test property with multiple strings|yes. Delimiter is '\|'| +|sampleMultiStringProperty|Value1 \| Value2|Test property with multiple strings|yes. Delimiter is '\|'.| |sampleDeprecatedProperty|test|Deprecated This is a sample deprecated property for tests|no| **Use this rule by referencing it:**