KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > bcel > internal > generic > ConstantPoolGen


1 package com.sun.org.apache.bcel.internal.generic;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache BCEL" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache BCEL", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import com.sun.org.apache.bcel.internal.Constants;
58 import com.sun.org.apache.bcel.internal.classfile.*;
59 import java.util.HashMap JavaDoc;
60
61 /**
62  * This class is used to build up a constant pool. The user adds
63  * constants via `addXXX' methods, `addString', `addClass',
64  * etc.. These methods return an index into the constant
65  * pool. Finally, `getFinalConstantPool()' returns the constant pool
66  * built up. Intermediate versions of the constant pool can be
67  * obtained with `getConstantPool()'. A constant pool has capacity for
68  * Constants.MAX_SHORT entries. Note that the first (0) is used by the
69  * JVM and that Double and Long constants need two slots.
70  *
71  * @version $Id: ConstantPoolGen.java,v 1.1.1.1 2001/10/29 20:00:08 jvanzyl Exp $
72  * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
73  * @see Constant
74  */

75 public class ConstantPoolGen {
76   protected int size = 1024; // Inital size, sufficient in most cases
77
protected Constant[] constants = new Constant[size];
78   protected int index = 1; // First entry (0) used by JVM
79

80   private static final String JavaDoc METHODREF_DELIM = ":";
81   private static final String JavaDoc IMETHODREF_DELIM = "#";
82   private static final String JavaDoc FIELDREF_DELIM = "&";
83   private static final String JavaDoc NAT_DELIM = "%";
84
85   private static class Index {
86     int index;
87     Index(int i) { index = i; }
88   }
89
90   /**
91    * Initialize with given array of constants.
92    *
93    * @param c array of given constants, new ones will be appended
94    */

95   public ConstantPoolGen(Constant[] cs) {
96     if(cs.length > size) {
97       size = cs.length;
98       constants = new Constant[size];
99     }
100
101     System.arraycopy(cs, 0, constants, 0, cs.length);
102
103     if(cs.length > 0)
104       index = cs.length;
105
106     for(int i=1; i < index; i++) {
107       Constant c = constants[i];
108
109       if(c instanceof ConstantString) {
110     ConstantString s = (ConstantString)c;
111     ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
112
113     string_table.put(u8.getBytes(), new Index(i));
114       } else if(c instanceof ConstantClass) {
115     ConstantClass s = (ConstantClass)c;
116     ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
117
118     class_table.put(u8.getBytes(), new Index(i));
119       } else if(c instanceof ConstantNameAndType) {
120     ConstantNameAndType n = (ConstantNameAndType)c;
121     ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
122     ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
123
124     n_a_t_table.put(u8.getBytes() + NAT_DELIM + u8_2.getBytes(), new Index(i));
125        } else if(c instanceof ConstantUtf8) {
126          ConstantUtf8 u = (ConstantUtf8)c;
127          
128          utf8_table.put(u.getBytes(), new Index(i));
129       } else if(c instanceof ConstantCP) {
130     ConstantCP m = (ConstantCP)c;
131     ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
132     ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
133     
134         ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
135         String JavaDoc class_name = u8.getBytes().replace('/', '.');
136
137     u8 = (ConstantUtf8)constants[n.getNameIndex()];
138     String JavaDoc method_name = u8.getBytes();
139
140     u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
141     String JavaDoc signature = u8.getBytes();
142
143     String JavaDoc delim = METHODREF_DELIM;
144
145     if(c instanceof ConstantInterfaceMethodref)
146       delim = IMETHODREF_DELIM;
147     else if(c instanceof ConstantFieldref)
148       delim = FIELDREF_DELIM;
149
150     cp_table.put(class_name + delim + method_name + delim + signature, new Index(i));
151       }
152     }
153   }
154
155   /**
156    * Initialize with given constant pool.
157    */

158   public ConstantPoolGen(ConstantPool cp) {
159     this(cp.getConstantPool());
160   }
161
162   /**
163    * Create empty constant pool.
164    */

165   public ConstantPoolGen() {}
166
167   /** Resize internal array of constants.
168    */

169   protected void adjustSize() {
170     if(index + 3 >= size) {
171       Constant[] cs = constants;
172
173       size *= 2;
174       constants = new Constant[size];
175       System.arraycopy(cs, 0, constants, 0, index);
176     }
177   }
178
179   private HashMap JavaDoc string_table = new HashMap JavaDoc();
180
181   /**
182    * Look for ConstantString in ConstantPool containing String `str'.
183    *
184    * @param str String to search for
185    * @return index on success, -1 otherwise
186    */

187   public int lookupString(String JavaDoc str) {
188     Index index = (Index)string_table.get(str);
189     return (index != null)? index.index : -1;
190   }
191   
192   /**
193    * Add a new String constant to the ConstantPool, if it is not already in there.
194    *
195    * @param str String to add
196    * @return index of entry
197    */

198   public int addString(String JavaDoc str) {
199     int ret;
200     
201     if((ret = lookupString(str)) != -1)
202       return ret; // Already in CP
203

204     adjustSize();
205
206     ConstantUtf8 u8 = new ConstantUtf8(str);
207     ConstantString s = new ConstantString(index);
208        
209     constants[index++] = u8;
210     ret = index;
211     constants[index++] = s;
212
213     string_table.put(str, new Index(ret));
214
215     return ret;
216   }
217
218   private HashMap JavaDoc class_table = new HashMap JavaDoc();
219
220   /**
221    * Look for ConstantClass in ConstantPool named `str'.
222    *
223    * @param str String to search for
224    * @return index on success, -1 otherwise
225    */

226   public int lookupClass(String JavaDoc str) {
227     Index index = (Index)class_table.get(str.replace('.', '/'));
228     return (index != null)? index.index : -1;
229   }
230
231   private int addClass_(String JavaDoc clazz) {
232     int ret;
233
234     if((ret = lookupClass(clazz)) != -1)
235       return ret; // Already in CP
236

237     adjustSize();
238
239     ConstantClass c = new ConstantClass(addUtf8(clazz));
240
241     ret = index;
242     constants[index++] = c;
243
244     class_table.put(clazz, new Index(ret));
245
246     return ret;
247   }
248
249   /**
250    * Add a new Class reference to the ConstantPool, if it is not already in there.
251    *
252    * @param str Class to add
253    * @return index of entry
254    */

255   public int addClass(String JavaDoc str) {
256     return addClass_(str.replace('.', '/'));
257   }
258
259   /**
260    * Add a new Class reference to the ConstantPool for a given type.
261    *
262    * @param str Class to add
263    * @return index of entry
264    */

265   public int addClass(ObjectType type) {
266     return addClass(type.getClassName());
267   }
268
269   /**
270    * Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
271    * instruction, e.g. to the ConstantPool.
272    *
273    * @param type type of array class
274    * @return index of entry
275    */

276   public int addArrayClass(ArrayType type) {
277     return addClass_(type.getSignature());
278   }
279
280   /**
281    * Look for ConstantInteger in ConstantPool.
282    *
283    * @param n integer number to look for
284    * @return index on success, -1 otherwise
285    */

286   public int lookupInteger(int n) {
287     for(int i=1; i < index; i++) {
288       if(constants[i] instanceof ConstantInteger) {
289     ConstantInteger c = (ConstantInteger)constants[i];
290
291     if(c.getBytes() == n)
292       return i;
293       }
294     }
295
296     return -1;
297   }
298
299   /**
300    * Add a new Integer constant to the ConstantPool, if it is not already in there.
301    *
302    * @param n integer number to add
303    * @return index of entry
304    */

305   public int addInteger(int n) {
306     int ret;
307
308     if((ret = lookupInteger(n)) != -1)
309       return ret; // Already in CP
310

311     adjustSize();
312
313     ret = index;
314     constants[index++] = new ConstantInteger(n);
315
316     return ret;
317   }
318
319   /**
320    * Look for ConstantFloat in ConstantPool.
321    *
322    * @param n Float number to look for
323    * @return index on success, -1 otherwise
324    */

325   public int lookupFloat(float n) {
326     for(int i=1; i < index; i++) {
327       if(constants[i] instanceof ConstantFloat) {
328     ConstantFloat c = (ConstantFloat)constants[i];
329
330     if(c.getBytes() == n)
331       return i;
332       }
333     }
334
335     return -1;
336   }
337
338   /**
339    * Add a new Float constant to the ConstantPool, if it is not already in there.
340    *
341    * @param n Float number to add
342    * @return index of entry
343    */

344   public int addFloat(float n) {
345     int ret;
346
347     if((ret = lookupFloat(n)) != -1)
348       return ret; // Already in CP
349

350     adjustSize();
351
352     ret = index;
353     constants[index++] = new ConstantFloat(n);
354
355     return ret;
356   }
357
358   private HashMap JavaDoc utf8_table = new HashMap JavaDoc();
359
360   /**
361    * Look for ConstantUtf8 in ConstantPool.
362    *
363    * @param n Utf8 string to look for
364    * @return index on success, -1 otherwise
365    */

366   public int lookupUtf8(String JavaDoc n) {
367     Index index = (Index)utf8_table.get(n);
368
369     return (index != null)? index.index : -1;
370   }
371
372   /**
373    * Add a new Utf8 constant to the ConstantPool, if it is not already in there.
374    *
375    * @param n Utf8 string to add
376    * @return index of entry
377    */

378   public int addUtf8(String JavaDoc n) {
379     int ret;
380
381     if((ret = lookupUtf8(n)) != -1)
382       return ret; // Already in CP
383

384     adjustSize();
385
386     ret = index;
387     constants[index++] = new ConstantUtf8(n);
388
389     utf8_table.put(n, new Index(ret));
390
391     return ret;
392   }
393
394   /**
395    * Look for ConstantLong in ConstantPool.
396    *
397    * @param n Long number to look for
398    * @return index on success, -1 otherwise
399    */

400   public int lookupLong(long n) {
401     for(int i=1; i < index; i++) {
402       if(constants[i] instanceof ConstantLong) {
403     ConstantLong c = (ConstantLong)constants[i];
404
405     if(c.getBytes() == n)
406       return i;
407       }
408     }
409
410     return -1;
411   }
412
413   /**
414    * Add a new long constant to the ConstantPool, if it is not already in there.
415    *
416    * @param n Long number to add
417    * @return index of entry
418    */

419   public int addLong(long n) {
420     int ret;
421
422     if((ret = lookupLong(n)) != -1)
423       return ret; // Already in CP
424

425     adjustSize();
426
427     ret = index;
428     constants[index] = new ConstantLong(n);
429     index += 2; // Wastes one entry according to spec
430

431     return ret;
432   }
433
434   /**
435    * Look for ConstantDouble in ConstantPool.
436    *
437    * @param n Double number to look for
438    * @return index on success, -1 otherwise
439    */

440   public int lookupDouble(double n) {
441     for(int i=1; i < index; i++) {
442       if(constants[i] instanceof ConstantDouble) {
443     ConstantDouble c = (ConstantDouble)constants[i];
444
445     if(c.getBytes() == n)
446       return i;
447       }
448     }
449
450     return -1;
451   }
452
453   /**
454    * Add a new double constant to the ConstantPool, if it is not already in there.
455    *
456    * @param n Double number to add
457    * @return index of entry
458    */

459   public int addDouble(double n) {
460     int ret;
461
462     if((ret = lookupDouble(n)) != -1)
463       return ret; // Already in CP
464

465     adjustSize();
466
467     ret = index;
468     constants[index] = new ConstantDouble(n);
469     index += 2; // Wastes one entry according to spec
470

471     return ret;
472   }
473
474   private HashMap JavaDoc n_a_t_table = new HashMap JavaDoc();
475
476   /**
477    * Look for ConstantNameAndType in ConstantPool.
478    *
479    * @param name of variable/method
480    * @param signature of variable/method
481    * @return index on success, -1 otherwise
482    */

483   public int lookupNameAndType(String JavaDoc name, String JavaDoc signature) {
484     Index index = (Index)n_a_t_table.get(name + NAT_DELIM + signature);
485     return (index != null)? index.index : -1;
486   }
487
488   /**
489    * Add a new NameAndType constant to the ConstantPool if it is not already
490    * in there.
491    *
492    * @param n NameAndType string to add
493    * @return index of entry
494    */

495   public int addNameAndType(String JavaDoc name, String JavaDoc signature) {
496     int ret;
497     int name_index, signature_index;
498
499     if((ret = lookupNameAndType(name, signature)) != -1)
500       return ret; // Already in CP
501

502     adjustSize();
503
504     name_index = addUtf8(name);
505     signature_index = addUtf8(signature);
506     ret = index;
507     constants[index++] = new ConstantNameAndType(name_index, signature_index);
508
509     n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret));
510     return ret;
511   }
512
513   private HashMap JavaDoc cp_table = new HashMap JavaDoc();
514
515   /**
516    * Look for ConstantMethodref in ConstantPool.
517    *
518    * @param class_name Where to find method
519    * @param method_name Guess what
520    * @param signature return and argument types
521    * @return index on success, -1 otherwise
522    */

