This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push: new d88aecf01c GROOVY-11269: GroovyClassDoc has empty 'enumConstants' d88aecf01c is described below commit d88aecf01cb3efc752b8b85ccc7fddec44e3b430 Author: Paul King <pa...@asert.com.au> AuthorDate: Thu Jan 11 14:18:13 2024 +1000 GROOVY-11269: GroovyClassDoc has empty 'enumConstants' --- .../groovy/org.apache.groovy-documented.gradle | 4 +- .../org/apache/groovy/antlr/GroovydocVisitor.java | 11 +++-- .../gstringTemplates/classLevel/classDocName.html | 48 +++++++++++----------- .../groovy/tools/groovydoc/GroovyDocToolTest.java | 3 +- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/build-logic/src/main/groovy/org.apache.groovy-documented.gradle b/build-logic/src/main/groovy/org.apache.groovy-documented.gradle index 75cc3b0a88..f95c1d65ee 100644 --- a/build-logic/src/main/groovy/org.apache.groovy-documented.gradle +++ b/build-logic/src/main/groovy/org.apache.groovy-documented.gradle @@ -56,7 +56,7 @@ tasks.withType(Javadoc).configureEach { encoding = 'UTF-8' version = true overview = project.relativePath(rootProject.file('src/main/java/overviewj.html')) - bottom = 'Copyright © 2003-2022 The Apache Software Foundation. All rights reserved.' + bottom = 'Copyright © 2003-2024 The Apache Software Foundation. All rights reserved.' source = sharedConfiguration.targetJavaVersion.get() links('https://docs.oracle.com/javase/8/docs/api/', 'https://docs.oracle.com/javaee/7/api/', @@ -75,7 +75,7 @@ tasks.withType(Groovydoc).configureEach { windowTitle = "Groovy ${versions.groovy}" docTitle = "Groovy ${versions.groovy}" header = "Groovy ${versions.groovy}" - footer = 'Copyright © 2003-2022 The Apache Software Foundation. All rights reserved.' + footer = 'Copyright © 2003-2024 The Apache Software Foundation. All rights reserved.' overviewText = rootProject.resources.text.fromFile('src/main/java/overview.html') access = GroovydocAccess.PROTECTED link 'https://docs.oracle.com/javaee/7/api/', 'javax.servlet.', 'javax.management.' 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 8ca5c3b43a..3f74b720a6 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 @@ -138,7 +138,7 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport { } currentClassDoc.setRawCommentText(getDocContent(node.getGroovydoc())); currentClassDoc.setNameWithTypeArgs(name + genericTypesAsString(node.getGenericsTypes())); - if (!node.isInterface() && node.getSuperClass() != null) { + if (!node.isInterface() && !node.isEnum() && node.getSuperClass() != null) { String superName = makeType(node.getSuperClass()); currentClassDoc.setSuperClassName(superName); String superSimpleName = node.getSuperClass().getNameWithoutPackage(); @@ -327,8 +327,7 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport { final ClassNode cn = node.isArray() ? node.getComponentType() : node; return cn.getName().replace('.', '/').replace('$', '.') + genericTypesAsString(cn.getGenericsTypes()) - + (node.isArray() ? "[]" : "") - ; + + (node.isArray() ? "[]" : ""); } @Override @@ -383,7 +382,11 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport { processModifiers(fieldDoc, node, node.getModifiers()); processAnnotations(fieldDoc, node); fieldDoc.setRawCommentText(getDocContent(node.getGroovydoc())); - currentClassDoc.add(fieldDoc); + if (node.isEnum()) { + currentClassDoc.addEnumConstant(fieldDoc); + } else { + currentClassDoc.add(fieldDoc); + } super.visitField(node); } 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);