//
// process getters
//
if (name.startsWith("get") && name.length() > 3 ||
name.startsWith("is") && name.length() > 2) {
JClass typ = methods[i].getReturnType();
//FIXME we just want the name - this forces the whole thing to be resolved
// need to either getReturnTypeRef() or change ClassImpl so that it lazily builds itself
if (typ == null) continue; // must have a typ and have
if (methods[i].getParameters().length > 0) continue; //no params
if (name.startsWith("get")) {
name = name.substring(3);
} else {
name = name.substring(2);
}
JProperty prop = (JProperty)name2prop.get(name);
if (prop == null) {
prop = declared ? clazz.addNewDeclaredProperty(name,methods[i],null) :
clazz.addNewProperty(name,methods[i],null);
name2prop.put(name,prop);
} else {
if (typ.equals(prop.getType())) {
((PropertyImpl)prop).setGetter(methods[i]); // cheater
}
}
}
//
// process setters
//
if (name.startsWith("set") && name.length() > 3) {
if (methods[i].getParameters().length != 1) continue; //1 param reqd
JClass type = methods[i].getParameters()[0].getType();
name = name.substring(3);
JProperty prop = (JProperty)name2prop.get(name);
if (prop == null) {
prop = declared ? clazz.addNewDeclaredProperty(name,null,methods[i]) :
clazz.addNewProperty(name,null,methods[i]);
name2prop.put(name,prop);
} else {
if (type.equals(prop.getType())) {
// if it's the same type, cool - just add the getter
((PropertyImpl)prop).setSetter(methods[i]); // with a sneaky cast
}
}
}