public static String toInterfaceName(String name) { if (name.endsWith(INTERFACE_SUFFIX)) { return name; } return capitalizeFirst(name) + INTERFACE_SUFFIX; }
/** * Returns true if method is a getter of property. * In strict mode it will not strip non-alphanumeric characters. */ private static boolean isApplicable(Method method, Property property, boolean strict) { if (method.getArguments().size() != 1) { return false; } if (!method.getArguments().get(0).getTypeRef().equals(property.getTypeRef())) { return false; } String capitalized = capitalizeFirst(property.getName()); if (method.getName().endsWith("set" + capitalized)) { return true; } if (!strict && method.getName().endsWith("set" + property.getNameCapitalized())) { return true; } return false; }
Method ctor = BuilderUtils.findBuildableConstructor(generatedType); if (m.getReturnType().getDimensions() > 0) { sb.append(".addAllTo").append(StringUtils.capitalizeFirst(trimmedName)).append("(") .append("Arrays.asList(") .append("instance.").append(m.getName()).append("())") .append(".collect(Collectors.toList()))"); } else { sb.append(".with").append(StringUtils.capitalizeFirst(trimmedName)).append("(") .append("new ").append(generatedType.getName()).append("(") .append(ctor.getArguments().stream() String withMethod = "with" + (StringUtils.capitalizeFirst(trimmedName));
public static String fullyQualifiedNameDiff(TypeRef typeRef, TypeDef originType) { Map<String, String> map = DefinitionRepository.getRepository().getReferenceMap(); String currentPackage = originType != null ? originType.getPackageName() : null; if (typeRef instanceof ClassRef) { TypeRef unwrapped = TypeAs.combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF, UNWRAP_OPTIONAL_OF).apply(typeRef); if (unwrapped instanceof ClassRef) { ClassRef classRef = (ClassRef) unwrapped; String candidateFqn = classRef.getFullyQualifiedName().replace(classRef.getDefinition().getPackageName(), currentPackage); //If classRef is inside the current package. if (candidateFqn.equals(classRef.getFullyQualifiedName())) { return ""; } //If candidate is imported and different that the actual name, do a diff if (originType.getImports().contains(candidateFqn) && !classRef.getDefinition().getFullyQualifiedName().equals(candidateFqn)) { return capitalizeFirst(TypeUtils.fullyQualifiedNameDiff(candidateFqn, classRef.getFullyQualifiedName())); } //If not then we compare against what has been found in the map. String fqn = map.get(classRef.getDefinition().getName()); if (fqn == null) { System.out.println("Warning: Expected to find class with name:" + classRef.getDefinition().getName()); } else if (!classRef.getDefinition().getFullyQualifiedName().equals(fqn)) { return capitalizeFirst(TypeUtils.fullyQualifiedNameDiff(fqn, classRef.getFullyQualifiedName())); } } } return ""; }
String capitalized = capitalizeFirst(property.getName()); if (method.getName().endsWith(GET_PREFIX + capitalized)) { return true;
public Method apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); String methodName = "end" + BuilderUtils.fullyQualifiedNameDiff(property.getTypeRef(), originTypeDef) + capitalizeFirst(IS_COLLECTION.apply(property.getTypeRef()) ? Singularize.FUNCTION.apply(property.getNameCapitalized()) : property.getNameCapitalized()); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withReturnType(N_REF) .withName(methodName) .withNewBlock() .addNewStringStatementStatement("return and();") .endBlock() .build(); } });