523   public int lookupMethodref(String JavaDoc class_name, String JavaDoc method_name, String JavaDoc signature) {
524     Index index = (Index)cp_table.get(class_name + METHODREF_DELIM + method_name +
525                       METHODREF_DELIM + signature);
526     return (index != null)? index.index : -1;
527   }
528
529   public int lookupMethodref(MethodGen method) {
530     return lookupMethodref(method.getClassName(), method.getName(),
531               method.getSignature());
532   }
533
534   /**
535    * Add a new Methodref constant to the ConstantPool, if it is not already
536    * in there.
537    *
538    * @param n Methodref string to add
539    * @return index of entry
540    */

541   public int addMethodref(String JavaDoc class_name, String JavaDoc method_name, String JavaDoc signature) {
542     int ret, class_index, name_and_type_index;
543
544     if((ret = lookupMethodref(class_name, method_name, signature)) != -1)
545       return ret; // Already in CP
546

547     adjustSize();
548
549     name_and_type_index = addNameAndType(method_name, signature);
550     class_index = addClass(class_name);
551     ret = index;
552     constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
553
554     cp_table.put(class_name + METHODREF_DELIM + method_name +
555          METHODREF_DELIM + signature, new Index(ret));
556
557     return ret;
558   }
559
560   public int addMethodref(MethodGen method) {
561     return addMethodref(method.getClassName(), method.getName(),
562             method.getSignature());
563   }
564
565   /**
566    * Look for ConstantInterfaceMethodref in ConstantPool.
567    *
568    * @param class_name Where to find method
569    * @param method_name Guess what
570    * @param signature return and argument types
571    * @return index on success, -1 otherwise
572    */

