Fixed SkylarkDoc.getDocumentation to append a period to the doc string if it is missing.
Fixes #1522.
--
Change-Id: Ib94c1544cb0862f40beeeadb60780da1a47dfc66
Reviewed-on: https://bazel-review.googlesource.com/#/c/4042
MOS_MIGRATED_REVID=128807763
diff --git a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java
index 01f84e7..e8b7d32 100644
--- a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java
+++ b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java
@@ -22,9 +22,9 @@
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
-
import java.util.Arrays;
import java.util.Map;
+import java.util.regex.Pattern;
/**
* Abstract class for containing documentation for a Skylark syntactic entity.
@@ -38,10 +38,26 @@
public abstract String getName();
/**
- * Returns a string containing the HTML documentation of the entity being
- * documented.
+ * Returns a string containing the formatted HTML documentation of the entity being documented.
*/
- public abstract String getDocumentation();
+ public String getDocumentation() {
+ String doc = getEntityDocumentation();
+ if (doc == null || doc.length() == 0) {
+ return "";
+ }
+
+ // Check if valid punctiation is not present at the end of the documentation.
+ if (!Pattern.matches("[.?!]$", doc)) {
+ // Add a final period.
+ doc += ".";
+ }
+ return doc;
+ }
+
+ /**
+ * Returns a string containing the HTML documentation of the entity, before being post-processed.
+ */
+ protected abstract String getEntityDocumentation();
protected String getTypeAnchor(Class<?> returnType, Class<?> generic1) {
return getTypeAnchor(returnType) + " of " + getTypeAnchor(generic1) + "s";