public GroovyDSLCategoryClass (Class<?>... categoryClasses) {
Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
for (Class<?> categoryClass : categoryClasses) {
ClassDescriptor cd = ClassCache.getFor(categoryClass);
Map<String, List<ClassMethod>> methodMap = cd.getMethods();
for (String name : methodMap.keySet()) {
boolean property = name.startsWith("get") && name.length() > 3 || name.startsWith("is") && name.length() > 2;
String setterName = null;
String getterName = null;
String propertyName = null;
if (property) {
getterName = name;
setterName = name.startsWith("is") ? name.substring(2) : name.substring(3);
propertyName = setterName.length() > 1 ? setterName.substring(0, 1).toLowerCase() + setterName.substring(1) : setterName.toLowerCase();
setterName = "set" + setterName;
}
List<ClassMethod> methods = methodMap.get(name);
for (ClassMethod method : methods) {
if (method.isStatic() && method.getParameterTypes().length > 0) {
Class forType = method.getParameterTypes()[0];
this.addCategory(classes, forType, cd);
if (forType.isPrimitive() || ReflectionUtil.isBoxedType(forType))
this.addCategory(classes, forType.isPrimitive() ? ReflectionUtil.getBoxedType(forType) : ReflectionUtil.getPrimitiveType(forType), cd);
if (property && method.getParameterTypes().length == 1) {
ClassMethod setter = null;
for (ClassMethod setterp : cd.getMethods(setterName)) {
if (setterp.getParameterTypes().length == 2 && setterp.getParameterTypes()[0] == forType && setterp.getParameterTypes()[1] == method.getReturnType()) {
setter = setterp; break;
}
}
this.properties.put(forType.getName() + ":" + propertyName, new GroovyDSLCategoryProperty(method, setter));