573   public int lookupInterfaceMethodref(String JavaDoc class_name, String JavaDoc method_name, String JavaDoc signature) {
574     Index index = (Index)cp_table.get(class_name + IMETHODREF_DELIM + method_name +
575                       IMETHODREF_DELIM + signature);
576     return (index != null)? index.index : -1;
577   }
578
579   public int lookupInterfaceMethodref(MethodGen method) {
580     return lookupInterfaceMethodref(method.getClassName(), method.getName(),
581                     method.getSignature());
582   }
583
584   /**
585    * Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
586    * in there.
587    *
588    * @param n InterfaceMethodref string to add
589    * @return index of entry
590    */

591   public int addInterfaceMethodref(String JavaDoc class_name, String JavaDoc method_name, String JavaDoc signature) {
592     int ret, class_index, name_and_type_index;
593
594     if((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1)
595       return ret; // Already in CP
596

597     adjustSize();
598
599     class_index = addClass(class_name);
600     name_and_type_index = addNameAndType(method_name, signature);
601     ret = index;
602     constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
603
604     cp_table.put(class_name + IMETHODREF_DELIM + method_name +
605          IMETHODREF_DELIM + signature, new Index(ret));
606
607     return ret;
608   }
609
610   public int addInterfaceMethodref(MethodGen method) {
611     return addInterfaceMethodref(method.getClassName(), method.getName(),
612                  method.getSignature());
613   }
614
615   /**
616    * Look for ConstantFieldref in ConstantPool.
617    *
618    * @param class_name Where to find method
619    * @param field_name Guess what
620    * @param signature return and argument types
621    * @return index on success, -1 otherwise
622    */

623   public int lookupFieldref(String JavaDoc class_name, String JavaDoc field_name, String JavaDoc signature) {
624     Index index = (Index)cp_table.get(class_name + FIELDREF_DELIM + field_name +
625                       FIELDREF_DELIM + signature);
626     return (index != null)? index.index : -1;
627   }
628
629   /**
630    * Add a new Fieldref constant to the ConstantPool, if it is not already
631    * in there.
632    *
633    * @param n Fieldref string to add
634    * @return index of entry
635    */

636   public int addFieldref(String JavaDoc class_name, String JavaDoc field_name, String JavaDoc signature) {
637     int ret;
638     int class_index, name_and_type_index;
639
640     if((ret = lookupFieldref(class_name, field_name, signature)) != -1)
641       return ret; // Already in CP
642

643     adjustSize();
644
645     class_index = addClass(class_name);
646     name_and_type_index = addNameAndType(field_name, signature);
647     ret = index;
648     constants[index++] = new ConstantFieldref(class_index, name_and_type_index);
649
650     cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret));
651
652     return ret;
653   }
654
655   /**
656    * @param i index in constant pool
657    * @return constant pool entry at index i
658    */

