Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

EnumElementValueGen.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - initial implementation {date}
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.generic.annotation;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.apache.bcel.classfile.ConstantUtf8;
  16. import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
  17. import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue;
  18. import org.aspectj.apache.bcel.generic.ConstantPoolGen;
  19. import org.aspectj.apache.bcel.generic.ObjectType;
  20. public class EnumElementValueGen extends ElementValueGen {
  21. // For enum types, these two indices point to the type and value
  22. private int typeIdx;
  23. private int valueIdx;
  24. /**
  25. * This ctor assumes the constant pool already contains the right type and value -
  26. * as indicated by typeIdx and valueIdx. This ctor is used for deserialization
  27. */
  28. protected EnumElementValueGen(int typeIdx,int valueIdx,ConstantPoolGen cpool) {
  29. super(ElementValueGen.ENUM_CONSTANT,cpool);
  30. if (type != ENUM_CONSTANT)
  31. throw new RuntimeException("Only element values of type enum can be built with this ctor");
  32. this.typeIdx = typeIdx;
  33. this.valueIdx= valueIdx;
  34. }
  35. /**
  36. * Return immutable variant of this EnumElementValue
  37. */
  38. public ElementValue getElementValue() {
  39. System.err.println("Duplicating value: "+getEnumTypeString()+":"+getEnumValueString());
  40. return new EnumElementValue(type,typeIdx,valueIdx,cpGen.getConstantPool());
  41. }
  42. public EnumElementValueGen(ObjectType t,String value,ConstantPoolGen cpool) {
  43. super(ElementValueGen.ENUM_CONSTANT,cpool);
  44. typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t);
  45. valueIdx= cpool.addUtf8(value);// was addString(value);
  46. }
  47. public EnumElementValueGen(EnumElementValue value, ConstantPoolGen cpool, boolean copyPoolEntries) {
  48. super(ENUM_CONSTANT,cpool);
  49. if (copyPoolEntries) {
  50. typeIdx = cpool.addUtf8(value.getEnumTypeString());// was addClass(value.getEnumTypeString());
  51. valueIdx = cpool.addUtf8(value.getEnumValueString()); // was addString(value.getEnumValueString());
  52. } else {
  53. typeIdx = value.getTypeIndex();
  54. valueIdx = value.getValueIndex();
  55. }
  56. }
  57. public void dump(DataOutputStream dos) throws IOException {
  58. dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
  59. dos.writeShort(typeIdx); // u2
  60. dos.writeShort(valueIdx); // u2
  61. }
  62. public String stringifyValue() {
  63. ConstantUtf8 cu8 = (ConstantUtf8)getConstantPool().getConstant(valueIdx);
  64. return cu8.getBytes();
  65. // ConstantString cu8 = (ConstantString)getConstantPool().getConstant(valueIdx);
  66. // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
  67. }
  68. // BCELBUG: Should we need to call utility.signatureToString() on the output here?
  69. public String getEnumTypeString() {
  70. // Constant cc = getConstantPool().getConstant(typeIdx);
  71. // ConstantClass cu8 = (ConstantClass)getConstantPool().getConstant(typeIdx);
  72. // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
  73. return ((ConstantUtf8)getConstantPool().getConstant(typeIdx)).getBytes();
  74. // return Utility.signatureToString(cu8.getBytes());
  75. }
  76. public String getEnumValueString() {
  77. return ((ConstantUtf8)getConstantPool().getConstant(valueIdx)).getBytes();
  78. // ConstantString cu8 = (ConstantString)getConstantPool().getConstant(valueIdx);
  79. // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
  80. }
  81. public int getValueIndex() { return valueIdx;}
  82. public int getTypeIndex() { return typeIdx; }
  83. }