Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

NameValuePair.java 2.2KB

14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  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. public class NameValuePair {
  17. private int nameIdx;
  18. private ElementValue value;
  19. private ConstantPool cpool;
  20. public NameValuePair(NameValuePair pair, ConstantPool cpool, boolean copyPoolEntries) {
  21. this.cpool = cpool;
  22. // J5ASSERT:
  23. // Could assert nvp.getNameString() points to the same thing as cpool.getConstant(nvp.getNameIndex())
  24. // if (!nvp.getNameString().equals(((ConstantUtf8)cpool.getConstant(nvp.getNameIndex())).getBytes())) {
  25. // throw new RuntimeException("envp buggered");
  26. // }
  27. if (copyPoolEntries) {
  28. nameIdx = cpool.addUtf8(pair.getNameString());
  29. } else {
  30. nameIdx = pair.getNameIndex();
  31. }
  32. value = ElementValue.copy(pair.getValue(), cpool, copyPoolEntries);
  33. }
  34. protected NameValuePair(int idx, ElementValue value, ConstantPool cpool) {
  35. this.nameIdx = idx;
  36. this.value = value;
  37. this.cpool = cpool;
  38. }
  39. public NameValuePair(String name, ElementValue value, ConstantPool cpool) {
  40. this.nameIdx = cpool.addUtf8(name);
  41. this.value = value;
  42. this.cpool = cpool;
  43. }
  44. protected void dump(DataOutputStream dos) throws IOException {
  45. dos.writeShort(nameIdx); // u2 name of the element
  46. value.dump(dos);
  47. }
  48. public int getNameIndex() {
  49. return nameIdx;
  50. }
  51. public final String getNameString() {
  52. return cpool.getConstantUtf8(nameIdx).getValue();
  53. }
  54. public final ElementValue getValue() {
  55. return value;
  56. }
  57. @Override
  58. public String toString() {
  59. StringBuilder sb = new StringBuilder();
  60. sb.append(getNameString()).append("=").append(value.stringifyValue());
  61. return sb.toString();
  62. }
  63. }