private IMethodInfo getPropertyGetMethod(IPropertyInfo pi, IJavaType ownerType) {
    JavaTypeInfo ti;
    if (!(pi.getOwnersType() instanceof IJavaType)) {
      return null;
    }
    if (ownerType.getTypeInfo() instanceof JavaTypeInfo) {
      ti = (JavaTypeInfo) ownerType.getTypeInfo();
    } else {
      throw new IllegalArgumentException(ownerType + " is not a recognized Java type");
    }

    IType propType = pi.getFeatureType();

    String strAccessor = "get" + pi.getDisplayName();
    IMethodInfo mi = ti.getMethod(ownerType, strAccessor);
    if (mi == null || mi.getReturnType() != propType) {
      strAccessor = "is" + pi.getDisplayName();
      mi = ti.getMethod(ownerType, strAccessor);
    }
    if (mi != null && mi.getReturnType() == propType) {
      return mi;
    }

    return null;
  }
 private void genInterfacePropertyDecl(StringBuilder sb, IPropertyInfo pi, IJavaType javaType) {
   if (pi.isStatic()) {
     genStaticProperty(pi, sb, javaType);
     return;
   }
   if (!pi.isReadable()) {
     return;
   }
   if (!(pi instanceof JavaBaseFeatureInfo)) {
     // It is possible that a methodinfo on a java type originates outside of java.
     // E.g., enhancement methods. Gosu does not support extending these.
     return;
   }
   IType type = getGenericType(pi);
   if (pi.getDescription() != null) {
     sb.append("/** ").append(pi.getDescription()).append(" */");
   }
   sb.append(" property get ")
       .append(pi.getName())
       .append("() : ")
       .append(type.getName())
       .append("\n");
   if (pi.isWritable(pi.getOwnersType())) {
     sb.append(" property set ")
         .append(pi.getName())
         .append("( _proxy_arg_value : ")
         .append(type.getName())
         .append(" )\n");
   }
 }
  protected static String deriveDescription(IPropertyInfo propertyInfo) {
    IType intrinsicType = propertyInfo.getOwnersType();
    String description;
    try {
      ResourceBundle resourceBundle =
          ResourceBundle.getBundle(
              intrinsicType.getName(),
              Locale.getDefault(),
              TypeSystem.getGosuClassLoader().getActualLoader());
      description = resourceBundle.getString(propertyInfo.getName());
    } catch (MissingResourceException e) {
      description = propertyInfo.getDescription();
    }

    return description == null ? "" : description.replaceAll("\n", " ");
  }
  private void genStaticProperty(IPropertyInfo pi, StringBuilder sb, IJavaType type) {
    if (!pi.isStatic()) {
      return;
    }

    if (!(pi instanceof JavaBaseFeatureInfo)) {
      // It is possible that a methodinfo on a java type originates outside of java.
      // E.g., enhancement methods. Gosu does not support extending these.
      return;
    }

    if (Keyword.isReserved(pi.getName())) {
      // Sorry these won't compile
      // ## todo: handle them reflectively?
      return;
    }

    if (pi.getDescription() != null) {
      sb.append("/** ").append(pi.getDescription()).append(" */");
    }
    if (pi instanceof JavaFieldPropertyInfo) {
      StringBuilder sbModifiers = appendFieldVisibilityModifier(pi);
      sb.append("  ")
          .append(sbModifiers)
          .append("static var ")
          .append(pi.getName())
          .append(" : ")
          .append(getGenericType(pi).getName())
          .append("\n");
    } else {
      StringBuilder sbModifiers = appendVisibilityModifier(pi);
      sb.append("  ")
          .append(sbModifiers)
          .append("static property get ")
          .append(pi.getName())
          .append("() : ")
          .append(getGenericType(pi).getName())
          .append("\n")
          .append("  {\n")
          .append("    return ")
          .append(type.getName())
          .append('.')
          .append(pi.getName())
          .append(";\n")
          .append("  }\n");

      if (pi.isWritable(pi.getOwnersType())) {
        sb.append("  static property set ")
            .append(pi.getName())
            .append("( _proxy_arg_value : ")
            .append(getGenericType(pi).getName())
            .append(" )\n")
            .append("  {\n")
            .append("  ")
            .append(type.getName())
            .append('.')
            .append(pi.getName())
            .append(" = _proxy_arg_value;\n")
            .append("  }\n");
      }
    }
  }
  private void genMemberProperty(IPropertyInfo pi, StringBuilder sb, IJavaType type) {
    if (pi.isStatic()) {
      return;
    }

    if (!(pi instanceof JavaBaseFeatureInfo)) {
      // It is possible that a propertyinfo on a java type originates outside of java.
      // E.g., enhancement properties. Gosu does not support extending these.
      return;
    }

    if (Keyword.isReserved(pi.getName()) && !Keyword.isReservedValue(pi.getName())) {
      // Sorry these won't compile
      // ## todo: handle them reflectively?
      return;
    }

    if (pi instanceof JavaFieldPropertyInfo) {
      StringBuilder sbModifiers = appendFieldVisibilityModifier(pi);
      sb.append("  ")
          .append(sbModifiers)
          .append(" var ")
          .append(pi.getName())
          .append(" : ")
          .append(getGenericType(pi).getName())
          .append("\n");
    } else {
      IMethodInfo mi = getPropertyGetMethod(pi, type);
      boolean bFinal = false;
      if (mi != null) {
        int iMethodModifiers = ((IJavaMethodInfo) mi).getModifiers();
        bFinal = java.lang.reflect.Modifier.isFinal(iMethodModifiers);
      }

      if (mi != null && !bFinal) {
        if (mi.getDescription() != null) {
          sb.append("/** ").append(mi.getDescription()).append(" */");
        }
        StringBuilder sbModifiers = buildModifiers(mi);
        sb.append("  ")
            .append(sbModifiers)
            .append("property get ")
            .append(pi.getName())
            .append("() : ")
            .append(getGenericType(pi).getName())
            .append("\n");
        if (!mi.isAbstract()) {
          generateStub(sb, mi.getReturnType());
        }
      } else {
        String strJavaClassName = type.getName();
        StringBuilder sbModifiers;
        boolean bAbstact = false;
        if (bFinal) {
          bAbstact = mi.isAbstract();
          sbModifiers = buildModifiers(mi);
        } else {
          sbModifiers = appendVisibilityModifier(pi);
        }
        sb.append("  ")
            .append(sbModifiers)
            .append("property get ")
            .append(pi.getName())
            .append("() : ")
            .append(getGenericType(pi).getName())
            .append("\n");
        if (!bAbstact) {
          generateStub(sb, getGenericType(pi));
        }
      }

      mi = getPropertySetMethod(pi, type);
      bFinal = false;
      if (mi != null) {
        int iMethodModifiers = ((IJavaMethodInfo) mi).getModifiers();
        bFinal = java.lang.reflect.Modifier.isFinal(iMethodModifiers);
      }

      if (mi != null && !bFinal) {
        StringBuilder sbModifiers = buildModifiers(mi);
        if (pi.isWritable(pi.getOwnersType())) {
          sb.append("  ")
              .append(sbModifiers)
              .append("property set ")
              .append(pi.getName())
              .append("( _proxy_arg_value : ")
              .append(getGenericType(pi).getName())
              .append(" )\n");
          if (!mi.isAbstract()) {
            generateStub(sb, JavaTypes.pVOID());
          }
        }
      } else {
        if (pi.isWritable(type.getEnclosingType() != null ? null : pi.getOwnersType())) {
          String strJavaClassName = type.getName();
          StringBuilder sbModifiers;
          boolean bAbstact = false;
          if (bFinal) {
            bAbstact = mi.isAbstract();
            sbModifiers = buildModifiers(mi);
          } else {
            sbModifiers = appendVisibilityModifier(pi);
          }
          sb.append("  ")
              .append(sbModifiers)
              .append("property set ")
              .append(pi.getName())
              .append("( _proxy_arg_value : ")
              .append(getGenericType(pi).getName())
              .append(" )\n");
          if (!bAbstact) {
            generateStub(sb, JavaTypes.pVOID());
          }
        }
      }
    }
  }