예제 #1
0
  /**
   * Find all buildable descendant equivalents of a property.
   *
   * @param property
   * @return
   */
  public static Set<JavaProperty> getPropertyBuildableAncestors(JavaProperty property) {
    Set<JavaProperty> result = new LinkedHashSet<JavaProperty>();
    JavaType baseType = property.getType();

    if (baseType.isCollection()) {
      JavaType candidate = TypeAs.UNWRAP_COLLECTION_OF.apply(baseType);
      for (JavaType descendant : BuilderUtils.getBuildableDescendants(candidate)) {
        JavaType collectionType =
            new JavaTypeBuilder(baseType).withGenericTypes(new JavaType[] {descendant}).build();
        String propertyName =
            deCaptializeFirst(descendant.getSimpleName()) + property.getNameCapitalized();
        result.add(
            new JavaPropertyBuilder(property)
                .withName(propertyName)
                .withType(collectionType)
                .addToAttributes(DESCENDANT_OF, property)
                .addToAttributes(BUILDABLE, true)
                .build());
      }
    } else {
      for (JavaType descendant : BuilderUtils.getBuildableDescendants(baseType)) {
        String propertyName = descendant.getSimpleName() + property.getNameCapitalized();
        result.add(
            new JavaPropertyBuilder(property)
                .withName(propertyName)
                .withType(descendant)
                .addToAttributes(DESCENDANT_OF, property)
                .addToAttributes(BUILDABLE, true)
                .build());
      }
    }
    return result;
  }
예제 #2
0
  private static boolean isApplicableGetterOf(JavaMethod method, JavaProperty property) {
    if (!method.getReturnType().isAssignable(property.getType())) {
      return false;
    }

    if (method.getName().endsWith("get" + property.getNameCapitalized())) {
      return true;
    }

    if (method.getName().endsWith("is" + property.getNameCapitalized())) {
      return true;
    }
    return false;
  }