Пример #1
0
  public void atClassObject(Expr expr) throws CompileError {
    ASTree op1 = expr.oprand1();
    if (!(op1 instanceof Symbol)) throw new CompileError("fatal error: badly parsed .class expr");

    String cname = ((Symbol) op1).get();
    if (cname.startsWith("[")) {
      int i = cname.indexOf("[L");
      if (i >= 0) {
        String name = cname.substring(i + 2, cname.length() - 1);
        String name2 = resolveClassName(name);
        if (!name.equals(name2)) {
          /* For example, to obtain String[].class,
           * "[Ljava.lang.String;" (not "[Ljava/lang/String"!)
           * must be passed to Class.forName().
           */
          name2 = MemberResolver.jvmToJavaName(name2);
          StringBuffer sbuf = new StringBuffer();
          while (i-- >= 0) sbuf.append('[');

          sbuf.append('L').append(name2).append(';');
          cname = sbuf.toString();
        }
      }
    } else {
      cname = resolveClassName(MemberResolver.javaToJvmName(cname));
      cname = MemberResolver.jvmToJavaName(cname);
    }

    atClassObject2(cname);
    exprType = CLASS;
    arrayDim = 0;
    className = "java/lang/Class";
  }
Пример #2
0
  protected static String toJvmTypeName(int type, int dim) {
    char c = 'I';
    switch (type) {
      case BOOLEAN:
        c = 'Z';
        break;
      case BYTE:
        c = 'B';
        break;
      case CHAR:
        c = 'C';
        break;
      case SHORT:
        c = 'S';
        break;
      case INT:
        c = 'I';
        break;
      case LONG:
        c = 'J';
        break;
      case FLOAT:
        c = 'F';
        break;
      case DOUBLE:
        c = 'D';
        break;
      case VOID:
        c = 'V';
        break;
    }

    StringBuffer sbuf = new StringBuffer();
    while (dim-- > 0) sbuf.append('[');

    sbuf.append(c);
    return sbuf.toString();
  }
Пример #3
0
  /** @param name the JVM-internal representation. name is not exapnded to java.lang.*. */
  protected static String toJvmArrayName(String name, int dim) {
    if (name == null) return null;

    if (dim == 0) return name;
    else {
      StringBuffer sbuf = new StringBuffer();
      int d = dim;
      while (d-- > 0) sbuf.append('[');

      sbuf.append('L');
      sbuf.append(name);
      sbuf.append(';');

      return sbuf.toString();
    }
  }