You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EnumElementValue.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - initial implementation {date}
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.classfile.annotation;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.apache.bcel.Constants;
  16. import org.aspectj.apache.bcel.classfile.ConstantPool;
  17. import org.aspectj.apache.bcel.classfile.ConstantUtf8;
  18. import org.aspectj.apache.bcel.classfile.Utility;
  19. public class EnumElementValue extends ElementValue {
  20. // For enum types, these two indices point to the type and value
  21. private int typeIdx;
  22. private int valueIdx;
  23. public EnumElementValue(int type,int typeIdx,int valueIdx,ConstantPool cpool) {
  24. super(type,cpool);
  25. if (type != ENUM_CONSTANT)
  26. throw new RuntimeException("Only element values of type enum can be built with this ctor");
  27. this.typeIdx = typeIdx;
  28. this.valueIdx= valueIdx;
  29. }
  30. public void dump(DataOutputStream dos) throws IOException {
  31. dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
  32. dos.writeShort(typeIdx); // u2
  33. dos.writeShort(valueIdx); // u2
  34. }
  35. public String stringifyValue() {
  36. ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8);
  37. return cu8.getBytes();
  38. }
  39. public String getEnumTypeString() {
  40. ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(typeIdx,Constants.CONSTANT_Utf8);
  41. return Utility.signatureToString(cu8.getBytes());
  42. }
  43. public String getEnumValueString() {
  44. ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8);
  45. return cu8.getBytes();
  46. }
  47. public int getValueIndex() { return valueIdx;}
  48. public int getTypeIndex() { return typeIdx; }
  49. }