예제 #1
0
 private boolean isPropertyGetter(IMethodInfo mi, String strPrefix) {
   String strMethod = mi.getDisplayName();
   if (strMethod.startsWith(strPrefix) && mi.getParameters().length == 0) {
     String strProp = strMethod.substring(strPrefix.length());
     if (strProp.length() > 0 && Character.isUpperCase(strProp.charAt(0))) {
       ITypeInfo ti = (ITypeInfo) mi.getContainer();
       IPropertyInfo pi =
           ti instanceof IRelativeTypeInfo
               ? ((IRelativeTypeInfo) ti).getProperty(mi.getOwnersType(), strProp)
               : ti.getProperty(strProp);
       if (pi != null && getGenericType(pi).getName().equals(getGenericReturnType(mi).getName())) {
         return !Keyword.isReserved(pi.getName()) || Keyword.isReservedValue(pi.getName());
       }
     }
   }
   return false;
 }
예제 #2
0
 private boolean isPropertySetter(IMethodInfo mi) {
   String strMethod = mi.getDisplayName();
   if (strMethod.startsWith("set")
       && strMethod.length() > 3
       && mi.getParameters().length == 1
       && mi.getReturnType() == JavaTypes.pVOID()) {
     String strProp = strMethod.substring("set".length());
     if (Character.isUpperCase(strProp.charAt(0))) {
       ITypeInfo ti = (ITypeInfo) mi.getContainer();
       IPropertyInfo pi =
           ti instanceof IRelativeTypeInfo
               ? ((IRelativeTypeInfo) ti).getProperty(mi.getOwnersType(), strProp)
               : ti.getProperty(strProp);
       if (pi != null
           && pi.isReadable()
           && getGenericType(pi)
               .getName()
               .equals(getGenericParameters(mi)[0].getFeatureType().getName())) {
         return !Keyword.isReserved(pi.getName()) || Keyword.isReservedValue(pi.getName());
       }
     }
   }
   return false;
 }
예제 #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");
      }
    }
  }
예제 #4
0
  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());
          }
        }
      }
    }
  }