home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / MethodDesc.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  3.2 KB  |  127 lines

  1. /*
  2.  *
  3.  * @(#) MethodDesc.java 1.5@(#)
  4.  *
  5.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  6.  * 
  7.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  8.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  9.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  10.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  11.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  12.  * THIS SOFTWARE OR ITS DERIVATIVES.
  13.  * 
  14.  */
  15.  
  16. /**
  17.  * <p>
  18.  * sunw.demo.classfile.MethodDesc
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25.  
  26. package sunw.demo.classfile;
  27.  
  28.  
  29. import java.io.DataOutputStream;
  30. import java.io.IOException;
  31.  
  32. import sunw.demo.classfile.ClassFile;
  33. import sunw.demo.classfile.UTF8Constant;
  34. import sunw.demo.classfile.Attribute;
  35.  
  36. /**
  37.  * <p> this class provides minimal support for method_info structures </p>
  38.  */
  39.  
  40. final class MethodDesc {
  41.  
  42.     final static short ACC_PUBLIC       = 0x0001;
  43.     final static short ACC_PRIVATE      = 0x0002;
  44.     final static short ACC_PROTECTED    = 0x0004;
  45.     final static short ACC_STATIC       = 0x0008;
  46.     final static short ACC_FINAL    = 0x0010;
  47.     final static short ACC_SYNCHRONIZED = 0x0020;
  48.     final static short ACC_NATIVE       = 0x0100;
  49.     final static short ACC_ABSTRACT     = 0x0400;
  50.  
  51.     private UTF8Constant    name;
  52.     private UTF8Constant    descriptor;
  53.  
  54.     private short        accessFlags;
  55.  
  56.     private ClassFile    classFile;
  57.  
  58.     private Attribute[]    attributes;
  59.  
  60.     /**
  61.      * <p> construct a descriptor for a method </p>
  62.      *
  63.      * @param method    the name of the method
  64.      * @param desc    a type descriptor for its signature
  65.      * @param flags    access flags
  66.      * @param cf    the class file
  67.      * @param attrs     arbitrary attributes
  68.      *
  69.      */
  70.  
  71.     MethodDesc(String method, String desc, short flags, ClassFile cf, Attribute[] attrs) {
  72.         super();
  73.  
  74.         // we would validate here ...
  75.  
  76.         name        = new UTF8Constant(method, cf);
  77.         descriptor  = new UTF8Constant(desc, cf);
  78.         accessFlags = flags;
  79.         classFile   = cf;
  80.         attributes  = attrs;
  81.     }
  82.  
  83.     /**
  84.      * <p> construct a descriptor for a method </p>
  85.      *
  86.      * @param method    the name of the method
  87.      * @param desc    a type descriptor for its signature
  88.      * @param flags    access flags
  89.      * @param cf    the class file
  90.      * @param code    the code
  91.      *
  92.      */
  93.  
  94.     MethodDesc(String method, String desc, short flags, ClassFile cf, Code code) {
  95.         super();
  96.         // we would validate here ...
  97.         name        = new UTF8Constant(method, cf);
  98.         descriptor  = new UTF8Constant(desc, cf);
  99.         accessFlags = flags;
  100.         classFile   = cf;
  101.     Attribute ats[] = { code };
  102.         attributes  = ats;
  103.     }
  104.  
  105.     /**
  106.      * <p> write the method to the stream </p>
  107.      *
  108.      * @param dos the output stream
  109.      *
  110.      * @throws IOException
  111.      */
  112.  
  113.     void write(DataOutputStream dos) throws IOException {
  114.         dos.writeShort(accessFlags);
  115.         dos.writeShort(name.getConstantPoolIndex());
  116.         dos.writeShort(descriptor.getConstantPoolIndex());
  117.  
  118.     if (attributes != null && attributes.length > 0) {
  119.             dos.writeShort(attributes.length);
  120.  
  121.             for (int i = 0; i < attributes.length; i++) {
  122.                 attributes[i].write(dos);
  123.             }
  124.     } else dos.writeShort(0);
  125.     }
  126. }
  127.