01: /*
02: * Copyright 2004 Brian S O'Neill
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.cojen.classfile.attribute;
18:
19: import java.io.DataInput;
20: import java.io.DataOutput;
21: import java.io.IOException;
22: import org.cojen.classfile.Attribute;
23: import org.cojen.classfile.ConstantPool;
24: import org.cojen.classfile.constant.ConstantClassInfo;
25: import org.cojen.classfile.constant.ConstantNameAndTypeInfo;
26:
27: /**
28: *
29: *
30: * @author Brian S O'Neill
31: */
32: public class EnclosingMethodAttr extends Attribute {
33: private final ConstantClassInfo mClass;
34: private final ConstantNameAndTypeInfo mMethod;
35:
36: public EnclosingMethodAttr(ConstantPool cp,
37: ConstantClassInfo enclosingClass,
38: ConstantNameAndTypeInfo enclosingMethod) {
39: this (cp, ENCLOSING_METHOD, enclosingClass, enclosingMethod);
40: }
41:
42: public EnclosingMethodAttr(ConstantPool cp, String name,
43: ConstantClassInfo enclosingClass,
44: ConstantNameAndTypeInfo enclosingMethod) {
45: super (cp, name);
46: mClass = enclosingClass;
47: mMethod = enclosingMethod;
48: }
49:
50: public EnclosingMethodAttr(ConstantPool cp, String name,
51: int length, DataInput din) throws IOException {
52: super (cp, name);
53: mClass = (ConstantClassInfo) cp.getConstant(din
54: .readUnsignedShort());
55: mMethod = (ConstantNameAndTypeInfo) cp.getConstant(din
56: .readUnsignedShort());
57: if ((length -= 4) > 0) {
58: din.skipBytes(length);
59: }
60: }
61:
62: public ConstantClassInfo getEnclosingClass() {
63: return mClass;
64: }
65:
66: public ConstantNameAndTypeInfo getEnclosingMethod() {
67: return mMethod;
68: }
69:
70: public int getLength() {
71: return 4;
72: }
73:
74: public void writeDataTo(DataOutput dout) throws IOException {
75: dout.writeShort(mClass.getIndex());
76: dout.writeShort(mMethod.getIndex());
77: }
78: }
|