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.

ElementNameValuePair.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. public class ElementNameValuePair {
  19. private int nameIdx;
  20. private ElementValue value;
  21. private ConstantPool cpool;
  22. public String toString() {
  23. StringBuffer sb = new StringBuffer();
  24. sb.append(getNameString()+"="+value.toString());
  25. return sb.toString();
  26. }
  27. public ElementNameValuePair(int idx,ElementValue value,ConstantPool cpool) {
  28. this.nameIdx = idx;
  29. this.value = value;
  30. this.cpool = cpool;
  31. }
  32. protected void dump(DataOutputStream dos) throws IOException {
  33. dos.writeShort(nameIdx); // u2 name of the element
  34. value.dump(dos);
  35. }
  36. public int getNameIndex() {
  37. return nameIdx;
  38. }
  39. public final String getNameString() {
  40. ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(nameIdx,Constants.CONSTANT_Utf8);
  41. return c.getBytes();
  42. }
  43. public final ElementValue getValue() {
  44. return value;
  45. }
  46. public String toShortString() {
  47. StringBuffer result = new StringBuffer();
  48. result.append(getNameString()).append("=").append(getValue().toShortString());
  49. return result.toString();
  50. }
  51. }