/**
   * 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));
    }
  }
Exemple #2
0
  /**
   * Lookup setter-based properties.
   *
   * <p>This method will be called after <code>lookupFields</code> and <code>lookupGetters</code>.
   */
  protected void lookupSetters(
      final Map<String, Property> properties, final MethodHolder<?> clazz) {
    for (Method<?> method : clazz.getMethods()) {
      // Exclude static methods

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

      // Get type

      List<Parameter> parameters = method.getParameters();

      if (parameters.size() != 1) {
        continue;
      }

      // Get name

      String propertyName = isSetter(method);

      if (propertyName == null) {
        continue;
      }

      // Exclude based on other criteria
      //
      // (explicitly set to null in case we encountered an imbalanced field/getter)

      String type = parameters.get(0).getType();

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

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

      // Already found via its getter?

      Property existingProperty = properties.get(propertyName);

      if (existingProperty instanceof ForgeProperty) {
        ForgeProperty existingForgeProperty = (ForgeProperty) existingProperty;

        // Beware covariant return types: always prefer the getter's type

        properties.put(
            propertyName,
            new ForgeProperty(
                propertyName,
                existingForgeProperty.getType(),
                existingForgeProperty.getReadMethod(),
                method,
                getPrivateField((FieldHolder<?>) clazz, propertyName)));
        continue;
      }

      // Explicitly excluded based on getter already?

      if ((existingProperty == null) && properties.containsKey(propertyName)) {
        continue;
      }

      properties.put(
          propertyName, new ForgeProperty(propertyName, type, null, method, privateField));
    }
  }