private void writeMethods() throws IOException {
   for (MethodInfo method : methods) {
     os.writeShort(method.getAccessFlags());
     os.writeShort(method.getNameIndex());
     os.writeShort(method.getDescriptorIndex());
     os.writeShort(method.getAttributes().length);
     attributeFacility.writeAttributes(method.getAttributes());
   }
 }
Example #2
0
 /** Returns true if the invoked method is static. */
 public boolean isStatic() {
   int acc = info.getAccessFlags();
   return (acc & AccessFlag.STATIC) != 0;
 }
  /** Prints the contents of a class file. */
  public static void print(ClassFile cf, PrintWriter out) {
    List<?> list;
    int n;

    /*
     * 0x0020 (SYNCHRONIZED) means ACC_SUPER if the modifiers are of a
     * class.
     */
    int mod = AccessFlag.toModifier(cf.getAccessFlags() & ~AccessFlag.SYNCHRONIZED);
    out.println(
        "major: "
            + cf.major
            + ", minor: "
            + cf.minor
            + " modifiers: "
            + Integer.toHexString(cf.getAccessFlags()));
    out.println(
        Modifier.toString(mod) + " class " + cf.getName() + " extends " + cf.getSuperclass());

    String[] infs = cf.getInterfaces();
    if (infs != null && infs.length > 0) {
      out.print("    implements ");
      out.print(infs[0]);
      for (int i = 1; i < infs.length; ++i) {
        out.print(", " + infs[i]);
      }

      out.println();
    }

    out.println();
    list = cf.getFields();
    n = list.size();
    for (int i = 0; i < n; ++i) {
      FieldInfo finfo = (FieldInfo) list.get(i);
      int acc = finfo.getAccessFlags();
      out.println(
          Modifier.toString(AccessFlag.toModifier(acc))
              + " "
              + finfo.getName()
              + "\t"
              + finfo.getDescriptor());
      printAttributes(finfo.getAttributes(), out, 'f');
    }

    out.println();
    list = cf.getMethods();
    n = list.size();
    for (int i = 0; i < n; ++i) {
      MethodInfo minfo = (MethodInfo) list.get(i);
      int acc = minfo.getAccessFlags();
      out.println(
          Modifier.toString(AccessFlag.toModifier(acc))
              + " "
              + minfo.getName()
              + "\t"
              + minfo.getDescriptor());
      printAttributes(minfo.getAttributes(), out, 'm');
      out.println();
    }

    out.println();
    printAttributes(cf.getAttributes(), out, 'c');
  }