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.

ClassElementValue.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.classfile.ConstantPool;
  16. import org.aspectj.apache.bcel.classfile.ConstantUtf8;
  17. import org.aspectj.apache.bcel.generic.ObjectType;
  18. public class ClassElementValue extends ElementValue {
  19. // For primitive types and string type, this points to the value entry in the cpool
  20. // For 'class' this points to the class entry in the cpool
  21. private int idx;
  22. protected ClassElementValue(int typeIdx, ConstantPool cpool) {
  23. super(ElementValue.CLASS, cpool);
  24. this.idx = typeIdx;
  25. }
  26. public ClassElementValue(ObjectType t, ConstantPool cpool) {
  27. super(ElementValue.CLASS, cpool);
  28. // this.idx = cpool.addClass(t);
  29. idx = cpool.addUtf8(t.getSignature());
  30. }
  31. /**
  32. * Return immutable variant of this ClassElementValueGen
  33. */
  34. // public ElementValueGen getElementValue() {
  35. // return new ClassElementValueGen(type,idx,cpGen);
  36. // }
  37. public ClassElementValue(ClassElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
  38. super(CLASS, cpool);
  39. if (copyPoolEntries) {
  40. // idx = cpool.addClass(value.getClassString());
  41. idx = cpool.addUtf8(value.getClassString());
  42. } else {
  43. idx = value.getIndex();
  44. }
  45. }
  46. public int getIndex() {
  47. return idx;
  48. }
  49. public String getClassString() {
  50. ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
  51. return cu8.getValue();
  52. // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
  53. // ConstantUtf8 utf8 = (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
  54. // return utf8.getBytes();
  55. }
  56. @Override
  57. public String stringifyValue() {
  58. return getClassString();
  59. }
  60. @Override
  61. public void dump(DataOutputStream dos) throws IOException {
  62. dos.writeByte(type); // u1 kind of value
  63. dos.writeShort(idx);
  64. }
  65. }