Esempio n. 1
0
  private void put(ClassFormatOutput out) throws IOException {

    /* Write out the header */
    out.putU4(VMDescriptor.JAVA_CLASS_FORMAT_MAGIC);
    out.putU2(minor_version);
    out.putU2(major_version);

    // special case checking that the number of constant
    // pool entries does not exceed the limit of 65535
    // (as it is stored as a U2).
    // Special case to allow somewhat easier debugging
    // of the resulting failure.
    out.putU2("constant_pool", cptEntries.size());
    cptPut(out);

    out.putU2(access_flags);
    out.putU2(this_class);
    out.putU2(super_class);

    if (interfaces != null) {
      int ilen = interfaces.length;
      out.putU2(ilen);
      for (int i = 0; i < ilen; i++) {
        out.putU2(interfaces[i]);
      }
    } else {
      out.putU2(0);
    }

    if (field_info != null) {
      out.putU2(field_info.size());
      field_info.put(out);
    } else {
      out.putU2(0);
    }

    if (method_info != null) {
      out.putU2(method_info.size());
      method_info.put(out);
    } else {
      out.putU2(0);
    }

    if (attribute_info != null) {
      out.putU2(attribute_info.size());
      attribute_info.put(out);
    } else {
      out.putU2(0);
    }
  }
Esempio n. 2
0
  /**
   * Convert the object representation of the class into its class file format.
   *
   * @exception IOException error writing the class
   */
  public ByteArray getFileFormat() throws IOException {

    int classFileSize = 4 + (10 * 2);
    classFileSize += cptEstimatedSize;

    if (interfaces != null) classFileSize += (interfaces.length * 2);

    if (field_info != null) classFileSize += field_info.classFileSize();

    if (method_info != null) classFileSize += method_info.classFileSize();

    if (attribute_info != null) classFileSize += attribute_info.classFileSize();

    ClassFormatOutput cfo = new ClassFormatOutput(classFileSize + 200);

    put(cfo);

    return new ByteArray(cfo.getData(), 0, cfo.size());
  }
Esempio n. 3
0
  /** @see ClassHolder#addMember */
  public ClassMember addMember(String simpleName, String descriptor, int modifier) {
    if (SanityManager.DEBUG) {
      if (descriptor.startsWith("(")) {
        if (method_info != null) {
          if (method_info.find(simpleName, descriptor) != null) {
            SanityManager.THROWASSERT("Method already exists " + simpleName + " " + descriptor);
          }
        }

      } else {
        if (field_info != null) {
          if (field_info.find(simpleName, descriptor) != null) {
            SanityManager.THROWASSERT("Field already exists " + simpleName + " " + descriptor);
          }
        }
      }
    }

    CONSTANT_Utf8_info utf = addUtf8Entry(simpleName);

    int nameIndex = utf.getIndex();
    int descriptorIndex = addUtf8Entry(descriptor).getIndex();

    ClassMember item = new ClassMember(this, modifier, nameIndex, descriptorIndex);
    MemberTable mt;
    if (descriptor.startsWith("(")) {
      mt = method_info;
      if (mt == null) mt = method_info = new MemberTable(0);

    } else {
      mt = field_info;
      if (mt == null) mt = field_info = new MemberTable(0);
    }

    mt.addEntry(item);
    return item;
  }