// EntityDescription are rendered as the FQN
group.registerRenderer(EntityDescription.class, new AttributeRenderer() {
@Override
public String toString(Object o, String formatString, Locale locale) {
EntityDescription entity = (EntityDescription) o;
if (entity.getTypeName().equals("baseHasUuid")) {
return BaseHasUuid.class.getCanonicalName();
}
return entity.getTypeName();
}
});
group.registerModelAdaptor(ApiDescription.class,
new ObjectModelAdaptor() {
@Override
public Object getProperty(Interpreter interp, ST self, Object o,
Object property, String propertyName)
throws STNoSuchPropertyException {
ApiDescription apiDescription = (ApiDescription) o;
if ("endpoints".equals(propertyName)) {
List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
apiDescription.getEndpoints());
Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
@Override
public int compare(EndpointDescription e1, EndpointDescription e2) {
return e1.getPath().compareTo(e2.getPath());
}
});
return sortedEndpoints;
}
else if ("importNames".equals(propertyName)) {
Set<String> imports = new HashSet<String>();
for (EndpointDescription e : apiDescription.getEndpoints()) {
if (e.getEntity() != null) {
String type = objcTypeForType(e.getEntity());
if (isRequiredImport(type)) {
imports.add(type);
}
}
if (e.getReturnType() != null) {
String type = objcTypeForType(e.getReturnType());
if (isRequiredImport(type)) {
imports.add(type);
}
}
}
List<String> sortedImports = new ArrayList<String>(imports);
Collections.sort(sortedImports);
return sortedImports;
}
return super.getProperty(interp, self, o, property, propertyName);
}
});
group.registerModelAdaptor(EndpointDescription.class,
new ObjectModelAdaptor() {
@Override
public Object getProperty(Interpreter interp, ST self, Object o,
Object property, String propertyName)
throws STNoSuchPropertyException {
EndpointDescription end = (EndpointDescription) o;
if ("docString".equals(propertyName)) {
return doxygenDocString(end.getDocString());
}
else if ("methodName".equals(propertyName)) {
StringBuilder sb = new StringBuilder();
sb.append("- (" + getBuilderReturnType(end) + " *)");
sb.append(getMethodizedPath(end));
if (end.getEntity() != null) {
if (end.getPathParameters() != null && end.getPathParameters().size() > 0) {
sb.append(" entity");
}
String type = objcTypeForType(end.getEntity());
sb.append(":(" + type + " *)");
String paramName = type;
if (type.startsWith(classPrefix)) {
paramName = downcase(type.substring(classPrefix.length()));
}
sb.append(paramName);
}
return sb.toString();
}
else if ("requestBuilderClassName".equals(propertyName)) {
return getBuilderReturnType(end);
}
else if ("requestBuilderBlockName".equals(propertyName)) {
return getBuilderReturnType(end) + "Block";
}
else if ("entityReturnType".equals(propertyName)) {
String type = objcFlatpackReturnType(end.getReturnType());
return type.equals("void") ? null : type;
}
else if ("entityReturnName".equals(propertyName)) {
if (end.getReturnType() == null) return null;
String name = "result";
if (end.getReturnType().getName() != null) {
name = end.getReturnType().getName();
}
if (end.getReturnType().getListElement() != null) {
if (end.getReturnType().getListElement().getName() != null) {
name = end.getReturnType().getListElement().getName();
}
name = pluralOf(name);
}
return name;
}
else if ("pathDecoded".equals(propertyName)) {
// URL-decode the path in the endpoint description
try {
String decoded = URLDecoder.decode(end.getPath(), "UTF8");
return decoded;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return super.getProperty(interp, self, o, property, propertyName);
}
});
group.registerModelAdaptor(EntityDescription.class,
new ObjectModelAdaptor() {
@Override
public Object getProperty(Interpreter interp, ST self, Object o,
Object property, String propertyName)
throws STNoSuchPropertyException {
EntityDescription entity = (EntityDescription) o;
if ("importNames".equals(propertyName)) {
Set<String> imports = new HashSet<String>();
String type = requireNameForType(entity.getTypeName());
if (isRequiredImport(type)) {
imports.add(type);
}
for (Property p : entity.getProperties()) {
String name = null;
if (p.getType().getListElement() != null) {
name = objcTypeForType(p.getType().getListElement());
}
else {
name = objcTypeForProperty(p);
}
if (name != null && isRequiredImport(name)) {
imports.add(name);
}
}
List<String> sortedImports = new ArrayList<String>(imports);
Collections.sort(sortedImports);
return sortedImports;
}
if ("docString".equals(propertyName)) {
return doxygenDocString(entity.getDocString());
}
else if ("payloadName".equals(propertyName)) {
return entity.getTypeName();
}
else if ("supertype".equals(propertyName)) {
EntityDescription supertype = entity.getSupertype();
if (supertype == null) {
supertype = baseHasUuid;
}
return supertype;
}