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.

ElementNameValuePairGen.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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
  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.ElementNameValuePair;
  17. import org.aspectj.apache.bcel.generic.ConstantPoolGen;
  18. public class ElementNameValuePairGen {
  19. private int nameIdx;
  20. private ElementValueGen value;
  21. private ConstantPoolGen cpool;
  22. public ElementNameValuePairGen(ElementNameValuePair nvp, ConstantPoolGen cpool) {
  23. this.cpool = cpool;
  24. // J5ASSERT:
  25. // Could assert nvp.getNameString() points to the same thing as cpool.getConstant(nvp.getNameIndex())
  26. nameIdx = nvp.getNameIndex();
  27. value = ElementValueGen.copy(nvp.getValue(),cpool);
  28. }
  29. protected ElementNameValuePairGen(int idx,ElementValueGen value,ConstantPoolGen cpool) {
  30. this.nameIdx = idx;
  31. this.value = value;
  32. this.cpool = cpool;
  33. }
  34. public ElementNameValuePairGen(String name,ElementValueGen value,ConstantPoolGen cpool) {
  35. this.nameIdx = cpool.addUtf8(name);
  36. this.value = value;
  37. this.cpool = cpool;
  38. }
  39. protected void dump(DataOutputStream dos) throws IOException {
  40. dos.writeShort(nameIdx); // u2 name of the element
  41. value.dump(dos);
  42. }
  43. public int getNameIndex() {
  44. return nameIdx;
  45. }
  46. public final String getNameString() {
  47. // ConstantString cu8 = (ConstantString)cpool.getConstant(nameIdx);
  48. return ((ConstantUtf8)cpool.getConstant(nameIdx)).getBytes();
  49. }
  50. public final ElementValueGen getValue() {
  51. return value;
  52. }
  53. public String toString() {
  54. return "ElementNameValuePair:["+getNameString()+"="+value.stringifyValue()+"]";
  55. }
  56. }