group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
@Override
public Object getProperty(Interpreter interp, ST self, Object o,
Object property, String propertyName)
throws STNoSuchPropertyException {
Property p = (Property) o;
if ("docString".equals(propertyName)) {
String docString = p.getDocString();
List<String> enumValues = p.getType().getEnumValues();
if (enumValues != null) {
docString = docString == null ? "" : docString;
docString += "\n\nPossible values: ";
for (int i = 0; i < enumValues.size(); i++) {
docString += enumValues.get(i);
if (i < enumValues.size() - 1) docString += ", ";
}
}
return doxygenDocString(docString);
}
else if ("requireName".equals(propertyName)) {
return requireNameForType(p.getType().getName());
}
else if ("phpType".equals(propertyName)) {
return phpTypeForProperty(p);
}
else if ("modifiers".equals(propertyName)) {
List<String> modifiers = new ArrayList<String>();
String safeName = getSafeName(p.getName());
if (p.getImpliedProperty() != null
&& p.getImpliedProperty().getType().getJsonKind().equals(JsonKind.LIST)) {
modifiers.add("weak");
}
else {
modifiers.add("strong");
}
if (p.getType().getJsonKind().equals(JsonKind.BOOLEAN)) {
modifiers.add("getter=is" + upcase(safeName));
}
// http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
if (p.getName().startsWith("new")) {
modifiers.add("getter=a" + upcase(safeName));
}
return modifiers;
}
else if ("safeName".equals(propertyName)) {
return getSafeName(p.getName());
}
else if ("upcaseName".equals(propertyName)) {
return upcase(getSafeName(p.getName()));
}
else if ("listElementphpType".equals(propertyName)) {
return phpTypeForType(p.getType().getListElement());
}
else if ("singularUpcaseName".equals(propertyName)) {
if (p.getType().getListElement() != null) {
String type = phpTypeForType(p.getType().getListElement());
return type.substring(2);
}
return upcase(p.getName());
}
return super.getProperty(interp, self, o, property, propertyName);
}
});