Example #1
0
 private String getConstantCharValue(char c) {
   StringBuilder sb = new StringBuilder();
   sb.append('\'');
   sb.append(esc(c, '\''));
   sb.append('\'');
   return sb.toString();
 }
Example #2
0
 private String getConstantStringValue(String s) {
   StringBuilder sb = new StringBuilder();
   sb.append("\"");
   for (int i = 0; i < s.length(); i++) {
     sb.append(esc(s.charAt(i), '"'));
   }
   sb.append("\"");
   return sb.toString();
 }
Example #3
0
  public void write(ClassFile cf) {
    setClassFile(cf);

    if ((options.sysInfo || options.verbose) && !options.compat) {
      if (uri != null) {
        if (uri.getScheme().equals("file")) println("Classfile " + uri.getPath());
        else println("Classfile " + uri);
      }
      indent(+1);
      if (lastModified != -1) {
        Date lm = new Date(lastModified);
        DateFormat df = DateFormat.getDateInstance();
        if (size > 0) {
          println("Last modified " + df.format(lm) + "; size " + size + " bytes");
        } else {
          println("Last modified " + df.format(lm));
        }
      } else if (size > 0) {
        println("Size " + size + " bytes");
      }
      if (digestName != null && digest != null) {
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) sb.append(String.format("%02x", b));
        println(digestName + " checksum " + sb);
      }
    }

    Attribute sfa = cf.getAttribute(Attribute.SourceFile);
    if (sfa instanceof SourceFile_attribute) {
      println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\"");
    }

    if ((options.sysInfo || options.verbose) && !options.compat) {
      indent(-1);
    }

    String name = getJavaName(classFile);
    AccessFlags flags = cf.access_flags;

    writeModifiers(flags.getClassModifiers());

    if (classFile.isClass()) print("class ");
    else if (classFile.isInterface()) print("interface ");

    print(name);

    Signature_attribute sigAttr = getSignature(cf.attributes);
    if (sigAttr == null) {
      // use info from class file header
      if (classFile.isClass() && classFile.super_class != 0) {
        String sn = getJavaSuperclassName(cf);
        print(" extends ");
        print(sn);
      }
      for (int i = 0; i < classFile.interfaces.length; i++) {
        print(i == 0 ? (classFile.isClass() ? " implements " : " extends ") : ",");
        print(getJavaInterfaceName(classFile, i));
      }
    } else {
      try {
        Type t = sigAttr.getParsedSignature().getType(constant_pool);
        // The signature parser cannot disambiguate between a
        // FieldType and a ClassSignatureType that only contains a superclass type.
        if (t instanceof Type.ClassSigType) print(getJavaName(t.toString()));
        else {
          print(" extends ");
          print(getJavaName(t.toString()));
        }
      } catch (ConstantPoolException e) {
        print(report(e));
      }
    }

    if (options.verbose) {
      println();
      indent(+1);
      attrWriter.write(cf, cf.attributes, constant_pool);
      println("minor version: " + cf.minor_version);
      println("major version: " + cf.major_version);
      if (!options.compat) writeList("flags: ", flags.getClassFlags(), NEWLINE);
      indent(-1);
      constantWriter.writeConstantPool();
    } else {
      print(" ");
    }

    println("{");
    indent(+1);
    writeFields();
    writeMethods();
    indent(-1);
    println("}");
  }