org.codehaus.groovy.tools.groovydoc.gstringTemplates.classLevel.classDocName.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of groovy-all Show documentation
Show all versions of groovy-all Show documentation
Groovy: A powerful, dynamic language for the JVM
<%
def title = classDoc.name() + (props.docTitle ? " (${props.docTitle})" : "")
def isVisible = { it.isPublic() || (it.isProtected() && props.protectedScope == 'true') || (!it.isProtected() && !it.isPrivate() && props.packageScope == 'true') || props.privateScope == 'true' }
def isVisibleExt = { t -> java.lang.reflect.Modifier.isPublic(t.modifiers) || java.lang.reflect.Modifier.isProtected(t.modifiers) }
def visibleFields = classDoc.fields().findAll(isVisible)
def visibleProperties = classDoc.properties() // props visible be defn
def visibleMethods = classDoc.methods().findAll(isVisible)
def visibleConstructors = classDoc.constructors().findAll(isVisible)
def visibleNested = classDoc.innerClasses().findAll(isVisible)
boolean hasFields = !classDoc.isAnnotationType() && visibleFields
boolean hasProperties = !classDoc.isAnnotationType() && visibleProperties
boolean hasElements = classDoc.isAnnotationType() && visibleFields
boolean methodSummaryShown = visibleMethods
boolean fieldSummaryShown = hasFields
boolean hasEnumConstants = classDoc.enumConstants()
def dolink = { t, boolean b ->
boolean isArray = false
if (!t || t instanceof String) {
return classDoc.getDocUrl(t, b)
}
if (t instanceof org.codehaus.groovy.tools.groovydoc.ArrayClassDocWrapper) {
t = t.delegate
isArray = true
}
if (t instanceof org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDoc) {
if (t.fullPathName == 'def') return classDoc.getDocUrl("java.lang.Object def", b)
if (!t.qualifiedTypeName().contains("<") && t.name().size() > 1)
return "" + (b ? t.qualifiedTypeName() : t.name()) + "" + (isArray ? "[]" : "")
}
return classDoc.getDocUrl(t.qualifiedTypeName(), b) + (isArray ? "[]" : "")
}
def linkfull = { t -> dolink(t, true) }
def linkable = { t -> dolink(t, false) }
def modifiersWithIgnore = { t, boolean ignorePublic ->
(t.isPrivate()?"private ":"") +
(t.isPublic() && !ignorePublic?"public ":"") +
(t.isProtected()?"protected ":"") +
(t.isStatic()?"static ":"") +
(t.isFinal()?"final ":"") +
(t.respondsTo('isAbstract') && t.isAbstract()?"abstract ":"")
}
def modifiers = { t -> modifiersWithIgnore(t, classDoc.isGroovy()) }
def modifiersBrief = { t ->
(t.isPrivate()?"private ":"") +
(t.isProtected()?"protected ":"") +
(t.isStatic()?"static ":"")
}
def annotations = { t, sepChar ->
t.annotations() ? t.annotations().collect{it.isTypeAvailable()?'@'+linkable(it.type().name())+(it.description()-('@'+it.type().name())):it.description()}.join(sepChar) + sepChar : ''
}
def elementTypes = [
"required":"true",
"optional":"false"
]
def isRequired = { f, v -> def req = f.constantValueExpression() == null; req.toString() == v }
def upcase = { n -> n[0].toUpperCase() + n[1..-1] }
def paramsOf = { n, boolean brief -> n.parameters().collect{ param -> (brief?'':annotations(param, ' ')) + linkable(param.isTypeAvailable()?param.type():param.typeName()) + (param.vararg()?'... ':' ') + param.name() + (param.defaultValue() ? " = " + param.defaultValue():"") }.join(", ") }
def nameFromParams = { n -> n.name() + '(' + n.parameters().collect{ param -> param.isTypeAvailable()?param.type().qualifiedTypeName():param.typeName() }.join(', ') + ')' }
def nameFromJavaParams = { n -> n.name + '(' + n.parameterTypes.collect{ param -> param.name }.join(', ') + ')' }
%>
${title}
- Summary:
<%
if (classDoc.isAnnotationType()) {
def hasReq = classDoc.fields().any{ isRequired(it, "true") }
def hasOpt = classDoc.fields().any{ isRequired(it, "false") }
if (hasReq) { %>- <% } %>Required<% if (hasReq) { %>
<% } %> <%
if (hasOpt) { %>- <% } %>Optional<% if (hasOpt) { %>
<% } %> <%
} else {
if (visibleNested) { %>- <% } %>Nested<% if (visibleNested) { %>
<% } %> <%
if (classDoc.isEnum()) {
if (hasEnumConstants) { %>- <% } %>Enum constants<% if (hasEnumConstants) { %>
<% } %> <%
}
if (hasFields) { %>- <% } %>Field<% if (hasFields) { %>
<% } %> <%
if (hasProperties) { %>- Property
<% } %> <%
if (classDoc.isClass()) {
if (visibleConstructors) { %>- <% } %>Constructor<% if (visibleConstructors) { %>
<% } %> <%
}
if (visibleMethods) { %>- <% } %>Method<% if (visibleMethods) { %>
<% } %> <%
}
%>
- | Detail:
<%
if (classDoc.isAnnotationType()) {
if (hasElements) { %>- <% } %>Element<% if (hasElements) { %>
<% } %> <%
} else {
if (classDoc.isEnum()) {
if (hasEnumConstants) { %>- <% } %>Enum constants<% if (hasEnumConstants) { %>
<% } %> <%
}
if (hasFields) { %>- <% } %>Field<% if (hasFields) { %>
<% } %> <%
if (hasProperties) { %>- Property
<% } %> <%
if (classDoc.isClass()) {
if (visibleConstructors) { %>- <% } %>Constructor<% if (visibleConstructors) { %>
<% } %> <%
}
if (visibleMethods) { %>- <% } %>Method<% if (visibleMethods) { %>
<% } %> <%
}
%>
<%
def pkg = classDoc.containingPackage().nameWithDots()
String classDesc = "${classDoc.isGroovy() ? "[Groovy]" : "[Java]"} ${classDoc.typeDescription} ${org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDoc.encodeAngleBrackets(classDoc.getNameWithTypeArgs())}"
if (pkg != "DefaultPackage") {
%>
Package: ${pkg}
<%}%>
${classDesc}
<%
def parents = classDoc.isInterface() ? classDoc.parentInterfaces : classDoc.parentClasses
if (parents.size() >= 2) {
parents.eachWithIndex { p, i ->
%>- <%
if ( i == parents.size() - 1) {
out << p.qualifiedTypeName()
} else {
%>
<% linkfull(p) %>
<%
}
}
}
%>
-
<%
if (classDoc.isInterface()) {
Set interfaces = classDoc.parentInterfaces
interfaces -= classDoc
if (interfaces) {
%>
- All Superinterfaces:
- ${interfaces.collect{ linkable(it) }.join(', ')}
<%
}
} else {
// TODO follow up the tree collecting interfaces seen?
def interfaces = classDoc.interfaces()
if (interfaces) {
%>
- All Implemented Interfaces and Traits:
- ${interfaces.collect{ linkable(it) }.join(', ')}
${annotations(classDoc, '\n') + modifiers(classDoc) + classDoc.typeSourceDescription + ' ' + classDoc.name()}
<% if (classDoc.isInterface() && classDoc.interfaces()) {
%>extends ${classDoc.interfaces().collect{ linkable(it) }.join(', ')}
<% } else if (classDoc.superclass()) {
%>extends ${linkable(classDoc.superclass())}
<% } %>
<% } %>
<% } %>
<% if (classDoc.commentText()) { %>
${classDoc.commentText()}
<% } %>
-
<% if (visibleNested) { %>
-
Nested Class Summary
Nested classes
Modifiers
Name
Description
<% visibleNested.eachWithIndex { c, i -> %>
${modifiersBrief(c) + c.typeSourceDescription}
${linkable(c)}
${c.firstSentenceCommentText()}
<% } %>
<% } %>
<% if (hasEnumConstants) { %>
-
Enum Constants Summary
Enum constants classes
Enum constant
Description
<% classDoc.enumConstants().eachWithIndex { ec, i -> %>
${ec.name()}
${ec.firstSentenceCommentText()}
<% } %>
<% } %>
<%
def buffer = new StringBuilder()
classes = []
if (classDoc.isInterface()) {
classes.addAll(classDoc.interfaces().toList())
} else {
if (classDoc.superclass()) classes += classDoc.superclass()
else classes += new org.codehaus.groovy.tools.groovydoc.ExternalGroovyClassDoc(Object.class)
}
visited = [classDoc] as Set
while (classes) {
Set nextLevel = []
classes.eachWithIndex { c,i ->
if (c.isInterface()) nextLevel.addAll(c.interfaces().toList())
else if (c.superclass() && c.qualifiedTypeName() != 'java.lang.Object') nextLevel += c.superclass()
nextLevel -= visited
visited += nextLevel
def list = []
if (c instanceof org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDoc) {
list = c.fields().findAll(isVisible).collect { field ->
"${field.name()}"
}
} else {
list = c.externalClass().fields.findAll{ isVisibleExt(it) }.collect { field ->
// "${field.name()}"
field.name
}
}
if (list) {
buffer << """
${c.typeSourceDescription} ${linkable(c)}
${list.join(', ')}
"""
}
}
classes = nextLevel
}
if (hasFields || buffer.length()>0) { %>
<%
if (hasFields) { %>
-
Field Summary
Fields
Modifiers
Name
Description
<% visibleFields.eachWithIndex { field, i -> %>
${modifiersBrief(field) + linkable(field.type())}
${field.name()}
${field.firstSentenceCommentText()}
<% } %>
<% } // if (hasFields)
if ((buffer.length())>0) { %>
-
Inherited fields
Fields inherited from class
Fields
${buffer}
<% } // if buffer %>
<% } // if hasFields or buffer %>
<% if (hasProperties) { %>
-
Properties Summary
Properties
Type
Name and description
<% visibleProperties.eachWithIndex { prop, i -> %>
${modifiersBrief(prop) + linkable(prop.type())}
${prop.name()}
${prop.firstSentenceCommentText()}
<% } %>
<% } %>
<% if (hasElements) { %>
-
Element Summary
<% elementTypes.each { k, v ->
%><%
if (visibleFields.any{ isRequired(it, v) }) { %>
${upcase(k)} Element Summary
Type
Name and Description
<% visibleFields.findAll {isRequired(it, v)}.eachWithIndex { element, i -> %>
${modifiersBrief(element) + linkable(element.type())}
${element.name()}
${element.firstSentenceCommentText()}
<% } %>
<% }
} //elementTypes.each %>
<% } %>
<% if (visibleConstructors) { %>
-
Constructor Summary
Constructors
Constructor and description
<% visibleConstructors.eachWithIndex { constructor, i -> %>
${modifiersBrief(constructor)}${constructor.name()}
(${paramsOf(constructor, true)})
${constructor.firstSentenceCommentText()}
<% } %>
<% } %>
<%
buffer = new StringBuilder()
Set classes = []
if (classDoc.isInterface()) {
classes.addAll(classDoc.interfaces().toList())
} else {
if (classDoc.superclass()) classes += classDoc.superclass()
else if (!classDoc.isTrait()) classes += new org.codehaus.groovy.tools.groovydoc.ExternalGroovyClassDoc(Object.class)
}
Set visited = [classDoc] as Set
while (classes) {
Set nextLevel = []
classes.eachWithIndex { c,i ->
if (c.isInterface()) nextLevel.addAll(c.interfaces().toList())
else if (c.superclass() && c.qualifiedTypeName() != 'java.lang.Object') nextLevel += c.superclass()
nextLevel -= visited
visited += nextLevel
def list = []
if (c instanceof org.codehaus.groovy.tools.groovydoc.SimpleGroovyClassDoc) {
list = c.methods().findAll(isVisible).collect { method ->
"${method.name()}"
}
} else {
list = c.externalClass().methods.findAll{ isVisibleExt(it) }.collect { method ->
linkable(c.externalClass().name + "#" + nameFromJavaParams(method) + " " + method.name)
}
}
if (list) {
buffer << """
${c.typeSourceDescription} ${linkable(c)}
${list.join(', ')}
"""
}
}
classes = nextLevel
}
if (visibleMethods || buffer.length()>0) { %>
<% if (visibleMethods) { %>
-
Methods Summary
Methods
Type
Name and description
<% visibleMethods.eachWithIndex { method, i -> %>
${modifiersBrief(method)}${linkable(method.returnType())}
${method.name()}(${paramsOf(method, true)})
${method.firstSentenceCommentText()}
<% } %>
<% } // if (visibleMethods)
if (buffer.length()>0) {
%>
-
Inherited Methods Summary
Inherited Methods
Methods inherited from class
Name
${buffer}
<%
} // if buffer.length%>
<% } %>
-
<% if (hasEnumConstants) { %>
-
Enum Constant Detail
<% for (ec in classDoc.enumConstants()) { %>
-
${modifiers(ec) + '' + classDoc.name() + ''} ${ec.name()}
${ec.commentText()}
<% } %>
<% } %>
<% if (hasFields) { %>
-
Field Detail
<% visibleFields.each { field -> %>
-
${annotations(field, '\n') + modifiersWithIgnore(field, false) + linkable(field.type())} ${field.name()}
${field.commentText()}
<% } %>
<% } %>
<% if (hasProperties) { %>
-
Property Detail
<% visibleProperties.each { prop -> %>
-
${annotations(prop, '\n') + modifiers(prop) + linkable(prop.type())} ${prop.name()}
${prop.commentText()}
<% } %>
<% } %>
<% if (hasElements) { %>
-
Element Detail
<% visibleFields.each { element -> %>
-
${modifiers(element) + linkable(element.type())} ${element.name()}
${element.commentText()}
<% } %>
<% } %>
<% if (visibleConstructors) { %>
<% } %>
<% if (visibleMethods) { %>
<% } %>
- Summary:
<%
if (classDoc.isAnnotationType()) {
def hasReq = classDoc.fields().any{ isRequired(it, "true") }
def hasOpt = classDoc.fields().any{ isRequired(it, "false") }
if (hasReq) { %>- <% } %>Required<% if (hasReq) { %>
<% } %> <%
if (hasOpt) { %>- <% } %>Optional<% if (hasOpt) { %>
<% } %> <%
} else {
if (visibleNested) { %>- <% } %>Nested<% if (visibleNested) { %>
<% } %> <%
if (classDoc.isEnum()) {
if (hasEnumConstants) { %>- <% } %>Enum constants<% if (hasEnumConstants) { %>
<% } %> <%
}
if (hasFields) { %>- <% } %>Field<% if (hasFields) { %>
<% } %> <%
if (hasProperties) { %>- Property
<% } %> <%
if (classDoc.isClass()) {
if (visibleConstructors) { %>- <% } %>Constructor<% if (visibleConstructors) { %>
<% } %> <%
}
if (visibleMethods) { %>- <% } %>Method<% if (visibleMethods) { %>
<% } %> <%
}
%>
- | Detail:
<%
if (classDoc.isAnnotationType()) {
if (hasElements) { %>- <% } %>Element<% if (hasElements) { %>
<% } %> <%
} else {
if (classDoc.isEnum()) {
if (hasEnumConstants) { %>- <% } %>Enum constants<% if (hasEnumConstants) { %>
<% } %> <%
}
if (hasFields) { %>- <% } %>Field<% if (hasFields) { %>
<% } %> <%
if (hasProperties) { %>- Property
<% } %> <%
if (classDoc.isClass()) {
if (visibleConstructors) { %>- <% } %>Constructor<% if (visibleConstructors) { %>
<% } %> <%
}
if (visibleMethods) { %>- <% } %>Method<% if (visibleMethods) { %>
<% } %> <%
}
%>
<% if (props.footer) { %>${props.footer}
<% } %>