Exemplo n.º 1
0
 private void genInterfaceMethodDecl(StringBuilder sb, IMethodInfo mi) {
   if (!(mi instanceof JavaMethodInfo)) {
     // 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 (isPropertyMethod(mi)) {
     return;
   }
   if (mi.getDisplayName().equals("hashCode")
       || mi.getDisplayName().equals("equals")
       || mi.getDisplayName().equals("toString")) {
     if (!mi.getOwnersType().getName().equals(IGosuObject.class.getName())) {
       return;
     }
   }
   if (mi.getDescription() != null) {
     sb.append("/** ").append(mi.getDescription()).append(" */");
   }
   sb.append("  function ")
       .append(mi.getDisplayName())
       .append(TypeInfoUtil.getTypeVarList(mi))
       .append("(");
   IParameterInfo[] params = getGenericParameters(mi);
   for (int i = 0; i < params.length; i++) {
     IParameterInfo pi = params[i];
     sb.append(' ').append("p").append(i).append(" : ").append(pi.getFeatureType().getName());
     sb.append(i < params.length - 1 ? ',' : ' ');
   }
   sb.append(") : ").append(getGenericReturnType(mi).getName()).append(";\n");
 }
Exemplo n.º 2
0
  private void genMemberMethod(StringBuilder sb, IMethodInfo mi, IJavaType type) {
    if (!canExtendMethod(mi)) {
      return;
    }

    StringBuilder sbModifiers = buildModifiers(mi);
    if (mi.getDescription() != null) {
      sb.append("/** ").append(mi.getDescription()).append(" */");
    }
    sb.append("  ")
        .append(sbModifiers)
        .append("function ")
        .append(mi.getDisplayName())
        .append(TypeInfoUtil.getTypeVarList(mi))
        .append("(");
    IParameterInfo[] params = getGenericParameters(mi);
    for (int i = 0; i < params.length; i++) {
      IParameterInfo pi = params[i];
      sb.append(' ')
          .append("p")
          .append(i)
          .append(" : ")
          .append(pi.getFeatureType().getName())
          .append(i < params.length - 1 ? ',' : ' ');
    }
    sb.append(") : ").append(getGenericReturnType(mi).getName()).append("\n");
    if (!mi.isAbstract()) {
      generateStub(sb, mi.getReturnType());
    }
  }
Exemplo n.º 3
0
  private void genStaticMethod(StringBuilder sb, IMethodInfo mi, IJavaType type) {
    if (!(mi instanceof JavaMethodInfo)) {
      // It is possible that a methodinfo on a java type originates outside of java.
      // E.g., enhancement methods. Only static JAVA members should be reflected in
      // the proxy.
      return;
    }

    if (isPropertyMethod(mi)) {
      // We favor properties over methods -- gotta pick one
      return;
    }

    StringBuilder sbModifiers = appendVisibilityModifier(mi);
    if (mi.getDescription() != null) {
      sb.append("/** ").append(mi.getDescription()).append(" */");
    }
    sb.append("  ")
        .append(sbModifiers)
        .append("static function ")
        .append(mi.getDisplayName())
        .append(TypeInfoUtil.getTypeVarList(mi))
        .append("(");
    IParameterInfo[] params = getGenericParameters(mi);
    for (int i = 0; i < params.length; i++) {
      IParameterInfo pi = params[i];
      sb.append(' ')
          .append("p")
          .append(i)
          .append(" : ")
          .append(pi.getFeatureType().getName())
          .append(i < params.length - 1 ? ',' : ' ');
    }
    sb.append(") : ")
        .append(getGenericReturnType(mi).getName())
        .append("\n")
        .append("{\n")
        .append((mi.getReturnType() == GosuParserTypes.NULL_TYPE() ? "" : "    return "))
        .append(type.getName())
        .append('.')
        .append(mi.getDisplayName())
        .append(TypeInfoUtil.getTypeVarListNoBounds(mi))
        .append("(");
    for (int i = 0; i < params.length; i++) {
      sb.append(' ').append("p").append(i).append(i < params.length - 1 ? ',' : ' ');
    }
    sb.append(");\n");
    sb.append("}\n");
  }