/**
   * Gets rule information of IOpenField instance.
   *
   * @param field IOpenField instance
   * @return rule info
   */
  private static RuleInfo getRuleInfoForField(IOpenField field) {

    String methodName = String.format("get%s", StringUtils.capitalize(field.getName()));
    Class<?>[] paramTypes = new Class<?>[0];
    Class<?> returnType = field.getType().getInstanceClass();

    RuleInfo ruleInfo = createRuleInfo(methodName, paramTypes, returnType);

    return ruleInfo;
  }
  /**
   * Generates interface class using methods and fields of given IOpenClass instance.
   *
   * @throws Exception if an error has occurred
   */
  public static Class<?> generateInterface(
      String className,
      IOpenClass openClass,
      ClassLoader classLoader,
      String[] includes,
      String[] excludes)
      throws Exception {

    if (openClass == null) {
      return generateInterface(className, EMPTY_RULES, classLoader);
    }

    List<RuleInfo> rules = new ArrayList<RuleInfo>();

    final Collection<IOpenMethod> methods = openClass.getMethods();
    for (IOpenMethod method : methods) {

      if (!isIgnoredMember(method)) {
        RuleInfo ruleInfo = getRuleInfoForMethod(method);
        boolean isMember = isMember(ruleInfo, includes, excludes);
        if (isMember) {
          rules.add(ruleInfo);
        }
      }
    }

    final Collection<IOpenField> fields = openClass.getFields().values();
    for (IOpenField field : fields) {

      if (!isIgnoredMember(field)) {

        if (field.isReadable()) {
          RuleInfo ruleInfo = getRuleInfoForField(field);
          boolean isMember = isMember(ruleInfo, includes, excludes);
          if (isMember) {
            rules.add(ruleInfo);
          }
        }
      }
    }

    return generateInterface(className, rules.toArray(new RuleInfo[rules.size()]), classLoader);
  }