Skip to content

Commit

Permalink
GROOVY-11269: GroovyClassDoc has empty 'enumConstants'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Jan 11, 2024
1 parent 05b00a0 commit d88aecf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand All @@ -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.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void visitClass(ClassNode node) {
}
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();
Expand Down Expand Up @@ -327,8 +327,7 @@ private String makeType(ClassNode node) {
final ClassNode cn = node.isArray() ? node.getComponentType() : node;
return cn.getName().replace('.', '/').replace('$', '.')
+ genericTypesAsString(cn.getGenericsTypes())
+ (node.isArray() ? "[]" : "")
;
+ (node.isArray() ? "[]" : "");
}

@Override
Expand Down Expand Up @@ -383,7 +382,11 @@ public void visitField(FieldNode node) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -157,14 +157,14 @@
if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
} else {
if (classDoc.isEnum()) {
if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (classDoc.isClass()) {
if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
%>
</ul>
Expand Down Expand Up @@ -232,7 +232,7 @@ <h2 title="${classDesc}" class="title">${classDesc}</h2>
<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(', ')
Expand Down Expand Up @@ -565,7 +565,7 @@ <h3>Enum Constant Detail</h3>
<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>
Expand Down Expand Up @@ -710,37 +710,37 @@ <h4>${method.typeParameters() ?
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><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasOpt) { %><li><a href="#optional_element_summary"><% } %>Optional<% if (hasOpt) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasReq) { %><li><a href="#required_element_summary"><% } %>Required<% if (hasReq) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasOpt) { %><li><a href="#optional_element_summary"><% } %>Optional<% if (hasOpt) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
} else {
if (visibleNested) { %><li><a href="#nested_summary"><% } %>Nested<% if (visibleNested) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleNested) { %><li><a href="#nested_summary"><% } %>Nested<% if (visibleNested) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (classDoc.isEnum()) {
if (hasEnumConstants) { %><li><a href="#enum_constant_summary"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasEnumConstants) { %><li><a href="#enum_constant_summary"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (hasFields) { %><li><a href="#field_summary"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#property_summary">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasFields) { %><li><a href="#field_summary"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#property_summary">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (classDoc.isClass()) {
if (visibleConstructors) { %><li><a href="#constructor_summary"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleConstructors) { %><li><a href="#constructor_summary"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (visibleMethods) { %><li><a href="#method_summary"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleMethods) { %><li><a href="#method_summary"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
%>
</ul>
<ul class="subNavList">
<li>&nbsp;|&nbsp;Detail:&nbsp;</li>
<%
if (classDoc.isAnnotationType()) {
if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasElements) { %><li><a href="#element_detail"><% } %>Element<% if (hasElements) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
} else {
if (classDoc.isEnum()) {
if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasEnumConstants) { %><li><a href="#enum_constant_detail"><% } %>Enum constants<% if (hasEnumConstants) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasFields) { %><li><a href="#field_detail"><% } %>Field<% if (hasFields) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (hasProperties) { %><li><a href="#prop_detail">Property</a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (classDoc.isClass()) {
if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleConstructors) { %><li><a href="#constructor_detail"><% } %>Constructor<% if (visibleConstructors) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
if (visibleMethods) { %><li><a href="#method_detail"><% } %>Method<% if (visibleMethods) { %></a></li><% } %>&nbsp;&nbsp;&nbsp;<%
}
%>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public void testInnerEnumReference() throws Exception {
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(
Expand All @@ -696,6 +696,7 @@ public void testEnumInitNotDocumented() throws Exception {
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);

Expand Down

0 comments on commit d88aecf

Please sign in to comment.