Esempio n. 1
0
  protected void writeMethod(Method m) {
    if (!options.checkAccess(m.access_flags)) return;

    method = m;

    AccessFlags flags = m.access_flags;

    Descriptor d;
    Type.MethodType methodType;
    List<? extends Type> methodExceptions;

    Signature_attribute sigAttr = getSignature(m.attributes);
    if (sigAttr == null) {
      d = m.descriptor;
      methodType = null;
      methodExceptions = null;
    } else {
      Signature methodSig = sigAttr.getParsedSignature();
      d = methodSig;
      try {
        methodType = (Type.MethodType) methodSig.getType(constant_pool);
        methodExceptions = methodType.throwsTypes;
        if (methodExceptions != null && methodExceptions.size() == 0) methodExceptions = null;
      } catch (ConstantPoolException e) {
        // report error?
        // fall back on standard descriptor
        methodType = null;
        methodExceptions = null;
      }
    }

    writeModifiers(flags.getMethodModifiers());
    if (methodType != null) {
      writeListIfNotEmpty("<", methodType.typeParamTypes, "> ");
    }
    if (getName(m).equals("<init>")) {
      print(getJavaName(classFile));
      print(getParameterTypes(d, flags));
    } else if (getName(m).equals("<clinit>")) {
      print("{}");
    } else {
      print(getReturnType(d));
      print(" ");
      print(getName(m));
      print(getParameterTypes(d, flags));
    }

    Attribute e_attr = m.attributes.get(Attribute.Exceptions);
    if (e_attr != null) { // if there are generic exceptions, there must be erased exceptions
      if (e_attr instanceof Exceptions_attribute) {
        Exceptions_attribute exceptions = (Exceptions_attribute) e_attr;
        print(" throws ");
        if (methodExceptions != null) { // use generic list if available
          writeList("", methodExceptions, "");
        } else {
          for (int i = 0; i < exceptions.number_of_exceptions; i++) {
            if (i > 0) print(", ");
            print(getJavaException(exceptions, i));
          }
        }
      } else {
        report("Unexpected or invalid value for Exceptions attribute");
      }
    }

    println(";");

    indent(+1);

    if (options.showInternalSignatures) {
      println("Signature: " + getValue(m.descriptor));
    }

    if (options.verbose && !options.compat) {
      writeList("flags: ", flags.getMethodFlags(), NEWLINE);
    }

    Code_attribute code = null;
    Attribute c_attr = m.attributes.get(Attribute.Code);
    if (c_attr != null) {
      if (c_attr instanceof Code_attribute) code = (Code_attribute) c_attr;
      else report("Unexpected or invalid value for Code attribute");
    }

    if (options.showDisassembled && !options.showAllAttrs) {
      if (code != null) {
        println("Code:");
        codeWriter.writeInstrs(code);
        codeWriter.writeExceptionTable(code);
      }
    }

    if (options.showLineAndLocalVariableTables) {
      if (code != null) {
        attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool);
        attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool);
      }
    }

    if (options.showAllAttrs) {
      Attribute[] attrs = m.attributes.attrs;
      for (Attribute attr : attrs) attrWriter.write(m, attr, constant_pool);
    }

    indent(-1);

    // set pendingNewline to write a newline before the next method (if any)
    // if a separator is desired
    setPendingNewline(
        options.showDisassembled
            || options.showAllAttrs
            || options.showInternalSignatures
            || options.showLineAndLocalVariableTables
            || options.verbose);
  }
Esempio n. 2
0
 protected void writeMethods() {
   for (Method m : classFile.methods) writeMethod(m);
   setPendingNewline(false);
 }