KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > EnclosingMethodAttribute


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7 package org.gjt.jclasslib.structures.attributes;
8
9 import org.gjt.jclasslib.structures.AttributeInfo;
10 import org.gjt.jclasslib.structures.InvalidByteCodeException;
11
12 import java.io.*;
13
14 /**
15  * Describes an <tt>EnclosingMethod</tt> attribute structure.
16  *
17  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
18  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:31 $
19  */

20 public class EnclosingMethodAttribute extends AttributeInfo {
21     /**
22      * Name of the attribute as in the corresponding constant pool entry.
23      */

24     public static final String JavaDoc ATTRIBUTE_NAME = "EnclosingMethod";
25
26     private static final int LENGTH = 4;
27
28     private int classInfoIndex;
29     private int methodInfoIndex;
30
31     /**
32      * Get the constant pool index of the <tt>CONSTANT_Class_info</tt>
33      * structure representing the innermost class that encloses the
34      * declaration of the current class.
35      *
36      * @return the index
37      */

38     public int getClassInfoIndex() {
39         return classInfoIndex;
40     }
41
42     /**
43      * Get the constant pool index of the <tt>CONSTANT_NameAndType_info</tt>
44      * structure representing the name and type of a method in the class
45      * referenced by the class info index above.
46      *
47      * @return the index
48      */

49     public int getMethodInfoIndex() {
50         return methodInfoIndex;
51     }
52
53     public void read(DataInput in)
54             throws InvalidByteCodeException, IOException {
55         super.read(in);
56
57         classInfoIndex = in.readUnsignedShort();
58         methodInfoIndex = in.readUnsignedShort();
59
60         if (debug) debug("read ");
61     }
62
63     public void write(DataOutput out)
64             throws InvalidByteCodeException, IOException {
65         super.write(out);
66
67         out.writeShort(classInfoIndex);
68         out.writeShort(methodInfoIndex);
69
70         if (debug) debug("wrote ");
71     }
72
73     public int getAttributeLength() {
74         return LENGTH;
75     }
76
77     protected void debug(String JavaDoc message) {
78         super.debug(message + "EnclosingMethod attribute with class index " +
79                 classInfoIndex + " and method index " + methodInfoIndex);
80     }
81 }
82
Popular Tags