659   public Constant getConstant(int i) { return constants[i]; }
660
661   /**
662    * Use with care!
663    *
664    * @param i index in constant pool
665    * @param c new constant pool entry at index i
666    */

667   public void setConstant(int i, Constant c) { constants[i] = c; }
668
669   /**
670    * @return intermediate constant pool
671    */

672   public ConstantPool getConstantPool() {
673     return new ConstantPool(constants);
674   }
675
676   /**
677    * @return current size of constant pool
678    */

679   public int getSize() {
680     return index;
681   }
682
683   /**
684    * @return constant pool with proper length
685    */

686   public ConstantPool getFinalConstantPool() {
687     Constant[] cs = new Constant[index];
688     
689     System.arraycopy(constants, 0, cs, 0, index);
690
691     return new ConstantPool(cs);
692   }
693
694   /**
695    * @return String representation.
696    */

697   public String JavaDoc toString() {
698     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
699
700     for(int i=1; i < index; i++)
701       buf.append(i + ")" + constants[i] + "\n");
702
703     return buf.toString();
704   }
705
706   /** Import constant from another ConstantPool and return new index.
707    */

708   public int addConstant(Constant c, ConstantPoolGen cp) {
709     Constant[] constants = cp.getConstantPool().getConstantPool();
710
711     switch(c.getTag()) {
712     case Constants.CONSTANT_String: {
713       ConstantString s = (ConstantString)c;
714       ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
715
716       return addString(u8.getBytes());
717     }
718
719     case Constants.CONSTANT_Class: {
720       ConstantClass s = (ConstantClass)c;
721       ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
722
723       return addClass(u8.getBytes());
724     }
725
726     case Constants.CONSTANT_NameAndType: {
727       ConstantNameAndType n = (ConstantNameAndType)c;
728       ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
729       ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
730
731       return addNameAndType(u8.getBytes(), u8_2.getBytes());
732     }
733
734     case Constants.CONSTANT_Utf8:
735       return addUtf8(((ConstantUtf8)c).getBytes());
736
737     case Constants.CONSTANT_Double:
738       return addDouble(((ConstantDouble)c).getBytes());
739
740     case Constants.CONSTANT_Float:
741       return addFloat(((ConstantFloat)c).getBytes());
742
743     case Constants.CONSTANT_Long:
744       return addLong(((ConstantLong)c).getBytes());
745
746     case Constants.CONSTANT_Integer:
747       return addInteger(((ConstantInteger)c).getBytes());
748
749     case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
750     case Constants.CONSTANT_Fieldref: {
751       ConstantCP m = (ConstantCP)c;
752       ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
753       ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
754       ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
755       String JavaDoc class_name = u8.getBytes().replace('/', '.');
756
757       u8 = (ConstantUtf8)constants[n.getNameIndex()];
758       String JavaDoc name = u8.getBytes();
759
760       u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
761       String JavaDoc signature = u8.getBytes();
762
763       switch(c.getTag()) {
764       case Constants.CONSTANT_InterfaceMethodref:
765     return addInterfaceMethodref(class_name, name, signature);
766
767       case Constants.CONSTANT_Methodref:
768     return addMethodref(class_name, name, signature);
769
770       case Constants.CONSTANT_Fieldref:
771     return addFieldref(class_name, name, signature);
772
773       default: // Never reached
774
throw new RuntimeException JavaDoc("Unknown constant type " + c);
775       }
776     }
777
778     default: // Never reached
779
throw new RuntimeException JavaDoc("Unknown constant type " + c);
780     }
781   }
782 }
783
Popular Tags