1. package com.sun.org.apache.bcel.internal.generic;
  2. /* ====================================================================
  3. * The Apache Software License, Version 1.1
  4. *
  5. * Copyright (c) 2001 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Apache" and "Apache Software Foundation" and
  28. * "Apache BCEL" must not be used to endorse or promote products
  29. * derived from this software without prior written permission. For
  30. * written permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * "Apache BCEL", nor may "Apache" appear in their name, without
  34. * prior written permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation. For more
  52. * information on the Apache Software Foundation, please see
  53. * <http://www.apache.org/>.
  54. */
  55. import com.sun.org.apache.bcel.internal.Constants;
  56. import com.sun.org.apache.bcel.internal.classfile.*;
  57. import java.util.HashMap;
  58. /**
  59. * This class is used to build up a constant pool. The user adds
  60. * constants via `addXXX' methods, `addString', `addClass',
  61. * etc.. These methods return an index into the constant
  62. * pool. Finally, `getFinalConstantPool()' returns the constant pool
  63. * built up. Intermediate versions of the constant pool can be
  64. * obtained with `getConstantPool()'. A constant pool has capacity for
  65. * Constants.MAX_SHORT entries. Note that the first (0) is used by the
  66. * JVM and that Double and Long constants need two slots.
  67. *
  68. * @version $Id: ConstantPoolGen.java,v 1.1.1.1 2001/10/29 20:00:08 jvanzyl Exp $
  69. * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  70. * @see Constant
  71. */
  72. public class ConstantPoolGen {
  73. protected int size = 1024; // Inital size, sufficient in most cases
  74. protected Constant[] constants = new Constant[size];
  75. protected int index = 1; // First entry (0) used by JVM
  76. private static final String METHODREF_DELIM = ":";
  77. private static final String IMETHODREF_DELIM = "#";
  78. private static final String FIELDREF_DELIM = "&";
  79. private static final String NAT_DELIM = "%";
  80. private static class Index {
  81. int index;
  82. Index(int i) { index = i; }
  83. }
  84. /**
  85. * Initialize with given array of constants.
  86. *
  87. * @param c array of given constants, new ones will be appended
  88. */
  89. public ConstantPoolGen(Constant[] cs) {
  90. if(cs.length > size) {
  91. size = cs.length;
  92. constants = new Constant[size];
  93. }
  94. System.arraycopy(cs, 0, constants, 0, cs.length);
  95. if(cs.length > 0)
  96. index = cs.length;
  97. for(int i=1; i < index; i++) {
  98. Constant c = constants[i];
  99. if(c instanceof ConstantString) {
  100. ConstantString s = (ConstantString)c;
  101. ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
  102. string_table.put(u8.getBytes(), new Index(i));
  103. } else if(c instanceof ConstantClass) {
  104. ConstantClass s = (ConstantClass)c;
  105. ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
  106. class_table.put(u8.getBytes(), new Index(i));
  107. } else if(c instanceof ConstantNameAndType) {
  108. ConstantNameAndType n = (ConstantNameAndType)c;
  109. ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
  110. ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
  111. n_a_t_table.put(u8.getBytes() + NAT_DELIM + u8_2.getBytes(), new Index(i));
  112. } else if(c instanceof ConstantUtf8) {
  113. ConstantUtf8 u = (ConstantUtf8)c;
  114. utf8_table.put(u.getBytes(), new Index(i));
  115. } else if(c instanceof ConstantCP) {
  116. ConstantCP m = (ConstantCP)c;
  117. ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
  118. ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
  119. ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
  120. String class_name = u8.getBytes().replace('/', '.');
  121. u8 = (ConstantUtf8)constants[n.getNameIndex()];
  122. String method_name = u8.getBytes();
  123. u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
  124. String signature = u8.getBytes();
  125. String delim = METHODREF_DELIM;
  126. if(c instanceof ConstantInterfaceMethodref)
  127. delim = IMETHODREF_DELIM;
  128. else if(c instanceof ConstantFieldref)
  129. delim = FIELDREF_DELIM;
  130. cp_table.put(class_name + delim + method_name + delim + signature, new Index(i));
  131. }
  132. }
  133. }
  134. /**
  135. * Initialize with given constant pool.
  136. */
  137. public ConstantPoolGen(ConstantPool cp) {
  138. this(cp.getConstantPool());
  139. }
  140. /**
  141. * Create empty constant pool.
  142. */
  143. public ConstantPoolGen() {}
  144. /** Resize internal array of constants.
  145. */
  146. protected void adjustSize() {
  147. if(index + 3 >= size) {
  148. Constant[] cs = constants;
  149. size *= 2;
  150. constants = new Constant[size];
  151. System.arraycopy(cs, 0, constants, 0, index);
  152. }
  153. }
  154. private HashMap string_table = new HashMap();
  155. /**
  156. * Look for ConstantString in ConstantPool containing String `str'.
  157. *
  158. * @param str String to search for
  159. * @return index on success, -1 otherwise
  160. */
  161. public int lookupString(String str) {
  162. Index index = (Index)string_table.get(str);
  163. return (index != null)? index.index : -1;
  164. }
  165. /**
  166. * Add a new String constant to the ConstantPool, if it is not already in there.
  167. *
  168. * @param str String to add
  169. * @return index of entry
  170. */
  171. public int addString(String str) {
  172. int ret;
  173. if((ret = lookupString(str)) != -1)
  174. return ret; // Already in CP
  175. adjustSize();
  176. ConstantUtf8 u8 = new ConstantUtf8(str);
  177. ConstantString s = new ConstantString(index);
  178. constants[index++] = u8;
  179. ret = index;
  180. constants[index++] = s;
  181. string_table.put(str, new Index(ret));
  182. return ret;
  183. }
  184. private HashMap class_table = new HashMap();
  185. /**
  186. * Look for ConstantClass in ConstantPool named `str'.
  187. *
  188. * @param str String to search for
  189. * @return index on success, -1 otherwise
  190. */
  191. public int lookupClass(String str) {
  192. Index index = (Index)class_table.get(str.replace('.', '/'));
  193. return (index != null)? index.index : -1;
  194. }
  195. private int addClass_(String clazz) {
  196. int ret;
  197. if((ret = lookupClass(clazz)) != -1)
  198. return ret; // Already in CP
  199. adjustSize();
  200. ConstantClass c = new ConstantClass(addUtf8(clazz));
  201. ret = index;
  202. constants[index++] = c;
  203. class_table.put(clazz, new Index(ret));
  204. return ret;
  205. }
  206. /**
  207. * Add a new Class reference to the ConstantPool, if it is not already in there.
  208. *
  209. * @param str Class to add
  210. * @return index of entry
  211. */
  212. public int addClass(String str) {
  213. return addClass_(str.replace('.', '/'));
  214. }
  215. /**
  216. * Add a new Class reference to the ConstantPool for a given type.
  217. *
  218. * @param str Class to add
  219. * @return index of entry
  220. */
  221. public int addClass(ObjectType type) {
  222. return addClass(type.getClassName());
  223. }
  224. /**
  225. * Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
  226. * instruction, e.g. to the ConstantPool.
  227. *
  228. * @param type type of array class
  229. * @return index of entry
  230. */
  231. public int addArrayClass(ArrayType type) {
  232. return addClass_(type.getSignature());
  233. }
  234. /**
  235. * Look for ConstantInteger in ConstantPool.
  236. *
  237. * @param n integer number to look for
  238. * @return index on success, -1 otherwise
  239. */
  240. public int lookupInteger(int n) {
  241. for(int i=1; i < index; i++) {
  242. if(constants[i] instanceof ConstantInteger) {
  243. ConstantInteger c = (ConstantInteger)constants[i];
  244. if(c.getBytes() == n)
  245. return i;
  246. }
  247. }
  248. return -1;
  249. }
  250. /**
  251. * Add a new Integer constant to the ConstantPool, if it is not already in there.
  252. *
  253. * @param n integer number to add
  254. * @return index of entry
  255. */
  256. public int addInteger(int n) {
  257. int ret;
  258. if((ret = lookupInteger(n)) != -1)
  259. return ret; // Already in CP
  260. adjustSize();
  261. ret = index;
  262. constants[index++] = new ConstantInteger(n);
  263. return ret;
  264. }
  265. /**
  266. * Look for ConstantFloat in ConstantPool.
  267. *
  268. * @param n Float number to look for
  269. * @return index on success, -1 otherwise
  270. */
  271. public int lookupFloat(float n) {
  272. for(int i=1; i < index; i++) {
  273. if(constants[i] instanceof ConstantFloat) {
  274. ConstantFloat c = (ConstantFloat)constants[i];
  275. if(c.getBytes() == n)
  276. return i;
  277. }
  278. }
  279. return -1;
  280. }
  281. /**
  282. * Add a new Float constant to the ConstantPool, if it is not already in there.
  283. *
  284. * @param n Float number to add
  285. * @return index of entry
  286. */
  287. public int addFloat(float n) {
  288. int ret;
  289. if((ret = lookupFloat(n)) != -1)
  290. return ret; // Already in CP
  291. adjustSize();
  292. ret = index;
  293. constants[index++] = new ConstantFloat(n);
  294. return ret;
  295. }
  296. private HashMap utf8_table = new HashMap();
  297. /**
  298. * Look for ConstantUtf8 in ConstantPool.
  299. *
  300. * @param n Utf8 string to look for
  301. * @return index on success, -1 otherwise
  302. */
  303. public int lookupUtf8(String n) {
  304. Index index = (Index)utf8_table.get(n);
  305. return (index != null)? index.index : -1;
  306. }
  307. /**
  308. * Add a new Utf8 constant to the ConstantPool, if it is not already in there.
  309. *
  310. * @param n Utf8 string to add
  311. * @return index of entry
  312. */
  313. public int addUtf8(String n) {
  314. int ret;
  315. if((ret = lookupUtf8(n)) != -1)
  316. return ret; // Already in CP
  317. adjustSize();
  318. ret = index;
  319. constants[index++] = new ConstantUtf8(n);
  320. utf8_table.put(n, new Index(ret));
  321. return ret;
  322. }
  323. /**
  324. * Look for ConstantLong in ConstantPool.
  325. *
  326. * @param n Long number to look for
  327. * @return index on success, -1 otherwise
  328. */
  329. public int lookupLong(long n) {
  330. for(int i=1; i < index; i++) {
  331. if(constants[i] instanceof ConstantLong) {
  332. ConstantLong c = (ConstantLong)constants[i];
  333. if(c.getBytes() == n)
  334. return i;
  335. }
  336. }
  337. return -1;
  338. }
  339. /**
  340. * Add a new long constant to the ConstantPool, if it is not already in there.
  341. *
  342. * @param n Long number to add
  343. * @return index of entry
  344. */
  345. public int addLong(long n) {
  346. int ret;
  347. if((ret = lookupLong(n)) != -1)
  348. return ret; // Already in CP
  349. adjustSize();
  350. ret = index;
  351. constants[index] = new ConstantLong(n);
  352. index += 2; // Wastes one entry according to spec
  353. return ret;
  354. }
  355. /**
  356. * Look for ConstantDouble in ConstantPool.
  357. *
  358. * @param n Double number to look for
  359. * @return index on success, -1 otherwise
  360. */
  361. public int lookupDouble(double n) {
  362. for(int i=1; i < index; i++) {
  363. if(constants[i] instanceof ConstantDouble) {
  364. ConstantDouble c = (ConstantDouble)constants[i];
  365. if(c.getBytes() == n)
  366. return i;
  367. }
  368. }
  369. return -1;
  370. }
  371. /**
  372. * Add a new double constant to the ConstantPool, if it is not already in there.
  373. *
  374. * @param n Double number to add
  375. * @return index of entry
  376. */
  377. public int addDouble(double n) {
  378. int ret;
  379. if((ret = lookupDouble(n)) != -1)
  380. return ret; // Already in CP
  381. adjustSize();
  382. ret = index;
  383. constants[index] = new ConstantDouble(n);
  384. index += 2; // Wastes one entry according to spec
  385. return ret;
  386. }
  387. private HashMap n_a_t_table = new HashMap();
  388. /**
  389. * Look for ConstantNameAndType in ConstantPool.
  390. *
  391. * @param name of variable/method
  392. * @param signature of variable/method
  393. * @return index on success, -1 otherwise
  394. */
  395. public int lookupNameAndType(String name, String signature) {
  396. Index index = (Index)n_a_t_table.get(name + NAT_DELIM + signature);
  397. return (index != null)? index.index : -1;
  398. }
  399. /**
  400. * Add a new NameAndType constant to the ConstantPool if it is not already
  401. * in there.
  402. *
  403. * @param n NameAndType string to add
  404. * @return index of entry
  405. */
  406. public int addNameAndType(String name, String signature) {
  407. int ret;
  408. int name_index, signature_index;
  409. if((ret = lookupNameAndType(name, signature)) != -1)
  410. return ret; // Already in CP
  411. adjustSize();
  412. name_index = addUtf8(name);
  413. signature_index = addUtf8(signature);
  414. ret = index;
  415. constants[index++] = new ConstantNameAndType(name_index, signature_index);
  416. n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret));
  417. return ret;
  418. }
  419. private HashMap cp_table = new HashMap();
  420. /**
  421. * Look for ConstantMethodref in ConstantPool.
  422. *
  423. * @param class_name Where to find method
  424. * @param method_name Guess what
  425. * @param signature return and argument types
  426. * @return index on success, -1 otherwise
  427. */
  428. public int lookupMethodref(String class_name, String method_name, String signature) {
  429. Index index = (Index)cp_table.get(class_name + METHODREF_DELIM + method_name +
  430. METHODREF_DELIM + signature);
  431. return (index != null)? index.index : -1;
  432. }
  433. public int lookupMethodref(MethodGen method) {
  434. return lookupMethodref(method.getClassName(), method.getName(),
  435. method.getSignature());
  436. }
  437. /**
  438. * Add a new Methodref constant to the ConstantPool, if it is not already
  439. * in there.
  440. *
  441. * @param n Methodref string to add
  442. * @return index of entry
  443. */
  444. public int addMethodref(String class_name, String method_name, String signature) {
  445. int ret, class_index, name_and_type_index;
  446. if((ret = lookupMethodref(class_name, method_name, signature)) != -1)
  447. return ret; // Already in CP
  448. adjustSize();
  449. name_and_type_index = addNameAndType(method_name, signature);
  450. class_index = addClass(class_name);
  451. ret = index;
  452. constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
  453. cp_table.put(class_name + METHODREF_DELIM + method_name +
  454. METHODREF_DELIM + signature, new Index(ret));
  455. return ret;
  456. }
  457. public int addMethodref(MethodGen method) {
  458. return addMethodref(method.getClassName(), method.getName(),
  459. method.getSignature());
  460. }
  461. /**
  462. * Look for ConstantInterfaceMethodref in ConstantPool.
  463. *
  464. * @param class_name Where to find method
  465. * @param method_name Guess what
  466. * @param signature return and argument types
  467. * @return index on success, -1 otherwise
  468. */
  469. public int lookupInterfaceMethodref(String class_name, String method_name, String signature) {
  470. Index index = (Index)cp_table.get(class_name + IMETHODREF_DELIM + method_name +
  471. IMETHODREF_DELIM + signature);
  472. return (index != null)? index.index : -1;
  473. }
  474. public int lookupInterfaceMethodref(MethodGen method) {
  475. return lookupInterfaceMethodref(method.getClassName(), method.getName(),
  476. method.getSignature());
  477. }
  478. /**
  479. * Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
  480. * in there.
  481. *
  482. * @param n InterfaceMethodref string to add
  483. * @return index of entry
  484. */
  485. public int addInterfaceMethodref(String class_name, String method_name, String signature) {
  486. int ret, class_index, name_and_type_index;
  487. if((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1)
  488. return ret; // Already in CP
  489. adjustSize();
  490. class_index = addClass(class_name);
  491. name_and_type_index = addNameAndType(method_name, signature);
  492. ret = index;
  493. constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
  494. cp_table.put(class_name + IMETHODREF_DELIM + method_name +
  495. IMETHODREF_DELIM + signature, new Index(ret));
  496. return ret;
  497. }
  498. public int addInterfaceMethodref(MethodGen method) {
  499. return addInterfaceMethodref(method.getClassName(), method.getName(),
  500. method.getSignature());
  501. }
  502. /**
  503. * Look for ConstantFieldref in ConstantPool.
  504. *
  505. * @param class_name Where to find method
  506. * @param field_name Guess what
  507. * @param signature return and argument types
  508. * @return index on success, -1 otherwise
  509. */
  510. public int lookupFieldref(String class_name, String field_name, String signature) {
  511. Index index = (Index)cp_table.get(class_name + FIELDREF_DELIM + field_name +
  512. FIELDREF_DELIM + signature);
  513. return (index != null)? index.index : -1;
  514. }
  515. /**
  516. * Add a new Fieldref constant to the ConstantPool, if it is not already
  517. * in there.
  518. *
  519. * @param n Fieldref string to add
  520. * @return index of entry
  521. */
  522. public int addFieldref(String class_name, String field_name, String signature) {
  523. int ret;
  524. int class_index, name_and_type_index;
  525. if((ret = lookupFieldref(class_name, field_name, signature)) != -1)
  526. return ret; // Already in CP
  527. adjustSize();
  528. class_index = addClass(class_name);
  529. name_and_type_index = addNameAndType(field_name, signature);
  530. ret = index;
  531. constants[index++] = new ConstantFieldref(class_index, name_and_type_index);
  532. cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret));
  533. return ret;
  534. }
  535. /**
  536. * @param i index in constant pool
  537. * @return constant pool entry at index i
  538. */
  539. public Constant getConstant(int i) { return constants[i]; }
  540. /**
  541. * Use with care!
  542. *
  543. * @param i index in constant pool
  544. * @param c new constant pool entry at index i
  545. */
  546. public void setConstant(int i, Constant c) { constants[i] = c; }
  547. /**
  548. * @return intermediate constant pool
  549. */
  550. public ConstantPool getConstantPool() {
  551. return new ConstantPool(constants);
  552. }
  553. /**
  554. * @return current size of constant pool
  555. */
  556. public int getSize() {
  557. return index;
  558. }
  559. /**
  560. * @return constant pool with proper length
  561. */
  562. public ConstantPool getFinalConstantPool() {
  563. Constant[] cs = new Constant[index];
  564. System.arraycopy(constants, 0, cs, 0, index);
  565. return new ConstantPool(cs);
  566. }
  567. /**
  568. * @return String representation.
  569. */
  570. public String toString() {
  571. StringBuffer buf = new StringBuffer();
  572. for(int i=1; i < index; i++)
  573. buf.append(i + ")" + constants[i] + "\n");
  574. return buf.toString();
  575. }
  576. /** Import constant from another ConstantPool and return new index.
  577. */
  578. public int addConstant(Constant c, ConstantPoolGen cp) {
  579. Constant[] constants = cp.getConstantPool().getConstantPool();
  580. switch(c.getTag()) {
  581. case Constants.CONSTANT_String: {
  582. ConstantString s = (ConstantString)c;
  583. ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
  584. return addString(u8.getBytes());
  585. }
  586. case Constants.CONSTANT_Class: {
  587. ConstantClass s = (ConstantClass)c;
  588. ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
  589. return addClass(u8.getBytes());
  590. }
  591. case Constants.CONSTANT_NameAndType: {
  592. ConstantNameAndType n = (ConstantNameAndType)c;
  593. ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
  594. ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
  595. return addNameAndType(u8.getBytes(), u8_2.getBytes());
  596. }
  597. case Constants.CONSTANT_Utf8:
  598. return addUtf8(((ConstantUtf8)c).getBytes());
  599. case Constants.CONSTANT_Double:
  600. return addDouble(((ConstantDouble)c).getBytes());
  601. case Constants.CONSTANT_Float:
  602. return addFloat(((ConstantFloat)c).getBytes());
  603. case Constants.CONSTANT_Long:
  604. return addLong(((ConstantLong)c).getBytes());
  605. case Constants.CONSTANT_Integer:
  606. return addInteger(((ConstantInteger)c).getBytes());
  607. case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  608. case Constants.CONSTANT_Fieldref: {
  609. ConstantCP m = (ConstantCP)c;
  610. ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
  611. ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
  612. ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
  613. String class_name = u8.getBytes().replace('/', '.');
  614. u8 = (ConstantUtf8)constants[n.getNameIndex()];
  615. String name = u8.getBytes();
  616. u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
  617. String signature = u8.getBytes();
  618. switch(c.getTag()) {
  619. case Constants.CONSTANT_InterfaceMethodref:
  620. return addInterfaceMethodref(class_name, name, signature);
  621. case Constants.CONSTANT_Methodref:
  622. return addMethodref(class_name, name, signature);
  623. case Constants.CONSTANT_Fieldref:
  624. return addFieldref(class_name, name, signature);
  625. default: // Never reached
  626. throw new RuntimeException("Unknown constant type " + c);
  627. }
  628. }
  629. default: // Never reached
  630. throw new RuntimeException("Unknown constant type " + c);
  631. }
  632. }
  633. }