final MemberTypeAdditions findAllMethod = crudAdditions
.get(FIND_ALL_METHOD);
findAllMethod.copyAdditionsTo(builder, governorTypeDetails);
final String simpleTypeName = field.getFieldType().getSimpleTypeName();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("List<" + simpleTypeName
+ "> suggestions = new ArrayList<" + simpleTypeName + ">();");
bodyBuilder.appendFormalLine("for (" + simpleTypeName + " "
+ StringUtils.uncapitalize(simpleTypeName) + " : "
+ findAllMethod.getMethodCall() + ") {");
bodyBuilder.indent();
final StringBuilder sb = new StringBuilder();
@SuppressWarnings("unchecked")
final List<FieldMetadata> applicationTypeFields = (List<FieldMetadata>) field
.getCustomData().get(APPLICATION_TYPE_FIELDS_KEY);
for (int i = 0; i < applicationTypeFields.size(); i++) {
final JavaSymbolName accessorMethodName = BeanInfoUtils
.getAccessorMethodName(applicationTypeFields.get(i));
if (i > 0) {
sb.append(" + ").append(" \" \" ").append(" + ");
}
sb.append(StringUtils.uncapitalize(simpleTypeName)).append(".")
.append(accessorMethodName).append("()");
}
bodyBuilder.appendFormalLine("String "
+ StringUtils.uncapitalize(simpleTypeName)
+ "Str = String.valueOf(" + sb.toString().trim() + ");");
bodyBuilder.appendFormalLine("if ("
+ StringUtils.uncapitalize(simpleTypeName)
+ "Str.toLowerCase().startsWith(query.toLowerCase())) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("suggestions.add("
+ StringUtils.uncapitalize(simpleTypeName) + ");");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.appendFormalLine("return suggestions;");
final JavaType returnType = new JavaType(
LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
Arrays.asList(field.getFieldType()));