Mercurial > public > gradleplugins
view 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 source
/* * Copyright (c) 2013. Ohio Department of Education. - All Rights Reserved. * Unauthorized copying of this file, in any medium, is strictly prohibited. * Written by State Software Development Team (http://ssdt.oecn.k12.oh.us/) */ 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() { getAdaptee().properties().findAll { GroovyFieldDoc p -> !p.isTransient() && p.name() != 'version' && !p.annotations().any { it.name().contains('Transient') } } } 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() } }