comparison 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
comparison
equal deleted inserted replaced
22:b3282a66cc05 23:e2d02e8742be
5 */ 5 */
6 6
7 package org.ssdt_ohio.gradle.doc.tools 7 package org.ssdt_ohio.gradle.doc.tools
8 8
9 import org.codehaus.groovy.groovydoc.GroovyFieldDoc 9 import org.codehaus.groovy.groovydoc.GroovyFieldDoc
10 import org.codehaus.groovy.groovydoc.GroovyProgramElementDoc
11
12 import static org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase
10 13
11 class UserClassDocProxy extends groovy.util.Proxy { 14 class UserClassDocProxy extends groovy.util.Proxy {
12 15
16 private static LABEL_PATTERN = ~/.*label = '([\w\s]*)'.*/
17 private static GROUP_PATTERN = ~/.*group = '([\w\s]*)'.*/
18
13 GroovyFieldDoc[] properties() { 19 GroovyFieldDoc[] properties() {
14 println "getting properties for $adaptee"
15 getAdaptee().properties().findAll { GroovyFieldDoc p -> 20 getAdaptee().properties().findAll { GroovyFieldDoc p ->
16 !p.isTransient() && 21 !p.isTransient() &&
17 p.name() != 'version' && 22 p.name() != 'version' &&
18 !p.annotations().any { it.name().contains('Transient') } 23 !p.annotations().any { it.name().contains('Transient') }
19 } 24 }
20 25
21 } 26 }
22 27
23 def propertyMissing(String name) { getAdaptee()."$name" } 28 def propertyMissing(String name) { getAdaptee()."$name" }
24 29
30 def getLabel(GroovyProgramElementDoc p) {
31 def result
32 def d = p.annotations().find {
33 it.name() == 'Display'
34 }
35 if (d) {
36 def m = LABEL_PATTERN.matcher(d.description())
37 if (m.matches()) {
38 result = m.group(1)
39 }
40 }
41
42 return result ?: labelFromCamelCase(p.name() - "get")
43
44 }
45
46 def getGroup(GroovyProgramElementDoc p) {
47 def result
48 def d = p.annotations().find {
49 it.name() == 'Display'
50 }
51 if (d) {
52 def m = GROUP_PATTERN.matcher(d.description())
53 if (m.matches()) {
54 result = m.group(1)
55 }
56 }
57
58 return labelFromCamelCase(result) ?: ''
59
60 }
61
62
63 static String labelFromCamelCase(String s) {
64 splitByCharacterTypeCamelCase(s).collect { it.trim() }.findAll { it }.join(' ').capitalize()
65
66 }
67
25 } 68 }