KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cojen > classfile > attribute > EnclosingMethodAttr


1 /*
2  * Copyright 2004 Brian S O'Neill
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.io.DataOutput JavaDoc;
21 import java.io.IOException JavaDoc;
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 JavaDoc 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 JavaDoc name, int length, DataInput JavaDoc din)
51         throws IOException JavaDoc
52     {
53         super(cp, name);
54         mClass = (ConstantClassInfo)cp.getConstant(din.readUnsignedShort());
55         mMethod = (ConstantNameAndTypeInfo)cp.getConstant(din.readUnsignedShort());
56         if ((length -= 4) > 0) {
57             din.skipBytes(length);
58         }
59     }
60
61     public ConstantClassInfo getEnclosingClass() {
62         return mClass;
63     }
64
65     public ConstantNameAndTypeInfo getEnclosingMethod() {
66         return mMethod;
67     }
68
69     public int getLength() {
70         return 4;
71     }
72     
73     public void writeDataTo(DataOutput JavaDoc dout) throws IOException JavaDoc {
74         dout.writeShort(mClass.getIndex());
75         dout.writeShort(mMethod.getIndex());
76     }
77 }
78
Popular Tags