01: /*
02: This library is free software; you can redistribute it and/or
03: modify it under the terms of the GNU General Public
04: License as published by the Free Software Foundation; either
05: version 2 of the license, or (at your option) any later version.
06: */
07: package org.gjt.jclasslib.structures.attributes;
08:
09: 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 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) throws InvalidByteCodeException,
54: IOException {
55: super .read(in);
56:
57: classInfoIndex = in.readUnsignedShort();
58: methodInfoIndex = in.readUnsignedShort();
59:
60: if (debug)
61: debug("read ");
62: }
63:
64: public void write(DataOutput out) throws InvalidByteCodeException,
65: IOException {
66: super .write(out);
67:
68: out.writeShort(classInfoIndex);
69: out.writeShort(methodInfoIndex);
70:
71: if (debug)
72: debug("wrote ");
73: }
74:
75: public int getAttributeLength() {
76: return LENGTH;
77: }
78:
79: protected void debug(String message) {
80: super .debug(message
81: + "EnclosingMethod attribute with class index "
82: + classInfoIndex + " and method index "
83: + methodInfoIndex);
84: }
85: }
|