1 52 53 package com.go.trove.classfile; 54 55 import java.io.*; 56 57 65 class ConstantValueAttr extends Attribute { 66 private ConstantInfo mConstant; 67 68 public ConstantValueAttr(ConstantPool cp, ConstantInfo constant) { 69 super(cp, CONSTANT_VALUE); 70 71 mConstant = constant; 72 } 73 74 public ConstantInfo getConstant() { 75 return mConstant; 76 } 77 78 public int getLength() { 79 return 2; 80 } 81 82 public void writeDataTo(DataOutput dout) throws IOException { 83 dout.writeShort(mConstant.getIndex()); 84 } 85 86 static Attribute define(ConstantPool cp, 87 String name, 88 int length, 89 DataInput din) throws IOException { 90 91 int index = din.readUnsignedShort(); 92 if ((length -= 2) > 0) { 93 din.skipBytes(length); 94 } 95 96 return new ConstantValueAttr(cp, cp.getConstant(index)); 97 } 98 } 99 | Popular Tags |