1 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 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, int length, DataInput din) 51 throws IOException 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 dout) throws IOException { 74 dout.writeShort(mClass.getIndex()); 75 dout.writeShort(mMethod.getIndex()); 76 } 77 } 78 | Popular Tags |