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.

AnnotationsAttribute.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later,
  9. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist.bytecode;
  17. import java.util.Map;
  18. import java.util.HashMap;
  19. import java.io.IOException;
  20. import java.io.DataInputStream;
  21. import java.io.ByteArrayOutputStream;
  22. import javassist.bytecode.annotation.*;
  23. /**
  24. * A class representing
  25. * <code>RuntimeVisibleAnnotations_attribute</code> and
  26. * <code>RuntimeInvisibleAnnotations_attribute</code>.
  27. *
  28. * <p>To obtain an AnnotationAttribute object, invoke
  29. * <code>getAttribute(AnnotationsAttribute.visibleTag)</code>
  30. * in <code>ClassFile</code>, <code>MethodInfo</code>,
  31. * or <code>FieldInfo</code>. The obtained attribute is a
  32. * runtime visible annotations attribute.
  33. * If the parameter is
  34. * <code>AnnotationAttribute.invisibleTag</code>, then the obtained
  35. * attribute is a runtime invisible one.
  36. *
  37. * <p>For example,
  38. *
  39. * <ul><pre>
  40. * import javassist.bytecode.annotation.Annotation;
  41. * :
  42. * CtMethod m = ... ;
  43. * MethodInfo minfo = m.getMethodInfo();
  44. * AnnotationsAttribute attr = (AnnotationsAttribute)
  45. * minfo.getAttribute(AnnotationsAttribute.invisibleTag);
  46. * Annotation an = attr.getAnnotation("Author");
  47. * String s = ((StringMemberValue)an.getMemberValue("name")).getValue();
  48. * System.out.println("@Author(name=" + s + ")");
  49. * </pre></ul>
  50. *
  51. * <p>This code snippet retrieves an annotation of the type <code>Author</code>
  52. * from the <code>MethodInfo</code> object specified by <code>minfo</code>.
  53. * Then, it prints the value of <code>name</code> in <code>Author</code>.
  54. *
  55. * <p>If the annotation type <code>Author</code> is annotated by a meta annotation:
  56. *
  57. * <ul><pre>
  58. * &#64;Retention(RetentionPolicy.RUNTIME)
  59. * </pre></ul>
  60. *
  61. * <p>Then <code>Author</code> is visible at runtime. Therefore, the third
  62. * statement of the code snippet above must be changed into:
  63. *
  64. * <ul><pre>
  65. * AnnotationsAttribute attr = (AnnotationsAttribute)
  66. * minfo.getAttribute(AnnotationsAttribute.visibleTag);
  67. * </pre></ul>
  68. *
  69. * <p>The attribute tag must be <code>visibleTag</code> instead of
  70. * <code>invisibleTag</code>.
  71. *
  72. * <p>If the member value of an annotation is not specified, the default value
  73. * is used as that member value. If so, <code>getMemberValue()</code> in
  74. * <code>Annotation</code> returns <code>null</code>
  75. * since the default value is not included in the
  76. * <code>AnnotationsAttribute</code>. It is included in the
  77. * <code>AnnotationDefaultAttribute</code> of the method declared in the
  78. * annotation type.
  79. *
  80. * <p>If you want to record a new AnnotationAttribute object, execute the
  81. * following snippet:
  82. *
  83. * <ul><pre>
  84. * ClassFile cf = ... ;
  85. * ConstPool cp = cf.getConstPool();
  86. * AnnotationsAttribute attr
  87. * = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
  88. * Annotation a = new Annotation("Author", cp);
  89. * a.addMemberValue("name", new StringMemberValue("Chiba", cp));
  90. * attr.setAnnotation(a);
  91. * cf.addAttribute(attr);
  92. * cf.setVersionToJava5();
  93. * </pre></ul>
  94. *
  95. * <p>The last statement is necessary if the class file was produced by
  96. * <code>javac</code> of JDK 1.4 or earlier. Otherwise, it is not necessary.
  97. *
  98. * @see AnnotationDefaultAttribute
  99. * @see javassist.bytecode.annotation.Annotation
  100. */
  101. public class AnnotationsAttribute extends AttributeInfo {
  102. /**
  103. * The name of the <code>RuntimeVisibleAnnotations</code> attribute.
  104. */
  105. public static final String visibleTag = "RuntimeVisibleAnnotations";
  106. /**
  107. * The name of the <code>RuntimeInvisibleAnnotations</code> attribute.
  108. */
  109. public static final String invisibleTag = "RuntimeInvisibleAnnotations";
  110. /**
  111. * Constructs a <code>Runtime(In)VisibleAnnotations_attribute</code>.
  112. *
  113. * @param cp constant pool
  114. * @param attrname attribute name (<code>visibleTag</code> or
  115. * <code>invisibleTag</code>).
  116. * @param info the contents of this attribute. It does not
  117. * include <code>attribute_name_index</code> or
  118. * <code>attribute_length</code>.
  119. */
  120. public AnnotationsAttribute(ConstPool cp, String attrname, byte[] info) {
  121. super(cp, attrname, info);
  122. }
  123. /**
  124. * Constructs an empty
  125. * <code>Runtime(In)VisibleAnnotations_attribute</code>.
  126. * A new annotation can be later added to the created attribute
  127. * by <code>setAnnotations()</code>.
  128. *
  129. * @param cp constant pool
  130. * @param attrname attribute name (<code>visibleTag</code> or
  131. * <code>invisibleTag</code>).
  132. * @see #setAnnotations(Annotation[])
  133. */
  134. public AnnotationsAttribute(ConstPool cp, String attrname) {
  135. this(cp, attrname, new byte[] { 0, 0 });
  136. }
  137. /**
  138. * @param n the attribute name.
  139. */
  140. AnnotationsAttribute(ConstPool cp, int n, DataInputStream in)
  141. throws IOException
  142. {
  143. super(cp, n, in);
  144. }
  145. /**
  146. * Returns <code>num_annotations</code>.
  147. */
  148. public int numAnnotations() {
  149. return ByteArray.readU16bit(info, 0);
  150. }
  151. /**
  152. * Copies this attribute and returns a new copy.
  153. */
  154. public AttributeInfo copy(ConstPool newCp, Map classnames) {
  155. Copier copier = new Copier(info, constPool, newCp, classnames);
  156. try {
  157. copier.annotationArray();
  158. return new AnnotationsAttribute(newCp, getName(), copier.close());
  159. }
  160. catch (Exception e) {
  161. throw new RuntimeException(e);
  162. }
  163. }
  164. /**
  165. * Parses the annotations and returns a data structure representing
  166. * the annotation with the specified type. See also
  167. * <code>getAnnotations()</code> as to the returned data structure.
  168. *
  169. * @param type the annotation type.
  170. * @return null if the specified annotation type is not included.
  171. * @see #getAnnotations()
  172. */
  173. public Annotation getAnnotation(String type) {
  174. Annotation[] annotations = getAnnotations();
  175. for (int i = 0; i < annotations.length; i++) {
  176. if (annotations[i].getTypeName().equals(type))
  177. return annotations[i];
  178. }
  179. return null;
  180. }
  181. /**
  182. * Adds an annotation. If there is an annotation with the same type,
  183. * it is removed before the new annotation is added.
  184. *
  185. * @param annotation the added annotation.
  186. */
  187. public void addAnnotation(Annotation annotation) {
  188. String type = annotation.getTypeName();
  189. Annotation[] annotations = getAnnotations();
  190. for (int i = 0; i < annotations.length; i++) {
  191. if (annotations[i].getTypeName().equals(type)) {
  192. annotations[i] = annotation;
  193. setAnnotations(annotations);
  194. return;
  195. }
  196. }
  197. Annotation[] newlist = new Annotation[annotations.length + 1];
  198. System.arraycopy(annotations, 0, newlist, 0, annotations.length);
  199. newlist[annotations.length] = annotation;
  200. setAnnotations(newlist);
  201. }
  202. /**
  203. * Parses the annotations and returns a data structure representing
  204. * that parsed annotations. Note that changes of the node values of the
  205. * returned tree are not reflected on the annotations represented by
  206. * this object unless the tree is copied back to this object by
  207. * <code>setAnnotations()</code>.
  208. *
  209. * @see #setAnnotations(Annotation[])
  210. */
  211. public Annotation[] getAnnotations() {
  212. try {
  213. return new Parser(info, constPool).parseAnnotations();
  214. }
  215. catch (Exception e) {
  216. throw new RuntimeException(e);
  217. }
  218. }
  219. /**
  220. * Changes the annotations represented by this object according to
  221. * the given array of <code>Annotation</code> objects.
  222. *
  223. * @param annotations the data structure representing the
  224. * new annotations.
  225. */
  226. public void setAnnotations(Annotation[] annotations) {
  227. ByteArrayOutputStream output = new ByteArrayOutputStream();
  228. AnnotationsWriter writer = new AnnotationsWriter(output, constPool);
  229. try {
  230. int n = annotations.length;
  231. writer.numAnnotations(n);
  232. for (int i = 0; i < n; ++i)
  233. annotations[i].write(writer);
  234. writer.close();
  235. }
  236. catch (IOException e) {
  237. throw new RuntimeException(e); // should never reach here.
  238. }
  239. set(output.toByteArray());
  240. }
  241. /**
  242. * Changes the annotations. A call to this method is equivalent to:
  243. * <ul><pre>setAnnotations(new Annotation[] { annotation })</pre></ul>
  244. *
  245. * @param annotation the data structure representing
  246. * the new annotation.
  247. */
  248. public void setAnnotation(Annotation annotation) {
  249. setAnnotations(new Annotation[] { annotation });
  250. }
  251. /**
  252. * @param oldname a JVM class name.
  253. * @param newname a JVM class name.
  254. */
  255. void renameClass(String oldname, String newname) {
  256. HashMap map = new HashMap();
  257. map.put(oldname, newname);
  258. renameClass(map);
  259. }
  260. void renameClass(Map classnames) {
  261. Renamer renamer = new Renamer(info, getConstPool(), classnames);
  262. try {
  263. renamer.annotationArray();
  264. } catch (Exception e) {
  265. throw new RuntimeException(e);
  266. }
  267. }
  268. void getRefClasses(Map classnames) { renameClass(classnames); }
  269. /**
  270. * Returns a string representation of this object.
  271. */
  272. public String toString() {
  273. Annotation[] a = getAnnotations();
  274. StringBuilder sbuf = new StringBuilder();
  275. int i = 0;
  276. while (i < a.length) {
  277. sbuf.append(a[i++].toString());
  278. if (i != a.length)
  279. sbuf.append(", ");
  280. }
  281. return sbuf.toString();
  282. }
  283. static class Walker {
  284. byte[] info;
  285. Walker(byte[] attrInfo) {
  286. info = attrInfo;
  287. }
  288. final void parameters() throws Exception {
  289. int numParam = info[0] & 0xff;
  290. parameters(numParam, 1);
  291. }
  292. void parameters(int numParam, int pos) throws Exception {
  293. for (int i = 0; i < numParam; ++i)
  294. pos = annotationArray(pos);
  295. }
  296. final void annotationArray() throws Exception {
  297. annotationArray(0);
  298. }
  299. final int annotationArray(int pos) throws Exception {
  300. int num = ByteArray.readU16bit(info, pos);
  301. return annotationArray(pos + 2, num);
  302. }
  303. int annotationArray(int pos, int num) throws Exception {
  304. for (int i = 0; i < num; ++i)
  305. pos = annotation(pos);
  306. return pos;
  307. }
  308. final int annotation(int pos) throws Exception {
  309. int type = ByteArray.readU16bit(info, pos);
  310. int numPairs = ByteArray.readU16bit(info, pos + 2);
  311. return annotation(pos + 4, type, numPairs);
  312. }
  313. int annotation(int pos, int type, int numPairs) throws Exception {
  314. for (int j = 0; j < numPairs; ++j)
  315. pos = memberValuePair(pos);
  316. return pos;
  317. }
  318. /**
  319. * {@code element_value_paris}
  320. */
  321. final int memberValuePair(int pos) throws Exception {
  322. int nameIndex = ByteArray.readU16bit(info, pos);
  323. return memberValuePair(pos + 2, nameIndex);
  324. }
  325. /**
  326. * {@code element_value_paris[]}
  327. */
  328. int memberValuePair(int pos, int nameIndex) throws Exception {
  329. return memberValue(pos);
  330. }
  331. /**
  332. * {@code element_value}
  333. */
  334. final int memberValue(int pos) throws Exception {
  335. int tag = info[pos] & 0xff;
  336. if (tag == 'e') {
  337. int typeNameIndex = ByteArray.readU16bit(info, pos + 1);
  338. int constNameIndex = ByteArray.readU16bit(info, pos + 3);
  339. enumMemberValue(pos, typeNameIndex, constNameIndex);
  340. return pos + 5;
  341. }
  342. else if (tag == 'c') {
  343. int index = ByteArray.readU16bit(info, pos + 1);
  344. classMemberValue(pos, index);
  345. return pos + 3;
  346. }
  347. else if (tag == '@')
  348. return annotationMemberValue(pos + 1);
  349. else if (tag == '[') {
  350. int num = ByteArray.readU16bit(info, pos + 1);
  351. return arrayMemberValue(pos + 3, num);
  352. }
  353. else { // primitive types or String.
  354. int index = ByteArray.readU16bit(info, pos + 1);
  355. constValueMember(tag, index);
  356. return pos + 3;
  357. }
  358. }
  359. /**
  360. * {@code const_value_index}
  361. */
  362. void constValueMember(int tag, int index) throws Exception {}
  363. /**
  364. * {@code enum_const_value}
  365. */
  366. void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
  367. throws Exception {
  368. }
  369. /**
  370. * {@code class_info_index}
  371. */
  372. void classMemberValue(int pos, int index) throws Exception {}
  373. /**
  374. * {@code annotation_value}
  375. */
  376. int annotationMemberValue(int pos) throws Exception {
  377. return annotation(pos);
  378. }
  379. /**
  380. * {@code array_value}
  381. */
  382. int arrayMemberValue(int pos, int num) throws Exception {
  383. for (int i = 0; i < num; ++i) {
  384. pos = memberValue(pos);
  385. }
  386. return pos;
  387. }
  388. }
  389. static class Renamer extends Walker {
  390. ConstPool cpool;
  391. Map classnames;
  392. /**
  393. * Constructs a renamer. It renames some class names
  394. * into the new names specified by <code>map</code>.
  395. *
  396. * @param info the annotations attribute.
  397. * @param cp the constant pool.
  398. * @param map pairs of replaced and substituted class names.
  399. * It can be null.
  400. */
  401. Renamer(byte[] info, ConstPool cp, Map map) {
  402. super(info);
  403. cpool = cp;
  404. classnames = map;
  405. }
  406. int annotation(int pos, int type, int numPairs) throws Exception {
  407. renameType(pos - 4, type);
  408. return super.annotation(pos, type, numPairs);
  409. }
  410. void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
  411. throws Exception
  412. {
  413. renameType(pos + 1, typeNameIndex);
  414. super.enumMemberValue(pos, typeNameIndex, constNameIndex);
  415. }
  416. void classMemberValue(int pos, int index) throws Exception {
  417. renameType(pos + 1, index);
  418. super.classMemberValue(pos, index);
  419. }
  420. private void renameType(int pos, int index) {
  421. String name = cpool.getUtf8Info(index);
  422. String newName = Descriptor.rename(name, classnames);
  423. if (!name.equals(newName)) {
  424. int index2 = cpool.addUtf8Info(newName);
  425. ByteArray.write16bit(index2, info, pos);
  426. }
  427. }
  428. }
  429. static class Copier extends Walker {
  430. ByteArrayOutputStream output;
  431. AnnotationsWriter writer;
  432. ConstPool srcPool, destPool;
  433. Map classnames;
  434. /**
  435. * Constructs a copier. This copier renames some class names
  436. * into the new names specified by <code>map</code> when it copies
  437. * an annotation attribute.
  438. *
  439. * @param info the source attribute.
  440. * @param src the constant pool of the source class.
  441. * @param dest the constant pool of the destination class.
  442. * @param map pairs of replaced and substituted class names.
  443. * It can be null.
  444. */
  445. Copier(byte[] info, ConstPool src, ConstPool dest, Map map) {
  446. this(info, src, dest, map, true);
  447. }
  448. Copier(byte[] info, ConstPool src, ConstPool dest, Map map, boolean makeWriter) {
  449. super(info);
  450. output = new ByteArrayOutputStream();
  451. if (makeWriter)
  452. writer = new AnnotationsWriter(output, dest);
  453. srcPool = src;
  454. destPool = dest;
  455. classnames = map;
  456. }
  457. byte[] close() throws IOException {
  458. writer.close();
  459. return output.toByteArray();
  460. }
  461. void parameters(int numParam, int pos) throws Exception {
  462. writer.numParameters(numParam);
  463. super.parameters(numParam, pos);
  464. }
  465. int annotationArray(int pos, int num) throws Exception {
  466. writer.numAnnotations(num);
  467. return super.annotationArray(pos, num);
  468. }
  469. int annotation(int pos, int type, int numPairs) throws Exception {
  470. writer.annotation(copyType(type), numPairs);
  471. return super.annotation(pos, type, numPairs);
  472. }
  473. int memberValuePair(int pos, int nameIndex) throws Exception {
  474. writer.memberValuePair(copy(nameIndex));
  475. return super.memberValuePair(pos, nameIndex);
  476. }
  477. void constValueMember(int tag, int index) throws Exception {
  478. writer.constValueIndex(tag, copy(index));
  479. super.constValueMember(tag, index);
  480. }
  481. void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
  482. throws Exception
  483. {
  484. writer.enumConstValue(copyType(typeNameIndex), copy(constNameIndex));
  485. super.enumMemberValue(pos, typeNameIndex, constNameIndex);
  486. }
  487. void classMemberValue(int pos, int index) throws Exception {
  488. writer.classInfoIndex(copyType(index));
  489. super.classMemberValue(pos, index);
  490. }
  491. int annotationMemberValue(int pos) throws Exception {
  492. writer.annotationValue();
  493. return super.annotationMemberValue(pos);
  494. }
  495. int arrayMemberValue(int pos, int num) throws Exception {
  496. writer.arrayValue(num);
  497. return super.arrayMemberValue(pos, num);
  498. }
  499. /**
  500. * Copies a constant pool entry into the destination constant pool
  501. * and returns the index of the copied entry.
  502. *
  503. * @param srcIndex the index of the copied entry into the source
  504. * constant pool.
  505. * @return the index of the copied item into the destination
  506. * constant pool.
  507. */
  508. int copy(int srcIndex) {
  509. return srcPool.copy(srcIndex, destPool, classnames);
  510. }
  511. /**
  512. * Copies a constant pool entry into the destination constant pool
  513. * and returns the index of the copied entry. That entry must be
  514. * a Utf8Info representing a class name in the L<class name>; form.
  515. *
  516. * @param srcIndex the index of the copied entry into the source
  517. * constant pool.
  518. * @return the index of the copied item into the destination
  519. * constant pool.
  520. */
  521. int copyType(int srcIndex) {
  522. String name = srcPool.getUtf8Info(srcIndex);
  523. String newName = Descriptor.rename(name, classnames);
  524. return destPool.addUtf8Info(newName);
  525. }
  526. }
  527. static class Parser extends Walker {
  528. ConstPool pool;
  529. Annotation[][] allParams; // all parameters
  530. Annotation[] allAnno; // all annotations
  531. Annotation currentAnno; // current annotation
  532. MemberValue currentMember; // current member
  533. /**
  534. * Constructs a parser. This parser constructs a parse tree of
  535. * the annotations.
  536. *
  537. * @param info the attribute.
  538. * @param src the constant pool.
  539. */
  540. Parser(byte[] info, ConstPool cp) {
  541. super(info);
  542. pool = cp;
  543. }
  544. Annotation[][] parseParameters() throws Exception {
  545. parameters();
  546. return allParams;
  547. }
  548. Annotation[] parseAnnotations() throws Exception {
  549. annotationArray();
  550. return allAnno;
  551. }
  552. MemberValue parseMemberValue() throws Exception {
  553. memberValue(0);
  554. return currentMember;
  555. }
  556. void parameters(int numParam, int pos) throws Exception {
  557. Annotation[][] params = new Annotation[numParam][];
  558. for (int i = 0; i < numParam; ++i) {
  559. pos = annotationArray(pos);
  560. params[i] = allAnno;
  561. }
  562. allParams = params;
  563. }
  564. int annotationArray(int pos, int num) throws Exception {
  565. Annotation[] array = new Annotation[num];
  566. for (int i = 0; i < num; ++i) {
  567. pos = annotation(pos);
  568. array[i] = currentAnno;
  569. }
  570. allAnno = array;
  571. return pos;
  572. }
  573. int annotation(int pos, int type, int numPairs) throws Exception {
  574. currentAnno = new Annotation(type, pool);
  575. return super.annotation(pos, type, numPairs);
  576. }
  577. int memberValuePair(int pos, int nameIndex) throws Exception {
  578. pos = super.memberValuePair(pos, nameIndex);
  579. currentAnno.addMemberValue(nameIndex, currentMember);
  580. return pos;
  581. }
  582. void constValueMember(int tag, int index) throws Exception {
  583. MemberValue m;
  584. ConstPool cp = pool;
  585. switch (tag) {
  586. case 'B' :
  587. m = new ByteMemberValue(index, cp);
  588. break;
  589. case 'C' :
  590. m = new CharMemberValue(index, cp);
  591. break;
  592. case 'D' :
  593. m = new DoubleMemberValue(index, cp);
  594. break;
  595. case 'F' :
  596. m = new FloatMemberValue(index, cp);
  597. break;
  598. case 'I' :
  599. m = new IntegerMemberValue(index, cp);
  600. break;
  601. case 'J' :
  602. m = new LongMemberValue(index, cp);
  603. break;
  604. case 'S' :
  605. m = new ShortMemberValue(index, cp);
  606. break;
  607. case 'Z' :
  608. m = new BooleanMemberValue(index, cp);
  609. break;
  610. case 's' :
  611. m = new StringMemberValue(index, cp);
  612. break;
  613. default :
  614. throw new RuntimeException("unknown tag:" + tag);
  615. }
  616. currentMember = m;
  617. super.constValueMember(tag, index);
  618. }
  619. void enumMemberValue(int pos, int typeNameIndex, int constNameIndex)
  620. throws Exception
  621. {
  622. currentMember = new EnumMemberValue(typeNameIndex,
  623. constNameIndex, pool);
  624. super.enumMemberValue(pos, typeNameIndex, constNameIndex);
  625. }
  626. void classMemberValue(int pos, int index) throws Exception {
  627. currentMember = new ClassMemberValue(index, pool);
  628. super.classMemberValue(pos, index);
  629. }
  630. int annotationMemberValue(int pos) throws Exception {
  631. Annotation anno = currentAnno;
  632. pos = super.annotationMemberValue(pos);
  633. currentMember = new AnnotationMemberValue(currentAnno, pool);
  634. currentAnno = anno;
  635. return pos;
  636. }
  637. int arrayMemberValue(int pos, int num) throws Exception {
  638. ArrayMemberValue amv = new ArrayMemberValue(pool);
  639. MemberValue[] elements = new MemberValue[num];
  640. for (int i = 0; i < num; ++i) {
  641. pos = memberValue(pos);
  642. elements[i] = currentMember;
  643. }
  644. amv.setValue(elements);
  645. currentMember = amv;
  646. return pos;
  647. }
  648. }
  649. }