示例#1
0
 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", " ");
  }
示例#3
0
  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");
      }
    }
  }