annotate 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
rev   line source
15
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
1 /*
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
2 * Copyright (c) 2013. Ohio Department of Education. - All Rights Reserved.
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
3 * Unauthorized copying of this file, in any medium, is strictly prohibited.
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
4 * Written by State Software Development Team (http://ssdt.oecn.k12.oh.us/)
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
5 */
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
6
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
7 package org.ssdt_ohio.gradle.doc.tools
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
8
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
9 import org.codehaus.groovy.groovydoc.GroovyFieldDoc
23
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
10 import org.codehaus.groovy.groovydoc.GroovyProgramElementDoc
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
11
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
12 import static org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase
15
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
13
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
14 class UserClassDocProxy extends groovy.util.Proxy {
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
15
23
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
16 private static LABEL_PATTERN = ~/.*label = '([\w\s]*)'.*/
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
17 private static GROUP_PATTERN = ~/.*group = '([\w\s]*)'.*/
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
18
15
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
19 GroovyFieldDoc[] properties() {
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
20 getAdaptee().properties().findAll { GroovyFieldDoc p ->
20
e8e14d5d6be2 improve formatting. exclude @transient and version
smith@nwoca.org
parents: 16
diff changeset
21 !p.isTransient() &&
e8e14d5d6be2 improve formatting. exclude @transient and version
smith@nwoca.org
parents: 16
diff changeset
22 p.name() != 'version' &&
e8e14d5d6be2 improve formatting. exclude @transient and version
smith@nwoca.org
parents: 16
diff changeset
23 !p.annotations().any { it.name().contains('Transient') }
15
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
24 }
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
25
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
26 }
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
27
16
8400a7db1330 USASR-1307: update templates to groovydoc 2.3.6
smith@nwoca.org
parents: 15
diff changeset
28 def propertyMissing(String name) { getAdaptee()."$name" }
20
e8e14d5d6be2 improve formatting. exclude @transient and version
smith@nwoca.org
parents: 16
diff changeset
29
23
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
30 def getLabel(GroovyProgramElementDoc p) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
31 def result
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
32 def d = p.annotations().find {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
33 it.name() == 'Display'
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
34 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
35 if (d) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
36 def m = LABEL_PATTERN.matcher(d.description())
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
37 if (m.matches()) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
38 result = m.group(1)
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
39 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
40 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
41
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
42 return result ?: labelFromCamelCase(p.name() - "get")
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
43
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
44 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
45
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
46 def getGroup(GroovyProgramElementDoc p) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
47 def result
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
48 def d = p.annotations().find {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
49 it.name() == 'Display'
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
50 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
51 if (d) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
52 def m = GROUP_PATTERN.matcher(d.description())
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
53 if (m.matches()) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
54 result = m.group(1)
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
55 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
56 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
57
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
58 return labelFromCamelCase(result) ?: ''
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
59
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
60 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
61
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
62
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
63 static String labelFromCamelCase(String s) {
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
64 splitByCharacterTypeCamelCase(s).collect { it.trim() }.findAll { it }.join(' ').capitalize()
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
65
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
66 }
e2d02e8742be usasr-1307: for render tables for properties and reportable properties with label and group names
smith@nwoca.org
parents: 20
diff changeset
67
15
e3c55e83c9a4 USASR-1307: start custom class/property displays
Dave Smith <smith@nwoca.org>
parents:
diff changeset
68 }