Mercurial > public > gradleplugins
diff src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy @ 23:e2d02e8742be
usasr-1307: for render tables for properties and reportable properties with label and group names
author | smith@nwoca.org |
---|---|
date | Wed, 16 Mar 2016 23:24:26 +0100 |
parents | e8e14d5d6be2 |
children |
line wrap: on
line diff
--- a/src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy Mon Jan 11 16:55:32 2016 +0000 +++ b/src/main/groovy/org/ssdt_ohio/gradle/doc/tools/UserClassDocProxy.groovy Wed Mar 16 23:24:26 2016 +0100 @@ -7,11 +7,16 @@ package org.ssdt_ohio.gradle.doc.tools import org.codehaus.groovy.groovydoc.GroovyFieldDoc +import org.codehaus.groovy.groovydoc.GroovyProgramElementDoc + +import static org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase class UserClassDocProxy extends groovy.util.Proxy { + private static LABEL_PATTERN = ~/.*label = '([\w\s]*)'.*/ + private static GROUP_PATTERN = ~/.*group = '([\w\s]*)'.*/ + GroovyFieldDoc[] properties() { - println "getting properties for $adaptee" getAdaptee().properties().findAll { GroovyFieldDoc p -> !p.isTransient() && p.name() != 'version' && @@ -22,4 +27,42 @@ def propertyMissing(String name) { getAdaptee()."$name" } + def getLabel(GroovyProgramElementDoc p) { + def result + def d = p.annotations().find { + it.name() == 'Display' + } + if (d) { + def m = LABEL_PATTERN.matcher(d.description()) + if (m.matches()) { + result = m.group(1) + } + } + + return result ?: labelFromCamelCase(p.name() - "get") + + } + + def getGroup(GroovyProgramElementDoc p) { + def result + def d = p.annotations().find { + it.name() == 'Display' + } + if (d) { + def m = GROUP_PATTERN.matcher(d.description()) + if (m.matches()) { + result = m.group(1) + } + } + + return labelFromCamelCase(result) ?: '' + + } + + + static String labelFromCamelCase(String s) { + splitByCharacterTypeCamelCase(s).collect { it.trim() }.findAll { it }.join(' ').capitalize() + + } + }