home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-10 | 3.2 KB | 127 lines |
- /*
- *
- * @(#) MethodDesc.java 1.5@(#)
- *
- * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- */
-
- /**
- * <p>
- * sunw.demo.classfile.MethodDesc
- * </p>
- *
- * @version 1.0
- * @author Laurence P. G. Cable
- */
-
-
- package sunw.demo.classfile;
-
-
- import java.io.DataOutputStream;
- import java.io.IOException;
-
- import sunw.demo.classfile.ClassFile;
- import sunw.demo.classfile.UTF8Constant;
- import sunw.demo.classfile.Attribute;
-
- /**
- * <p> this class provides minimal support for method_info structures </p>
- */
-
- final class MethodDesc {
-
- final static short ACC_PUBLIC = 0x0001;
- final static short ACC_PRIVATE = 0x0002;
- final static short ACC_PROTECTED = 0x0004;
- final static short ACC_STATIC = 0x0008;
- final static short ACC_FINAL = 0x0010;
- final static short ACC_SYNCHRONIZED = 0x0020;
- final static short ACC_NATIVE = 0x0100;
- final static short ACC_ABSTRACT = 0x0400;
-
- private UTF8Constant name;
- private UTF8Constant descriptor;
-
- private short accessFlags;
-
- private ClassFile classFile;
-
- private Attribute[] attributes;
-
- /**
- * <p> construct a descriptor for a method </p>
- *
- * @param method the name of the method
- * @param desc a type descriptor for its signature
- * @param flags access flags
- * @param cf the class file
- * @param attrs arbitrary attributes
- *
- */
-
- MethodDesc(String method, String desc, short flags, ClassFile cf, Attribute[] attrs) {
- super();
-
- // we would validate here ...
-
- name = new UTF8Constant(method, cf);
- descriptor = new UTF8Constant(desc, cf);
- accessFlags = flags;
- classFile = cf;
- attributes = attrs;
- }
-
- /**
- * <p> construct a descriptor for a method </p>
- *
- * @param method the name of the method
- * @param desc a type descriptor for its signature
- * @param flags access flags
- * @param cf the class file
- * @param code the code
- *
- */
-
- MethodDesc(String method, String desc, short flags, ClassFile cf, Code code) {
- super();
- // we would validate here ...
- name = new UTF8Constant(method, cf);
- descriptor = new UTF8Constant(desc, cf);
- accessFlags = flags;
- classFile = cf;
- Attribute ats[] = { code };
- attributes = ats;
- }
-
- /**
- * <p> write the method to the stream </p>
- *
- * @param dos the output stream
- *
- * @throws IOException
- */
-
- void write(DataOutputStream dos) throws IOException {
- dos.writeShort(accessFlags);
- dos.writeShort(name.getConstantPoolIndex());
- dos.writeShort(descriptor.getConstantPoolIndex());
-
- if (attributes != null && attributes.length > 0) {
- dos.writeShort(attributes.length);
-
- for (int i = 0; i < attributes.length; i++) {
- attributes[i].write(dos);
- }
- } else dos.writeShort(0);
- }
- }
-