Пример #1
0
  /**
   * Returns whether the given method is a 'getter' method.
   *
   * @param method a parameterless method that returns a non-void
   * @return the property name
   */
  protected String isGetter(final Method<?> method) {

    String methodName = method.getName();
    String propertyName;

    if (methodName.startsWith(ClassUtils.JAVABEAN_GET_PREFIX)) {
      propertyName = methodName.substring(ClassUtils.JAVABEAN_GET_PREFIX.length());

    } else if (methodName.startsWith(ClassUtils.JAVABEAN_IS_PREFIX)
        && boolean.class.equals(method.getQualifiedReturnType())) {

      // As per section 8.3.2 (Boolean properties) of The JavaBeans API specification, 'is'
      // only applies to boolean (little 'b')

      propertyName = methodName.substring(ClassUtils.JAVABEAN_IS_PREFIX.length());
    } else {
      return null;
    }

    if (!StringUtils.isCapitalized(propertyName)) {
      return null;
    }

    return StringUtils.decapitalize(propertyName);
  }
  /**
   * Lookup getter-based properties.
   *
   * <p>This method will be called after <code>lookupFields</code> but before <code>lookupSetters
   * </code>.
   */
  protected void lookupGetters(
      final Map<String, Property> properties, final MethodHolder<?> clazz) {
    // Hack until https://issues.jboss.org/browse/FORGE-368

    for (Method<?> method : clazz.getMethods()) {
      // Exclude static methods

      if (method.isStatic()) {
        continue;
      }

      // Get type

      if (!method.getParameters().isEmpty()) {
        continue;
      }

      String returnType = method.getQualifiedReturnType();

      if (returnType == null) {
        continue;
      }

      // Get name

      String propertyName = isGetter(method);

      if (propertyName == null) {
        continue;
      }

      Field<?> privateField = getPrivateField((FieldHolder<?>) clazz, propertyName);

      if (privateField != null && this.privateFieldConvention == null) {
        propertyName = privateField.getName();
      }

      properties.put(
          propertyName,
          new ForgeProperty(propertyName, returnType, method, null, privateField, this.project));
    }
  }