You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2024/01/11 05:12:31 UTC
(groovy) branch master updated: GROOVY-11269: GroovyClassDoc has empty 'enumConstants' (add test case)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 4e6359526d GROOVY-11269: GroovyClassDoc has empty 'enumConstants' (add test case)
4e6359526d is described below
commit 4e6359526d48d1babb74dfc91da55d070aa3aeba
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jan 11 15:12:11 2024 +1000
GROOVY-11269: GroovyClassDoc has empty 'enumConstants' (add test case)
---
.../org/apache/groovy/antlr/GroovydocVisitor.java | 2 +-
.../gstringTemplates/classLevel/classDocName.html | 48 +++++++++++-----------
.../groovy/tools/groovydoc/GroovyDocToolTest.java | 3 +-
3 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
index 12b1257c9c..3f2f65e8d1 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
@@ -376,7 +376,7 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport {
processModifiers(fieldDoc, node, node.getModifiers());
processAnnotations(fieldDoc, node);
fieldDoc.setRawCommentText(getDocContent(node.getGroovydoc()));
- if (currentClassDoc.isEnum()) {
+ if (node.isEnum()) {
currentClassDoc.addEnumConstant(fieldDoc);
} else {
currentClassDoc.add(fieldDoc);
diff --git a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
index 8328fb4292..67937207f2 100644
--- a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
+++ b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
@@ -56,12 +56,12 @@
}
def linkfull = { t -> dolink(t, true) }
def linkable = { t -> dolink(t, false) }
- def modifiersWithOptions = { t, boolean ignorePublic, boolean ignoreAbstract ->
+ def modifiersWithOptions = { t, boolean ignorePublic, boolean ignoreAbstract, boolean ignoreFinal=false, boolean ignoreStatic=false ->
(t.isPrivate()?"private ":"") +
(t.isPublic() && !ignorePublic?"public ":"") +
(t.isProtected()?"protected ":"") +
- (t.isStatic()?"static ":"") +
- (t.isFinal()?"final ":"") +
+ (t.isStatic() && !ignoreStatic ?"static ":"") +
+ (t.isFinal() && !ignoreFinal?"final ":"") +
(!ignoreAbstract && t.respondsTo('isAbstract') && t.isAbstract()?"abstract ":"")
}
def modifiers = { t -> modifiersWithOptions(t, classDoc.isGroovy(), false) }
@@ -157,14 +157,14 @@ if (location.href.indexOf('is-external=true') == -1) {
if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %> <%
} else {
if (classDoc.isEnum()) {
- if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
+ if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
}
- if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
- if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %> <%
+ if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
+ if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %> <%
if (classDoc.isClass()) {
- if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
+ if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
}
- if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
+ if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
}
%>
</ul>
@@ -232,7 +232,7 @@ if (classDoc.isInterface()) {
<hr>
<%
def declaration = annotations(classDoc, '\n') +
- modifiersWithOptions(classDoc, classDoc.isGroovy(), classDoc.isInterface() || classDoc.isAnnotationType()) +
+ modifiersWithOptions(classDoc, classDoc.isGroovy(), classDoc.isInterface() || classDoc.isAnnotationType(), classDoc.isEnum(), false) +
classDoc.typeSourceDescription +
" ${nameEncoded}"
final interfaces = classDoc.interfaces().collect{ linkable(it) }.join(', ')
@@ -565,7 +565,7 @@ if (classDoc.isInterface() && classDoc.interfaces()) {
<a name="${ec.name()}"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
- <h4>${modifiers(ec) + '<a href="' + classDoc.relativeRootPath + classDoc.fullPathName + '.html">' + classDoc.name() + '</a>'} <strong>${ec.name()}</strong></h4>
+ <h4>${annotations(ec, '<br>') + modifiersWithOptions(ec, true, true, true, true) + '<a href="' + classDoc.relativeRootPath + classDoc.fullPathName + '.html">' + classDoc.name() + '</a>'} <strong>${ec.name()}</strong></h4>
<p>${ec.commentText()}</p>
</li>
</ul>
@@ -710,19 +710,19 @@ if (classDoc.isInterface() && classDoc.interfaces()) {
if (classDoc.isAnnotationType()) {
def hasReq = classDoc.fields().any{ isRequired(it, "true") }
def hasOpt = classDoc.fields().any{ isRequired(it, "false") }
- if (hasReq) { %><li><a href="#required_element_summary"><% } %>Required<% if (hasReq) { %></a></li><% } %> <%
- if (hasOpt) { %><li><a href="#optional_element_summary"><% } %>Optional<% if (hasOpt) { %></a></li><% } %> <%
+ if (hasReq) { %><li><a href="#required_element_summary"><% } %>Required<% if (hasReq) { %></a></li><% } %> <%
+ if (hasOpt) { %><li><a href="#optional_element_summary"><% } %>Optional<% if (hasOpt) { %></a></li><% } %> <%
} else {
- if (visibleNested) { %><li><a href="#nested_summary"><% } %>Nested<% if (visibleNested) { %></a></li><% } %> <%
+ if (visibleNested) { %><li><a href="#nested_summary"><% } %>Nested<% if (visibleNested) { %></a></li><% } %> <%
if (classDoc.isEnum()) {
- if (hasEnumConstants) { %><li><a href="#enum_constant_summary"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
+ if (hasEnumConstants) { %><li><a href="#enum_constant_summary"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
}
- if (hasFields) { %><li><a href="#field_summary"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
- if (hasProperties) { %><li><a href="#property_summary">Property</a></li><% } %> <%
+ if (hasFields) { %><li><a href="#field_summary"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
+ if (hasProperties) { %><li><a href="#property_summary">Property</a></li><% } %> <%
if (classDoc.isClass()) {
- if (visibleConstructors) { %><li><a href="#constructor_summary"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
+ if (visibleConstructors) { %><li><a href="#constructor_summary"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
}
- if (visibleMethods) { %><li><a href="#method_summary"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
+ if (visibleMethods) { %><li><a href="#method_summary"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
}
%>
</ul>
@@ -730,17 +730,17 @@ if (classDoc.isInterface() && classDoc.interfaces()) {
<li> | Detail: </li>
<%
if (classDoc.isAnnotationType()) {
- if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %> <%
+ if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %> <%
} else {
if (classDoc.isEnum()) {
- if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
+ if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %> <%
}
- if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
- if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %> <%
+ if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %> <%
+ if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %> <%
if (classDoc.isClass()) {
- if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
+ if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %> <%
}
- if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
+ if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %> <%
}
%>
</ul>
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 86eb165b50..2ba78271cd 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -685,7 +685,7 @@ public class GroovyDocToolTest extends GroovyTestCase {
assertEquals("There has to be a reference to class Enum", "Enum", m.group(3));
}
- public void testEnumInitNotDocumented() throws Exception {
+ public void testEnumConstantsDocumentedAndInitNotDocumented() throws Exception {
final String base = "org/codehaus/groovy/tools/groovydoc/testfiles";
final String klass = "EnumWithDeprecatedConstants";
htmlTool.add(Arrays.asList(
@@ -696,6 +696,7 @@ public class GroovyDocToolTest extends GroovyTestCase {
htmlTool.renderToOutput(output, MOCK_DIR);
final String groovydoc = output.getText(MOCK_DIR + "/" + base + "/"+ klass +".html");
+ assertTrue(groovydoc.matches("(?s).*<table .*summary=\"Enum constants summary table\".*>bar<.*<\\/table>.*"));
final Matcher ctor = Pattern.compile(Pattern.quote("$INIT")).matcher(groovydoc);