first scanner /parser copied from the jdt java version
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / codegen / ConstantPool.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.codegen;
12
13 import net.sourceforge.phpdt.internal.compiler.ClassFile;
14
15 import net.sourceforge.phpdt.internal.compiler.classfmt.ClassFileConstants;
16 import net.sourceforge.phpdt.internal.compiler.lookup.*;
17 import net.sourceforge.phpdt.internal.compiler.util.*;
18
19 /**
20  * This type is used to store all the constant pool entries.
21  */
22 public class ConstantPool implements ClassFileConstants, TypeIds {
23         public static final int DOUBLE_INITIAL_SIZE = 5;
24         public static final int FLOAT_INITIAL_SIZE = 3;
25         public static final int INT_INITIAL_SIZE = 248;
26         public static final int LONG_INITIAL_SIZE = 5;
27         public static final int UTF8_INITIAL_SIZE = 778;
28         public static final int STRING_INITIAL_SIZE = 761;
29         public static final int FIELD_INITIAL_SIZE = 156;
30         public static final int METHOD_INITIAL_SIZE = 236;
31         public static final int INTERFACE_INITIAL_SIZE = 50;
32         public static final int CLASS_INITIAL_SIZE = 86;
33         public static final int NAMEANDTYPE_INITIAL_SIZE = 272;
34         public static final int CONSTANTPOOL_INITIAL_SIZE = 2000;
35         public static final int CONSTANTPOOL_GROW_SIZE = 6000;
36         protected DoubleCache doubleCache;
37         protected FloatCache floatCache;
38         protected IntegerCache intCache;
39         protected LongCache longCache;
40         public CharArrayCache UTF8Cache;
41         protected CharArrayCache stringCache;
42         protected ObjectCache fieldCache;
43         protected ObjectCache methodCache;
44         protected ObjectCache interfaceMethodCache;
45         protected ObjectCache classCache;
46         protected FieldNameAndTypeCache nameAndTypeCacheForFields;
47         protected MethodNameAndTypeCache nameAndTypeCacheForMethods;
48         int[] wellKnownTypes = new int[21];
49         int[] wellKnownMethods = new int[36];
50         int[] wellKnownFields = new int[10];
51         int[] wellKnownFieldNameAndTypes = new int[2];
52         int[] wellKnownMethodNameAndTypes = new int[33];
53         public byte[] poolContent;
54         public int currentIndex = 1;
55         public int currentOffset;
56         // predefined constant index for well known types
57         final static int JAVA_LANG_BOOLEAN_TYPE = 0;
58         final static int JAVA_LANG_BYTE_TYPE = 1;
59         final static int JAVA_LANG_CHARACTER_TYPE = 2;
60         final static int JAVA_LANG_DOUBLE_TYPE = 3;
61         final static int JAVA_LANG_FLOAT_TYPE = 4;
62         final static int JAVA_LANG_INTEGER_TYPE = 5;
63         final static int JAVA_LANG_LONG_TYPE = 6;
64         final static int JAVA_LANG_SHORT_TYPE = 7;
65         final static int JAVA_LANG_VOID_TYPE = 8;
66         final static int JAVA_LANG_CLASS_TYPE = 9;
67         final static int JAVA_LANG_CLASSNOTFOUNDEXCEPTION_TYPE = 10;
68         final static int JAVA_LANG_NOCLASSDEFFOUNDERROR_TYPE = 11;
69         final static int JAVA_LANG_OBJECT_TYPE = 12;
70         final static int JAVA_LANG_STRING_TYPE = 13;
71         final static int JAVA_LANG_STRINGBUFFER_TYPE = 14;
72         final static int JAVA_LANG_SYSTEM_TYPE = 15;
73         final static int JAVA_LANG_THROWABLE_TYPE = 16;
74         final static int JAVA_LANG_ERROR_TYPE = 17;
75         final static int JAVA_LANG_EXCEPTION_TYPE = 18;
76         final static int JAVA_LANG_REFLECT_CONSTRUCTOR_TYPE = 19;
77         final static int JAVA_LANG_ASSERTIONERROR_TYPE = 20;
78         
79         // predefined constant index for well known fields  
80         final static int TYPE_BYTE_FIELD = 0;
81         final static int TYPE_SHORT_FIELD = 1;
82         final static int TYPE_CHARACTER_FIELD = 2;
83         final static int TYPE_INTEGER_FIELD = 3;
84         final static int TYPE_LONG_FIELD = 4;
85         final static int TYPE_FLOAT_FIELD = 5;
86         final static int TYPE_DOUBLE_FIELD = 6;
87         final static int TYPE_BOOLEAN_FIELD = 7;
88         final static int TYPE_VOID_FIELD = 8;
89         final static int OUT_SYSTEM_FIELD = 9;
90         // predefined constant index for well known methods 
91         final static int FORNAME_CLASS_METHOD = 0;
92         final static int NOCLASSDEFFOUNDERROR_CONSTR_METHOD = 1;
93         final static int APPEND_INT_METHOD = 2;
94         final static int APPEND_FLOAT_METHOD = 3;
95         final static int APPEND_LONG_METHOD = 4;
96         final static int APPEND_OBJECT_METHOD = 5;
97         final static int APPEND_CHAR_METHOD = 6;
98         final static int APPEND_STRING_METHOD = 7;
99         final static int APPEND_BOOLEAN_METHOD = 8;
100         final static int APPEND_DOUBLE_METHOD = 9;
101         final static int STRINGBUFFER_STRING_CONSTR_METHOD = 10;
102         final static int STRINGBUFFER_DEFAULT_CONSTR_METHOD = 11;
103         final static int STRINGBUFFER_TOSTRING_METHOD = 12;
104         final static int SYSTEM_EXIT_METHOD = 13;
105         final static int THROWABLE_GETMESSAGE_METHOD = 14;
106         final static int JAVALANGERROR_CONSTR_METHOD = 15;
107         final static int GETCONSTRUCTOR_CLASS_METHOD = 16;
108         final static int NEWINSTANCE_CONSTRUCTOR_METHOD = 17;
109         final static int STRING_INTERN_METHOD = 18;
110         final static int VALUEOF_INT_METHOD = 19;
111         final static int VALUEOF_FLOAT_METHOD = 20;
112         final static int VALUEOF_LONG_METHOD = 21;
113         final static int VALUEOF_OBJECT_METHOD = 22;
114         final static int VALUEOF_CHAR_METHOD = 23;
115         final static int VALUEOF_BOOLEAN_METHOD = 24;
116         final static int VALUEOF_DOUBLE_METHOD = 25;
117         final static int ASSERTIONERROR_CONSTR_OBJECT_METHOD = 26;
118         final static int ASSERTIONERROR_CONSTR_INT_METHOD = 27;
119         final static int ASSERTIONERROR_CONSTR_LONG_METHOD = 28;
120         final static int ASSERTIONERROR_CONSTR_FLOAT_METHOD = 29;
121         final static int ASSERTIONERROR_CONSTR_DOUBLE_METHOD = 30;
122         final static int ASSERTIONERROR_CONSTR_BOOLEAN_METHOD = 31;
123         final static int ASSERTIONERROR_CONSTR_CHAR_METHOD = 32;
124         final static int ASSERTIONERROR_DEFAULT_CONSTR_METHOD = 33;
125         final static int DESIREDASSERTIONSTATUS_CLASS_METHOD = 34;
126         final static int GETCLASS_OBJECT_METHOD = 35;
127         // predefined constant index for well known name and type for fields
128         final static int TYPE_JAVALANGCLASS_NAME_AND_TYPE = 0;
129         final static int OUT_SYSTEM_NAME_AND_TYPE = 1;
130         // predefined constant index for well known name and type for methods
131         final static int FORNAME_CLASS_METHOD_NAME_AND_TYPE = 0;
132         final static int CONSTR_STRING_METHOD_NAME_AND_TYPE = 1;
133         final static int DEFAULT_CONSTR_METHOD_NAME_AND_TYPE = 2;
134         final static int APPEND_INT_METHOD_NAME_AND_TYPE = 3;
135         final static int APPEND_FLOAT_METHOD_NAME_AND_TYPE = 4;
136         final static int APPEND_LONG_METHOD_NAME_AND_TYPE = 5;
137         final static int APPEND_OBJECT_METHOD_NAME_AND_TYPE = 6;
138         final static int APPEND_CHAR_METHOD_NAME_AND_TYPE = 7;
139         final static int APPEND_STRING_METHOD_NAME_AND_TYPE = 8;
140         final static int APPEND_BOOLEAN_METHOD_NAME_AND_TYPE = 9;
141         final static int APPEND_DOUBLE_METHOD_NAME_AND_TYPE = 10;
142         final static int TOSTRING_METHOD_NAME_AND_TYPE = 11;
143         final static int EXIT_METHOD_NAME_AND_TYPE = 12;
144         final static int GETMESSAGE_METHOD_NAME_AND_TYPE = 13;
145         final static int GETCONSTRUCTOR_METHOD_NAME_AND_TYPE = 14;
146         final static int NEWINSTANCE_METHOD_NAME_AND_TYPE = 15;
147         final static int INTERN_METHOD_NAME_AND_TYPE = 16;
148         final static int VALUEOF_INT_METHOD_NAME_AND_TYPE = 17;
149         final static int VALUEOF_FLOAT_METHOD_NAME_AND_TYPE = 18;
150         final static int VALUEOF_LONG_METHOD_NAME_AND_TYPE = 19;
151         final static int VALUEOF_OBJECT_METHOD_NAME_AND_TYPE = 20;
152         final static int VALUEOF_CHAR_METHOD_NAME_AND_TYPE = 21;
153         final static int VALUEOF_BOOLEAN_METHOD_NAME_AND_TYPE = 22;
154         final static int VALUEOF_DOUBLE_METHOD_NAME_AND_TYPE = 23;
155         final static int CONSTR_INT_METHOD_NAME_AND_TYPE = 24;
156         final static int CONSTR_LONG_METHOD_NAME_AND_TYPE = 25;
157         final static int CONSTR_FLOAT_METHOD_NAME_AND_TYPE = 26;
158         final static int CONSTR_DOUBLE_METHOD_NAME_AND_TYPE = 27;
159         final static int CONSTR_OBJECT_METHOD_NAME_AND_TYPE = 28;
160         final static int CONSTR_CHAR_METHOD_NAME_AND_TYPE = 29;
161         final static int CONSTR_BOOLEAN_METHOD_NAME_AND_TYPE = 30;
162         final static int DESIREDASSERTIONSTATUS_METHOD_NAME_AND_TYPE = 31;
163         final static int GETCLASS_OBJECT_METHOD_NAME_AND_TYPE = 32;
164
165         
166         public ClassFile classFile;
167
168 /**
169  * ConstantPool constructor comment.
170  */
171 public ConstantPool(ClassFile classFile) {
172         this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE);
173         this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE);
174         this.fieldCache = new ObjectCache(FIELD_INITIAL_SIZE);
175         this.methodCache = new ObjectCache(METHOD_INITIAL_SIZE);
176         this.interfaceMethodCache = new ObjectCache(INTERFACE_INITIAL_SIZE);
177         this.classCache = new ObjectCache(CLASS_INITIAL_SIZE);
178         this.nameAndTypeCacheForMethods = new MethodNameAndTypeCache(NAMEANDTYPE_INITIAL_SIZE);
179         this.nameAndTypeCacheForFields = new FieldNameAndTypeCache(NAMEANDTYPE_INITIAL_SIZE);   
180         this.poolContent = classFile.header;
181         this.currentOffset = classFile.headerOffset;
182         // currentOffset is initialized to 0 by default
183         this.currentIndex = 1;
184         this.classFile = classFile;
185 }
186 /**
187  * Return the content of the receiver
188  */
189 public byte[] dumpBytes() {
190         System.arraycopy(poolContent, 0, (poolContent = new byte[currentOffset]), 0, currentOffset);
191         return poolContent;
192 }
193 /**
194  * Return the index of the @fieldBinding.
195  *
196  * Returns -1 if the @fieldBinding is not a predefined fieldBinding, 
197  * the right index otherwise.
198  *
199  * @param fieldBinding org.eclipse.jdt.internal.compiler.lookup.FieldBinding
200  * @return <CODE>int</CODE>
201  */
202 public int indexOfWellKnownFieldNameAndType(FieldBinding fieldBinding) {
203         if ((fieldBinding.type.id == T_JavaLangClass) && (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE)))
204                 return TYPE_JAVALANGCLASS_NAME_AND_TYPE;
205         if ((fieldBinding.type.id == T_JavaIoPrintStream) && (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.Out)))
206                 return OUT_SYSTEM_NAME_AND_TYPE;
207         return -1;
208 }
209 /**
210  * Return the index of the @fieldBinding.
211  *
212  * Returns -1 if the @fieldBinding is not a predefined fieldBinding, 
213  * the right index otherwise.
214  *
215  * @param fieldBinding org.eclipse.jdt.internal.compiler.lookup.FieldBinding
216  * @return <CODE>int</CODE>
217  */
218 public int indexOfWellKnownFields(FieldBinding fieldBinding) {
219         switch (fieldBinding.declaringClass.id) {
220                 case T_JavaLangByte :
221                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
222                                 return TYPE_BYTE_FIELD;
223                         break;
224                 case T_JavaLangShort :
225                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
226                                 return TYPE_SHORT_FIELD;
227                         break;
228                 case T_JavaLangCharacter :
229                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
230                                 return TYPE_CHARACTER_FIELD;
231                         break;
232                 case T_JavaLangInteger :
233                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
234                                 return TYPE_INTEGER_FIELD;
235                         break;
236                 case T_JavaLangLong :
237                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
238                                 return TYPE_LONG_FIELD;
239                         break;
240                 case T_JavaLangFloat :
241                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
242                                 return TYPE_FLOAT_FIELD;
243                         break;
244                 case T_JavaLangDouble :
245                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
246                                 return TYPE_DOUBLE_FIELD;
247                         break;
248                 case T_JavaLangBoolean :
249                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
250                                 return TYPE_BOOLEAN_FIELD;
251                         break;
252                 case T_JavaLangVoid :
253                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.TYPE))
254                                 return TYPE_VOID_FIELD;
255                         break;
256                 case T_JavaLangSystem :
257                         if (CharOperation.equals(fieldBinding.name, QualifiedNamesConstants.Out))
258                                 return OUT_SYSTEM_FIELD;
259         }
260         return -1;
261 }
262 /**
263  * Return the index of the @methodBinding.
264  *
265  * Returns -1 if the @methodBinding is not a predefined methodBinding, 
266  * the right index otherwise.
267  *
268  * @param methodBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
269  * @return <CODE>int</CODE>
270  */
271 public int indexOfWellKnownMethodNameAndType(MethodBinding methodBinding) {
272         char firstChar = methodBinding.selector[0];
273         switch (firstChar) {
274                 case 'f' :
275                         if ((methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_JavaLangString) && (methodBinding.returnType.id == T_JavaLangClass) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ForName))) {
276                                 // This method binding is forName(java.lang.String)
277                                 return FORNAME_CLASS_METHOD_NAME_AND_TYPE;
278                         }
279                         break;
280                 case '<' :
281                         if (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Init)) {
282                                 switch(methodBinding.parameters.length) {
283                                         case 1:
284                                                 switch(methodBinding.parameters[0].id) {
285                                                         case T_String :
286                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.StringConstructorSignature)) {
287                                                                         return CONSTR_STRING_METHOD_NAME_AND_TYPE;      
288                                                                 } else {
289                                                                         return -1;
290                                                                 }
291                                                         case T_Object :
292                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorObjectConstrSignature)) {
293                                                                         return CONSTR_OBJECT_METHOD_NAME_AND_TYPE;
294                                                                 } else {
295                                                                         return -1;
296                                                                 }
297                                                         case T_int :
298                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorIntConstrSignature)) {
299                                                                         return CONSTR_INT_METHOD_NAME_AND_TYPE;
300                                                                 } else {
301                                                                         return -1;
302                                                                 }
303                                                         case T_char :
304                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorCharConstrSignature)) {
305                                                                         return CONSTR_CHAR_METHOD_NAME_AND_TYPE;
306                                                                 } else {
307                                                                         return -1;
308                                                                 }
309                                                         case T_boolean :
310                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorBooleanConstrSignature)) {
311                                                                         return CONSTR_BOOLEAN_METHOD_NAME_AND_TYPE;
312                                                                 } else {
313                                                                         return -1;
314                                                                 }
315                                                         case T_float :
316                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorFloatConstrSignature)) {
317                                                                         return CONSTR_FLOAT_METHOD_NAME_AND_TYPE;
318                                                                 } else {
319                                                                         return -1;
320                                                                 }
321                                                         case T_double :
322                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorDoubleConstrSignature)) {
323                                                                         return CONSTR_DOUBLE_METHOD_NAME_AND_TYPE;
324                                                                 } else {
325                                                                         return -1;
326                                                                 }
327                                                         case T_long :
328                                                                 if (CharOperation.equals(methodBinding.signature(), QualifiedNamesConstants.AssertionErrorLongConstrSignature)) {
329                                                                         return CONSTR_LONG_METHOD_NAME_AND_TYPE;
330                                                                 } else {
331                                                                         return -1;
332                                                                 }
333                                                 }
334                                         case 0:
335                                                 if (methodBinding.signature().length == 3) {
336                                                         return DEFAULT_CONSTR_METHOD_NAME_AND_TYPE;
337                                                 }
338                                 }
339                         }
340                         break;
341                 case 'a' :
342                         if ((methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangStringBuffer) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Append))) {
343                                 switch (methodBinding.parameters[0].id) {
344                                         case T_int :
345                                         case T_byte :
346                                         case T_short :
347                                                 // This method binding is append(int)
348                                                 return APPEND_INT_METHOD_NAME_AND_TYPE;
349                                         case T_float :
350                                                 // This method binding is append(float)
351                                                 return APPEND_FLOAT_METHOD_NAME_AND_TYPE;
352                                         case T_long :
353                                                 // This method binding is append(long)
354                                                 return APPEND_LONG_METHOD_NAME_AND_TYPE;
355                                         case T_JavaLangObject :
356                                                 // This method binding is append(java.lang.Object)
357                                                 return APPEND_OBJECT_METHOD_NAME_AND_TYPE;
358                                         case T_char :
359                                                 // This method binding is append(char)
360                                                 return APPEND_CHAR_METHOD_NAME_AND_TYPE;
361                                         case T_JavaLangString :
362                                                 // This method binding is append(java.lang.String)
363                                                 return APPEND_STRING_METHOD_NAME_AND_TYPE;
364                                         case T_boolean :
365                                                 // This method binding is append(boolean)
366                                                 return APPEND_BOOLEAN_METHOD_NAME_AND_TYPE;
367                                         case T_double :
368                                                 // This method binding is append(double)
369                                                 return APPEND_DOUBLE_METHOD_NAME_AND_TYPE;
370                                 }
371                         }
372                         break;
373                 case 't' :
374                         if ((methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ToString))) {
375                                 // This method binding is toString()
376                                 return TOSTRING_METHOD_NAME_AND_TYPE;
377                         }
378                         break;
379                 case 'v' :
380                         if ((methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ValueOf))) {
381                                 switch(methodBinding.parameters[0].id) {
382                                         case T_Object:
383                                                 return VALUEOF_OBJECT_METHOD_NAME_AND_TYPE;
384                                         case T_int:
385                                         case T_short:
386                                         case T_byte:
387                                                 return VALUEOF_INT_METHOD_NAME_AND_TYPE;
388                                         case T_long:
389                                                 return VALUEOF_LONG_METHOD_NAME_AND_TYPE;
390                                         case T_float:
391                                                 return VALUEOF_FLOAT_METHOD_NAME_AND_TYPE;
392                                         case T_double:
393                                                 return VALUEOF_DOUBLE_METHOD_NAME_AND_TYPE;
394                                         case T_boolean:
395                                                 return VALUEOF_BOOLEAN_METHOD_NAME_AND_TYPE;
396                                         case T_char:
397                                                 return VALUEOF_CHAR_METHOD_NAME_AND_TYPE;
398                                 }
399                         }
400                         break;
401                 case 'e' :
402                         if ((methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_int) && (methodBinding.returnType.id == T_void) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Exit))) {
403                                 // This method binding is exit(int)
404                                 return EXIT_METHOD_NAME_AND_TYPE;
405                         }
406                         break;
407                 case 'g' :
408                         if ((methodBinding.selector.length == 10)
409                             && (methodBinding.parameters.length == 0)
410                             && (methodBinding.returnType.id == T_JavaLangString)
411                             && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.GetMessage))) {
412                                 // This method binding is getMessage()
413                                 return GETMESSAGE_METHOD_NAME_AND_TYPE;
414                         }
415                         if (methodBinding.parameters.length == 0
416                                 && methodBinding.returnType.id == T_JavaLangClass
417                                 && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.GetClass)) {
418                                         return GETCLASS_OBJECT_METHOD_NAME_AND_TYPE;
419                         }                               
420                         break;
421                 case 'i' :
422                         if ((methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Intern))) {
423                                 // This method binding is toString()
424                                 return INTERN_METHOD_NAME_AND_TYPE;
425                         }       
426         }
427         return -1;
428 }
429 /**
430  * Return the index of the @methodBinding.
431  *
432  * Returns -1 if the @methodBinding is not a predefined methodBinding, 
433  * the right index otherwise.
434  *
435  * @param methodBinding org.eclipse.jdt.internal.compiler.lookup.MethodBinding
436  * @return <CODE>int</CODE>
437  */
438 public int indexOfWellKnownMethods(MethodBinding methodBinding) {
439         char firstChar = methodBinding.selector[0];
440         switch (methodBinding.declaringClass.id) {
441                 case T_JavaLangClass :
442                         if ((firstChar == 'f') && (methodBinding.isStatic()) && (methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_JavaLangString) && (methodBinding.returnType.id == T_JavaLangClass) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ForName))) {
443                                 // This method binding is forName(java.lang.String)
444                                 return FORNAME_CLASS_METHOD;
445                         } else if ((firstChar == 'g') && (methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangReflectConstructor) && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.GetConstructor) && CharOperation.equals(methodBinding.parameters[0].constantPoolName(), QualifiedNamesConstants.ArrayJavaLangClassConstantPoolName)) {
446                                         return GETCONSTRUCTOR_CLASS_METHOD;
447                         } else if ((firstChar == 'd') && (methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_boolean) && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.DesiredAssertionStatus)) {
448                                         return DESIREDASSERTIONSTATUS_CLASS_METHOD;
449                         }
450                         break;
451                 case T_JavaLangNoClassDefError :
452                         if ((firstChar == '<') && (methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Init))) {
453                                 // This method binding is NoClassDefFoundError(java.lang.String)
454                                 return NOCLASSDEFFOUNDERROR_CONSTR_METHOD;
455                         }
456                         break;
457                 case T_JavaLangReflectConstructor :
458                         if ((firstChar == 'n') && (methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangObject) && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.NewInstance) && CharOperation.equals(methodBinding.parameters[0].constantPoolName(), QualifiedNamesConstants.ArrayJavaLangObjectConstantPoolName)) {
459                                 return NEWINSTANCE_CONSTRUCTOR_METHOD;
460                         }
461                         break;
462                 case T_JavaLangStringBuffer :
463                         if ((firstChar == 'a') && (methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangStringBuffer) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Append))) {
464                                 switch (methodBinding.parameters[0].id) {
465                                         case T_int :
466                                         case T_byte :
467                                         case T_short :
468                                                 // This method binding is append(int)
469                                                 return APPEND_INT_METHOD;
470                                         case T_float :
471                                                 // This method binding is append(float)
472                                                 return APPEND_FLOAT_METHOD;
473                                         case T_long :
474                                                 // This method binding is append(long)
475                                                 return APPEND_LONG_METHOD;
476                                         case T_JavaLangObject :
477                                                 // This method binding is append(java.lang.Object)
478                                                 return APPEND_OBJECT_METHOD;
479                                         case T_char :
480                                                 // This method binding is append(char)
481                                                 return APPEND_CHAR_METHOD;
482                                         case T_JavaLangString :
483                                                 // This method binding is append(java.lang.String)
484                                                 return APPEND_STRING_METHOD;
485                                         case T_boolean :
486                                                 // This method binding is append(boolean)
487                                                 return APPEND_BOOLEAN_METHOD;
488                                         case T_double :
489                                                 // This method binding is append(double)
490                                                 return APPEND_DOUBLE_METHOD;
491                                 }
492                         } else
493                                 if ((firstChar == 't') && (methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ToString))) {
494                                         // This method binding is toString()
495                                         return STRINGBUFFER_TOSTRING_METHOD;
496                                 } else
497                                         if ((firstChar == '<') && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Init))) {
498                                                 if ((methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_JavaLangString)) {
499                                                         // This method binding is <init>(String)                    
500                                                         return STRINGBUFFER_STRING_CONSTR_METHOD;
501                                                 } else {
502                                                         if (methodBinding.parameters.length == 0) {
503                                                                 // This method binding is <init>()
504                                                                 return STRINGBUFFER_DEFAULT_CONSTR_METHOD;
505                                                         }
506                                                 }
507                                         }
508                         break;
509                 case T_JavaLangString :
510                         if ((firstChar == 'v') && (methodBinding.parameters.length == 1) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.ValueOf))) {
511                                 // This method binding is valueOf(java.lang.Object)
512                                 switch (methodBinding.parameters[0].id) {
513                                         case T_Object :
514                                                 return VALUEOF_OBJECT_METHOD;
515                                         case T_int :
516                                         case T_short :
517                                         case T_byte :
518                                                 return VALUEOF_INT_METHOD;
519                                         case T_long :
520                                                 return VALUEOF_LONG_METHOD;
521                                         case T_float :
522                                                 return VALUEOF_FLOAT_METHOD;
523                                         case T_double :
524                                                 return VALUEOF_DOUBLE_METHOD;
525                                         case T_boolean :
526                                                 return VALUEOF_BOOLEAN_METHOD;
527                                         case T_char :
528                                                 return VALUEOF_CHAR_METHOD;
529                                 }
530                         } else
531                                 if ((firstChar == 'i') && (methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Intern))) {
532                                         // This method binding is valueOf(java.lang.Object)
533                                         return STRING_INTERN_METHOD;
534                                 }
535                         break;
536                 case T_JavaLangSystem :
537                         if ((firstChar == 'e') && (methodBinding.parameters.length == 1) && (methodBinding.parameters[0].id == T_int) && (methodBinding.returnType.id == T_void) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Exit))) {
538                                 // This method binding is exit(int)
539                                 return SYSTEM_EXIT_METHOD;
540                         }
541                         break;
542                 case T_JavaLangThrowable :
543                         if ((firstChar == 'g') && (methodBinding.selector.length == 10) && (methodBinding.parameters.length == 0) && (methodBinding.returnType.id == T_JavaLangString) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.GetMessage))) {
544                                 // This method binding is getMessage()
545                                 return THROWABLE_GETMESSAGE_METHOD;
546                         }
547                         break;
548                 case T_JavaLangError :
549                         if ((firstChar == '<') && (methodBinding.parameters.length == 1) && (CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Init)) && (methodBinding.parameters[0].id == T_String)) {
550                                 return JAVALANGERROR_CONSTR_METHOD;
551                         }
552                         break;
553                 case T_JavaLangAssertionError :
554                         if ((firstChar == '<') && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.Init)) {
555                                 switch (methodBinding.parameters.length) {
556                                         case 0:
557                                                 return ASSERTIONERROR_DEFAULT_CONSTR_METHOD;
558                                         case 1:
559                                                 switch(methodBinding.parameters[0].id) {
560                                                         case T_boolean :
561                                                                 return ASSERTIONERROR_CONSTR_BOOLEAN_METHOD;
562                                                         case T_char :
563                                                                 return ASSERTIONERROR_CONSTR_CHAR_METHOD;
564                                                         case T_double :
565                                                                 return ASSERTIONERROR_CONSTR_DOUBLE_METHOD;
566                                                         case T_int :
567                                                         case T_byte :
568                                                         case T_short :
569                                                                 return ASSERTIONERROR_CONSTR_INT_METHOD;
570                                                         case T_float :
571                                                                 return ASSERTIONERROR_CONSTR_FLOAT_METHOD;
572                                                         case T_long :
573                                                                 return ASSERTIONERROR_CONSTR_LONG_METHOD;
574                                                         default:
575                                                                 return ASSERTIONERROR_CONSTR_OBJECT_METHOD;
576                                                 }
577                                 }
578                         }
579                         break;
580                 case T_JavaLangObject :
581                         if (methodBinding.parameters.length == 0
582                                 && CharOperation.equals(methodBinding.selector, QualifiedNamesConstants.GetClass)) {
583                                         return GETCLASS_OBJECT_METHOD;
584                         }                       
585         }
586         return -1;
587 }
588 /**
589  * Return the index of the @typeBinding
590  *
591  * Returns -1 if the @typeBinding is not a predefined binding, the right index 
592  * otherwise.
593  *
594  * @param typeBinding org.eclipse.jdt.internal.compiler.lookup.TypeBinding
595  * @return <CODE>int</CODE>
596  */
597 public int indexOfWellKnownTypes(TypeBinding typeBinding) {
598         switch(typeBinding.id) {
599                 case T_JavaLangBoolean : return JAVA_LANG_BOOLEAN_TYPE;
600                 case T_JavaLangByte : return JAVA_LANG_BYTE_TYPE;
601                 case T_JavaLangCharacter : return JAVA_LANG_CHARACTER_TYPE;
602                 case T_JavaLangDouble : return JAVA_LANG_DOUBLE_TYPE;
603                 case T_JavaLangFloat : return JAVA_LANG_FLOAT_TYPE;
604                 case T_JavaLangInteger : return JAVA_LANG_INTEGER_TYPE;
605                 case T_JavaLangLong : return JAVA_LANG_LONG_TYPE;
606                 case T_JavaLangShort : return JAVA_LANG_SHORT_TYPE;
607                 case T_JavaLangVoid : return JAVA_LANG_VOID_TYPE;
608                 case T_JavaLangClass : return JAVA_LANG_CLASS_TYPE;
609                 case T_JavaLangClassNotFoundException : return JAVA_LANG_CLASSNOTFOUNDEXCEPTION_TYPE;
610                 case T_JavaLangNoClassDefError : return JAVA_LANG_NOCLASSDEFFOUNDERROR_TYPE;
611                 case T_JavaLangObject : return JAVA_LANG_OBJECT_TYPE;
612                 case T_JavaLangString : return JAVA_LANG_STRING_TYPE;
613                 case T_JavaLangStringBuffer : return JAVA_LANG_STRINGBUFFER_TYPE;
614                 case T_JavaLangSystem : return JAVA_LANG_SYSTEM_TYPE;
615                 case T_JavaLangThrowable : return JAVA_LANG_THROWABLE_TYPE;
616                 case T_JavaLangError : return JAVA_LANG_ERROR_TYPE;
617                 case T_JavaLangException : return JAVA_LANG_EXCEPTION_TYPE;
618                 case T_JavaLangReflectConstructor : return JAVA_LANG_REFLECT_CONSTRUCTOR_TYPE;
619                 case T_JavaLangAssertionError : return JAVA_LANG_ASSERTIONERROR_TYPE;
620         }
621         return -1;
622 }
623 public int literalIndex(byte[] utf8encoding, char[] stringCharArray) {
624         int index;
625         if ((index = UTF8Cache.get(stringCharArray)) < 0) {
626                 // The entry doesn't exit yet
627                 index = UTF8Cache.put(stringCharArray, currentIndex);
628                 if (index > 0xFFFF){
629                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
630                 }
631                 currentIndex++;
632                 // Write the tag first
633                 writeU1(Utf8Tag);
634                 // Then the size of the stringName array
635                 //writeU2(utf8Constant.length);
636                 int savedCurrentOffset = currentOffset;
637                 if (currentOffset + 2 >= poolContent.length) {
638                         // we need to resize the poolContent array because we won't have
639                         // enough space to write the length
640                         int length = poolContent.length;
641                         System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
642                 }
643                 currentOffset += 2;
644                 // add in once the whole byte array
645                 int length = poolContent.length;
646                 int utf8encodingLength = utf8encoding.length;
647                 if (currentOffset + utf8encodingLength >= length) {
648                         System.arraycopy(poolContent, 0, (poolContent = new byte[length + utf8encodingLength + CONSTANTPOOL_GROW_SIZE]), 0, length);
649                 }
650                 System.arraycopy(utf8encoding, 0, poolContent, currentOffset, utf8encodingLength);
651                 currentOffset += utf8encodingLength;
652                 // Now we know the length that we have to write in the constant pool
653                 // we use savedCurrentOffset to do that
654                 poolContent[savedCurrentOffset] = (byte) (utf8encodingLength >> 8);
655                 poolContent[savedCurrentOffset + 1] = (byte) utf8encodingLength;
656         }
657         return index;
658 }
659 /**
660  * This method returns the index into the constantPool corresponding to the type descriptor.
661  *
662  * @param char[] stringName
663  * @return <CODE>int</CODE>
664  */
665 public int literalIndex(char[] utf8Constant) {
666         int index;
667         if ((index = UTF8Cache.get(utf8Constant)) < 0) {
668                 // The entry doesn't exit yet
669                 // Write the tag first
670                 writeU1(Utf8Tag);
671                 // Then the size of the stringName array
672                 int savedCurrentOffset = currentOffset;
673                 if (currentOffset + 2 >= poolContent.length) {
674                         // we need to resize the poolContent array because we won't have
675                         // enough space to write the length
676                         int length = poolContent.length;
677                         System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
678                 }
679                 currentOffset += 2;
680                 int length = 0;
681                 for (int i = 0; i < utf8Constant.length; i++) {
682                         char current = utf8Constant[i];
683                         if ((current >= 0x0001) && (current <= 0x007F)) {
684                                 // we only need one byte: ASCII table
685                                 writeU1(current);
686                                 length++;
687                         } else
688                                 if (current > 0x07FF) {
689                                         // we need 3 bytes
690                                         length += 3;
691                                         writeU1(0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
692                                         writeU1(0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
693                                         writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
694                                 } else {
695                                         // we can be 0 or between 0x0080 and 0x07FF
696                                         // In that case we only need 2 bytes
697                                         length += 2;
698                                         writeU1(0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
699                                         writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
700                                 }
701                 }
702                 if (length >= 65535) {
703                         currentOffset = savedCurrentOffset - 1;
704                         return -1;
705                 }
706                 index = UTF8Cache.put(utf8Constant, currentIndex);
707                 if (index > 0xFFFF){
708                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
709                 }
710                 currentIndex++;     
711                 // Now we know the length that we have to write in the constant pool
712                 // we use savedCurrentOffset to do that
713                 poolContent[savedCurrentOffset] = (byte) (length >> 8);
714                 poolContent[savedCurrentOffset + 1] = (byte) length;
715         }
716         return index;
717 }
718 public int literalIndex(char[] stringCharArray, byte[] utf8encoding) {
719         int index;
720         int stringIndex;
721         if ((index = stringCache.get(stringCharArray)) < 0) {
722                 // The entry doesn't exit yet
723                 stringIndex = literalIndex(utf8encoding, stringCharArray);
724                 index = stringCache.put(stringCharArray, currentIndex++);
725                 if (index > 0xFFFF){
726                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
727                 }
728                 // Write the tag first
729                 writeU1(StringTag);
730                 // Then the string index
731                 writeU2(stringIndex);
732         }
733         return index;
734 }
735 /**
736  * This method returns the index into the constantPool corresponding to the double
737  * value. If the double is not already present into the pool, it is added. The 
738  * double cache is updated and it returns the right index.
739  *
740  * @param <CODE>double</CODE> key
741  * @return <CODE>int</CODE>
742  */
743 public int literalIndex(double key) {
744         //Retrieve the index from the cache
745         // The double constant takes two indexes into the constant pool, but we only store
746         // the first index into the long table
747         int index;
748         // lazy initialization for base type caches
749         // If it is null, initialize it, otherwise use it
750         if (doubleCache == null) {
751                         doubleCache = new DoubleCache(DOUBLE_INITIAL_SIZE);
752         }
753         if ((index = doubleCache.get(key)) < 0) {
754                 index = doubleCache.put(key, currentIndex++);
755                 if (index > 0xFFFF){
756                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
757                 }
758                 currentIndex++; // a double needs an extra place into the constant pool
759                 // Write the double into the constant pool
760                 // First add the tag
761                 writeU1(DoubleTag);
762                 // Then add the 8 bytes representing the double
763                 long temp = java.lang.Double.doubleToLongBits(key);
764                 for (int i = 0; i < 8; i++) {
765                         try {
766                                 poolContent[currentOffset++] = (byte) (temp >>> (56 - (i << 3)));
767                         } catch (IndexOutOfBoundsException e) { //currentOffset has been ++ already (see the -1)
768                                 int length = poolContent.length;
769                                 System.arraycopy(poolContent, 0, (poolContent = new byte[(length << 1) + CONSTANTPOOL_INITIAL_SIZE]), 0, length);
770                                 poolContent[currentOffset - 1] = (byte) (temp >>> (56 - (i << 3)));
771                         }
772                 }
773         };
774         return index;
775 }
776 /**
777  * This method returns the index into the constantPool corresponding to the float
778  * value. If the float is not already present into the pool, it is added. The 
779  * int cache is updated and it returns the right index.
780  *
781  * @param <CODE>float</CODE> key
782  * @return <CODE>int</CODE>
783  */
784 public int literalIndex(float key) {
785         //Retrieve the index from the cache
786         int index;
787         // lazy initialization for base type caches
788         // If it is null, initialize it, otherwise use it
789         if (floatCache == null) {
790                 floatCache = new FloatCache(FLOAT_INITIAL_SIZE);
791         }
792         if ((index = floatCache.get(key)) < 0) {
793                 index = floatCache.put(key, currentIndex++);
794                 if (index > 0xFFFF){
795                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
796                 }
797                 // Write the float constant entry into the constant pool
798                 // First add the tag
799                 writeU1(FloatTag);
800                 // Then add the 4 bytes representing the float
801                 int temp = java.lang.Float.floatToIntBits(key);
802                 for (int i = 0; i < 4; i++) {
803                         try {
804                                 poolContent[currentOffset++] = (byte) (temp >>> (24 - i * 8));
805                         } catch (IndexOutOfBoundsException e) { //currentOffset has been ++ already (see the -1)
806                                 int length = poolContent.length;
807                                 System.arraycopy(poolContent, 0, (poolContent = new byte[length * 2 + CONSTANTPOOL_INITIAL_SIZE]), 0, length);
808                                 poolContent[currentOffset - 1] = (byte) (temp >>> (24 - i * 8));
809                         }
810                 }
811         };
812         return index;
813 }
814 /**
815  * This method returns the index into the constantPool corresponding to the int
816  * value. If the int is not already present into the pool, it is added. The 
817  * int cache is updated and it returns the right index.
818  *
819  * @param <CODE>int</CODE> key
820  * @return <CODE>int</CODE>
821  */
822 public int literalIndex(int key) {
823         //Retrieve the index from the cache
824         int index;
825         // lazy initialization for base type caches
826         // If it is null, initialize it, otherwise use it
827         if (intCache == null) {
828                 intCache = new IntegerCache(INT_INITIAL_SIZE);
829         }
830         if ((index = intCache.get(key)) < 0) {
831                 index = intCache.put(key, currentIndex++);
832                 if (index > 0xFFFF){
833                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
834                 }
835                 // Write the integer constant entry into the constant pool
836                 // First add the tag
837                 writeU1(IntegerTag);
838                 // Then add the 4 bytes representing the int
839                 for (int i = 0; i < 4; i++) {
840                         try {
841                                 poolContent[currentOffset++] = (byte) (key >>> (24 - i * 8));
842                         } catch (IndexOutOfBoundsException e) { //currentOffset has been ++ already (see the -1)
843                                 int length = poolContent.length;
844                                 System.arraycopy(poolContent, 0, (poolContent = new byte[length * 2 + CONSTANTPOOL_INITIAL_SIZE]), 0, length);
845                                 poolContent[currentOffset - 1] = (byte) (key >>> (24 - i * 8));
846                         }
847                 }
848         };
849         return index;
850 }
851 /**
852  * This method returns the index into the constantPool corresponding to the long
853  * value. If the long is not already present into the pool, it is added. The 
854  * long cache is updated and it returns the right index.
855  *
856  * @param <CODE>long</CODE> key
857  * @return <CODE>int</CODE>
858  */
859 public int literalIndex(long key) {
860         // Retrieve the index from the cache
861         // The long constant takes two indexes into the constant pool, but we only store
862         // the first index into the long table
863         int index;
864         // lazy initialization for base type caches
865         // If it is null, initialize it, otherwise use it
866         if (longCache == null) {
867                 longCache = new LongCache(LONG_INITIAL_SIZE);
868         }
869         if ((index = longCache.get(key)) < 0) {
870                 index = longCache.put(key, currentIndex++);
871                 if (index > 0xFFFF){
872                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
873                 }
874                 currentIndex++; // long value need an extra place into thwe constant pool
875                 // Write the long into the constant pool
876                 // First add the tag
877                 writeU1(LongTag);
878                 // Then add the 8 bytes representing the long
879                 for (int i = 0; i < 8; i++) {
880                         try {
881                                 poolContent[currentOffset++] = (byte) (key >>> (56 - (i << 3)));
882                         } catch (IndexOutOfBoundsException e) { //currentOffset has been ++ already (see the -1)
883                                 int length = poolContent.length;
884                                 System.arraycopy(poolContent, 0, (poolContent = new byte[(length << 1) + CONSTANTPOOL_INITIAL_SIZE]), 0, length);
885                                 poolContent[currentOffset - 1] = (byte) (key >>> (56 - (i << 3)));
886                         }
887                 }
888         }
889         return index;
890 }
891 /**
892  * This method returns the index into the constantPool corresponding to the type descriptor.
893  *
894  * @param stringConstant java.lang.String
895  * @return <CODE>int</CODE>
896  */
897 public int literalIndex(String stringConstant) {
898         int index;
899         char[] stringCharArray = stringConstant.toCharArray();
900         if ((index = stringCache.get(stringCharArray)) < 0) {
901                 // The entry doesn't exit yet
902                 int stringIndex = literalIndex(stringCharArray);
903                 index = stringCache.put(stringCharArray, currentIndex++);
904                 if (index > 0xFFFF){
905                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
906                 }
907                 // Write the tag first
908                 writeU1(StringTag);
909                 // Then the string index
910                 writeU2(stringIndex);
911         }
912         return index;
913 }
914 /**
915  * This method returns the index into the constantPool 
916  * corresponding to the field binding aFieldBinding.
917  *
918  * @param FieldBinding aFieldBinding
919  * @return <CODE>int</CODE>
920  */
921 public int literalIndex(FieldBinding aFieldBinding) {
922         int index;
923         int nameAndTypeIndex;
924         int classIndex;
925         int indexWellKnownField;
926         if ((indexWellKnownField = indexOfWellKnownFields(aFieldBinding)) == -1) {
927                 if ((index = fieldCache.get(aFieldBinding)) < 0) {
928                         // The entry doesn't exit yet
929                         classIndex = literalIndex(aFieldBinding.declaringClass);
930                         nameAndTypeIndex = literalIndexForFields(literalIndex(aFieldBinding.name), literalIndex(aFieldBinding.type.signature()), aFieldBinding);
931                         index = fieldCache.put(aFieldBinding, currentIndex++);
932                         if (index > 0xFFFF){
933                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
934                         }
935                         writeU1(FieldRefTag);
936                         writeU2(classIndex);
937                         writeU2(nameAndTypeIndex);
938                 }
939         } else {
940                 if ((index = wellKnownFields[indexWellKnownField]) == 0) {
941                         // that field need to be inserted
942                         classIndex = literalIndex(aFieldBinding.declaringClass);
943                         nameAndTypeIndex = literalIndexForFields(literalIndex(aFieldBinding.name), literalIndex(aFieldBinding.type.signature()), aFieldBinding);
944                         index = wellKnownFields[indexWellKnownField] = currentIndex++;
945                         if (index > 0xFFFF){
946                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
947                         }
948                         writeU1(FieldRefTag);
949                         writeU2(classIndex);
950                         writeU2(nameAndTypeIndex);
951                 }
952         }
953         return index;
954 }
955 /**
956  * This method returns the index into the constantPool corresponding to the 
957  * method descriptor. It can be either an interface method reference constant
958  * or a method reference constant.
959  *
960  * @param MethodBinding aMethodBinding
961  * @return <CODE>int</CODE>
962  */
963 public int literalIndex(MethodBinding aMethodBinding) {
964         int index;
965         int nameAndTypeIndex;
966         int classIndex;
967         int indexWellKnownMethod;
968         if ((indexWellKnownMethod = indexOfWellKnownMethods(aMethodBinding)) == -1) {
969                 if (aMethodBinding.declaringClass.isInterface()) {
970                         // Lookinf into the interface method ref table
971                         if ((index = interfaceMethodCache.get(aMethodBinding)) < 0) {
972                                 classIndex = literalIndex(aMethodBinding.declaringClass);
973                                 nameAndTypeIndex = literalIndexForMethods(literalIndex(aMethodBinding.constantPoolName()), literalIndex(aMethodBinding.signature()), aMethodBinding);
974                                 index = interfaceMethodCache.put(aMethodBinding, currentIndex++);
975                                 if (index > 0xFFFF){
976                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
977                                 }
978                                 // Write the interface method ref constant into the constant pool
979                                 // First add the tag
980                                 writeU1(InterfaceMethodRefTag);
981                                 // Then write the class index
982                                 writeU2(classIndex);
983                                 // The write the nameAndType index
984                                 writeU2(nameAndTypeIndex);
985                         }
986                 } else {
987                         // Lookinf into the method ref table
988                         if ((index = methodCache.get(aMethodBinding)) < 0) {
989                                 classIndex = literalIndex(aMethodBinding.declaringClass);
990                                 nameAndTypeIndex = literalIndexForMethods(literalIndex(aMethodBinding.constantPoolName()), literalIndex(aMethodBinding.signature()), aMethodBinding);
991                                 index = methodCache.put(aMethodBinding, currentIndex++);
992                                 if (index > 0xFFFF){
993                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
994                                 }
995                                 // Write the method ref constant into the constant pool
996                                 // First add the tag
997                                 writeU1(MethodRefTag);
998                                 // Then write the class index
999                                 writeU2(classIndex);
1000                                 // The write the nameAndType index
1001                                 writeU2(nameAndTypeIndex);
1002                         }
1003                 }
1004         } else {
1005                 // This is a well known method
1006                 if ((index = wellKnownMethods[indexWellKnownMethod]) == 0) {
1007                         // this methods was not inserted yet
1008                         if (aMethodBinding.declaringClass.isInterface()) {
1009                                 // Lookinf into the interface method ref table
1010                                 classIndex = literalIndex(aMethodBinding.declaringClass);
1011                                 nameAndTypeIndex = literalIndexForMethods(literalIndex(aMethodBinding.constantPoolName()), literalIndex(aMethodBinding.signature()), aMethodBinding);
1012                                 index = wellKnownMethods[indexWellKnownMethod] = currentIndex++;
1013                                 if (index > 0xFFFF){
1014                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1015                                 }
1016                                 // Write the interface method ref constant into the constant pool
1017                                 // First add the tag
1018                                 writeU1(InterfaceMethodRefTag);
1019                                 // Then write the class index
1020                                 writeU2(classIndex);
1021                                 // The write the nameAndType index
1022                                 writeU2(nameAndTypeIndex);
1023                         } else {
1024                                 // Lookinf into the method ref table
1025                                 classIndex = literalIndex(aMethodBinding.declaringClass);
1026                                 nameAndTypeIndex = literalIndexForMethods(literalIndex(aMethodBinding.constantPoolName()), literalIndex(aMethodBinding.signature()), aMethodBinding);
1027                                 index = wellKnownMethods[indexWellKnownMethod] = currentIndex++;
1028                                 if (index > 0xFFFF){
1029                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1030                                 }
1031                                 // Write the method ref constant into the constant pool
1032                                 // First add the tag
1033                                 writeU1(MethodRefTag);
1034                                 // Then write the class index
1035                                 writeU2(classIndex);
1036                                 // The write the nameAndType index
1037                                 writeU2(nameAndTypeIndex);
1038                         }
1039                 }
1040         }
1041         return index;
1042 }
1043 /**
1044  * This method returns the index into the constantPool corresponding to the type descriptor.
1045  *
1046  * @param TypeBinding aTypeBinding
1047  * @return <CODE>int</CODE>
1048  */
1049 public int literalIndex(TypeBinding aTypeBinding) {
1050         int index;
1051         int nameIndex;
1052         int indexWellKnownType;
1053         if ((indexWellKnownType = indexOfWellKnownTypes(aTypeBinding)) == -1) {
1054                 if ((index = classCache.get(aTypeBinding)) < 0) {
1055                         // The entry doesn't exit yet
1056                         nameIndex = literalIndex(aTypeBinding.constantPoolName());
1057                         index = classCache.put(aTypeBinding, currentIndex++);
1058                         if (index > 0xFFFF){
1059                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1060                         }
1061                         writeU1(ClassTag);
1062                         // Then add the 8 bytes representing the long
1063                         writeU2(nameIndex);
1064                 }
1065         } else {
1066                 if ((index = wellKnownTypes[indexWellKnownType]) == 0) {
1067                         // Need to insert that binding
1068                         nameIndex = literalIndex(aTypeBinding.constantPoolName());
1069                         index = wellKnownTypes[indexWellKnownType] = currentIndex++;
1070                         if (index > 0xFFFF){
1071                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1072                         }
1073                         writeU1(ClassTag);
1074                         // Then add the 8 bytes representing the long
1075                         writeU2(nameIndex);
1076                 }
1077         }
1078         return index;
1079 }
1080 /**
1081  * This method returns the index into the constantPool corresponding 
1082  * nameAndType constant with nameIndex, typeIndex.
1083  *
1084  * @param int nameIndex
1085  * @param int nameIndex
1086  * @param org.eclipse.jdt.internal.compiler.lookup.FieldBinding a FieldBinding
1087  * @return <CODE>int</CODE>
1088  */
1089 public int literalIndexForFields(int nameIndex, int typeIndex, FieldBinding key) {
1090         int index;
1091         int indexOfWellKnownFieldNameAndType;
1092         if ((indexOfWellKnownFieldNameAndType = indexOfWellKnownFieldNameAndType(key)) == -1) {
1093                 // check if the entry already exists
1094                 if ((index = nameAndTypeCacheForFields.get(key)) == -1) {
1095                         // The entry doesn't exit yet
1096                         index = nameAndTypeCacheForFields.put(key, currentIndex++);
1097                         if (index > 0xFFFF){
1098                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1099                         }
1100                         writeU1(NameAndTypeTag);
1101                         writeU2(nameIndex);
1102                         writeU2(typeIndex);
1103                 }
1104         } else {
1105                 if ((index = wellKnownFieldNameAndTypes[indexOfWellKnownFieldNameAndType]) == 0) {
1106                         index = wellKnownFieldNameAndTypes[indexOfWellKnownFieldNameAndType] = currentIndex++;
1107                         if (index > 0xFFFF){
1108                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1109                         }
1110                         writeU1(NameAndTypeTag);
1111                         writeU2(nameIndex);
1112                         writeU2(typeIndex);
1113                 }
1114         }
1115         return index;
1116 }
1117 /**
1118  * This method returns the index into the constantPool corresponding to the type descriptor.
1119  *
1120  * @param TypeBinding aTypeBinding
1121  * @return <CODE>int</CODE>
1122  */
1123 public int literalIndexForJavaLangBoolean() {
1124         int index;
1125         if ((index = wellKnownTypes[JAVA_LANG_BOOLEAN_TYPE]) == 0) {
1126                 int nameIndex;
1127                 // The entry doesn't exit yet
1128                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangBooleanConstantPoolName);
1129                 index = wellKnownTypes[JAVA_LANG_BOOLEAN_TYPE] = currentIndex++;
1130                 if (index > 0xFFFF){
1131                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1132                 }
1133                 writeU1(ClassTag);
1134                 // Then add the 8 bytes representing the long
1135                 writeU2(nameIndex);
1136         }
1137         return index;
1138 }
1139 /**
1140  * This method returns the index into the constantPool 
1141  * corresponding to the field binding aFieldBinding.
1142  *
1143  * @return <CODE>int</CODE>
1144  */
1145 public int literalIndexForJavaLangBooleanTYPE() {
1146         int index;
1147         if ((index = wellKnownFields[TYPE_BOOLEAN_FIELD]) == 0) {
1148                 int nameAndTypeIndex;
1149                 int classIndex;
1150                 // The entry doesn't exit yet
1151                 classIndex = literalIndexForJavaLangBoolean();
1152                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1153                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1154                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1155                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1156                         writeU1(NameAndTypeTag);
1157                         writeU2(nameIndex);
1158                         writeU2(typeIndex);
1159                 }
1160                 index = wellKnownFields[TYPE_BOOLEAN_FIELD] = currentIndex++;
1161                 if (index > 0xFFFF){
1162                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1163                 }
1164                 writeU1(FieldRefTag);
1165                 writeU2(classIndex);
1166                 writeU2(nameAndTypeIndex);
1167         }
1168         return index;
1169 }
1170 /**
1171  * This method returns the index into the constantPool corresponding to the type descriptor.
1172  *
1173  * @param TypeBinding aTypeBinding
1174  * @return <CODE>int</CODE>
1175  */
1176 public int literalIndexForJavaLangByte() {
1177         int index;
1178         if ((index = wellKnownTypes[JAVA_LANG_BYTE_TYPE]) == 0) {
1179                 int nameIndex;
1180                 // The entry doesn't exit yet
1181                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangByteConstantPoolName);
1182                 index = wellKnownTypes[JAVA_LANG_BYTE_TYPE] = currentIndex++;
1183                 if (index > 0xFFFF){
1184                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1185                 }
1186                 writeU1(ClassTag);
1187                 // Then add the 8 bytes representing the long
1188                 writeU2(nameIndex);
1189         }
1190         return index;
1191 }
1192 /**
1193  * This method returns the index into the constantPool 
1194  * corresponding to the field binding aFieldBinding.
1195  *
1196  * @return <CODE>int</CODE>
1197  */
1198 public int literalIndexForJavaLangByteTYPE() {
1199         int index;
1200         if ((index = wellKnownFields[TYPE_BYTE_FIELD]) == 0) {
1201                 int nameAndTypeIndex;
1202                 int classIndex;
1203                 // The entry doesn't exit yet
1204                 classIndex = literalIndexForJavaLangByte();
1205                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1206                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1207                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1208                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1209                         writeU1(NameAndTypeTag);
1210                         writeU2(nameIndex);
1211                         writeU2(typeIndex);
1212                 }
1213                 index = wellKnownFields[TYPE_BYTE_FIELD] = currentIndex++;
1214                 if (index > 0xFFFF){
1215                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1216                 }
1217                 writeU1(FieldRefTag);
1218                 writeU2(classIndex);
1219                 writeU2(nameAndTypeIndex);
1220         }
1221         return index;
1222 }
1223 /**
1224  * This method returns the index into the constantPool corresponding to the type descriptor.
1225  *
1226  * @param TypeBinding aTypeBinding
1227  * @return <CODE>int</CODE>
1228  */
1229 public int literalIndexForJavaLangCharacter() {
1230         int index;
1231         if ((index = wellKnownTypes[JAVA_LANG_CHARACTER_TYPE]) == 0) {
1232                 int nameIndex;
1233                 // The entry doesn't exit yet
1234                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangCharacterConstantPoolName);
1235                 index = wellKnownTypes[JAVA_LANG_CHARACTER_TYPE] = currentIndex++;
1236                 if (index > 0xFFFF){
1237                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1238                 }
1239                 writeU1(ClassTag);
1240                 // Then add the 8 bytes representing the long
1241                 writeU2(nameIndex);
1242         }
1243         return index;
1244 }
1245 /**
1246  * This method returns the index into the constantPool 
1247  * corresponding to the field binding aFieldBinding.
1248  *
1249  * @return <CODE>int</CODE>
1250  */
1251 public int literalIndexForJavaLangCharacterTYPE() {
1252         int index;
1253         if ((index = wellKnownFields[TYPE_CHARACTER_FIELD]) == 0) {
1254                 int nameAndTypeIndex;
1255                 int classIndex;
1256                 // The entry doesn't exit yet
1257                 classIndex = literalIndexForJavaLangCharacter();
1258                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1259                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1260                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1261                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1262                         writeU1(NameAndTypeTag);
1263                         writeU2(nameIndex);
1264                         writeU2(typeIndex);
1265                 }
1266                 index = wellKnownFields[TYPE_CHARACTER_FIELD] = currentIndex++;
1267                 if (index > 0xFFFF){
1268                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1269                 }
1270                 writeU1(FieldRefTag);
1271                 writeU2(classIndex);
1272                 writeU2(nameAndTypeIndex);
1273         }
1274         return index;
1275 }
1276 /**
1277  * This method returns the index into the constantPool corresponding to the type descriptor.
1278  *
1279  * @param TypeBinding aTypeBinding
1280  * @return <CODE>int</CODE>
1281  */
1282 public int literalIndexForJavaLangClass() {
1283         int index;
1284         if ((index = wellKnownTypes[JAVA_LANG_CLASS_TYPE]) == 0) {
1285                 int nameIndex;
1286                 // The entry doesn't exit yet
1287                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangClassConstantPoolName);
1288                 index = wellKnownTypes[JAVA_LANG_CLASS_TYPE] = currentIndex++;
1289                 if (index > 0xFFFF){
1290                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1291                 }
1292                 writeU1(ClassTag);
1293                 // Then add the 8 bytes representing the long
1294                 writeU2(nameIndex);
1295         }
1296         return index;
1297 }
1298 /**
1299  * This method returns the index into the constantPool corresponding to the 
1300  * method descriptor. It can be either an interface method reference constant
1301  * or a method reference constant.
1302  *
1303  * @return <CODE>int</CODE>
1304  */
1305 public int literalIndexForJavaLangClassForName() {
1306         int index;
1307         int nameAndTypeIndex;
1308         int classIndex;
1309         // Looking into the method ref table
1310         if ((index = wellKnownMethods[FORNAME_CLASS_METHOD]) == 0) {
1311                 classIndex = literalIndexForJavaLangClass();
1312                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[FORNAME_CLASS_METHOD_NAME_AND_TYPE]) == 0) {
1313                         int nameIndex = literalIndex(QualifiedNamesConstants.ForName);
1314                         int typeIndex = literalIndex(QualifiedNamesConstants.ForNameSignature);
1315                         nameAndTypeIndex = wellKnownMethodNameAndTypes[FORNAME_CLASS_METHOD_NAME_AND_TYPE] = currentIndex++;
1316                         writeU1(NameAndTypeTag);
1317                         writeU2(nameIndex);
1318                         writeU2(typeIndex);
1319                 }
1320                 index = wellKnownMethods[FORNAME_CLASS_METHOD] = currentIndex++;
1321                 if (index > 0xFFFF){
1322                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1323                 }
1324                 // Write the method ref constant into the constant pool
1325                 // First add the tag
1326                 writeU1(MethodRefTag);
1327                 // Then write the class index
1328                 writeU2(classIndex);
1329                 // The write the nameAndType index
1330                 writeU2(nameAndTypeIndex);
1331         }
1332         return index;
1333 }
1334 /**
1335  * This method returns the index into the constantPool corresponding to the 
1336  * method descriptor. It can be either an interface method reference constant
1337  * or a method reference constant.
1338  *
1339  * @return <CODE>int</CODE>
1340  */
1341 public int literalIndexForJavaLangClassGetConstructor() {
1342         int index;
1343         int nameAndTypeIndex;
1344         int classIndex;
1345         // Looking into the method ref table
1346         if ((index = wellKnownMethods[GETCONSTRUCTOR_CLASS_METHOD]) == 0) {
1347                 classIndex = literalIndexForJavaLangClass();
1348                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[GETCONSTRUCTOR_METHOD_NAME_AND_TYPE]) == 0) {
1349                         int nameIndex = literalIndex(QualifiedNamesConstants.GetConstructor);
1350                         int typeIndex = literalIndex(QualifiedNamesConstants.GetConstructorSignature);
1351                         nameAndTypeIndex = wellKnownMethodNameAndTypes[GETCONSTRUCTOR_METHOD_NAME_AND_TYPE] = currentIndex++;
1352                         writeU1(NameAndTypeTag);
1353                         writeU2(nameIndex);
1354                         writeU2(typeIndex);
1355                 }
1356                 index = wellKnownMethods[GETCONSTRUCTOR_CLASS_METHOD] = currentIndex++;
1357                 if (index > 0xFFFF){
1358                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1359                 }
1360                 // Write the method ref constant into the constant pool
1361                 // First add the tag
1362                 writeU1(MethodRefTag);
1363                 // Then write the class index
1364                 writeU2(classIndex);
1365                 // The write the nameAndType index
1366                 writeU2(nameAndTypeIndex);
1367         }
1368         return index;
1369 }
1370 /**
1371  * This method returns the index into the constantPool corresponding to the 
1372  * method descriptor. It can be either an interface method reference constant
1373  * or a method reference constant.
1374  *
1375  * @return <CODE>int</CODE>
1376  */
1377 public int literalIndexForJavaLangClassDesiredAssertionStatus() {
1378         int index;
1379         int nameAndTypeIndex;
1380         int classIndex;
1381         // Looking into the method ref table
1382         if ((index = wellKnownMethods[DESIREDASSERTIONSTATUS_CLASS_METHOD]) == 0) {
1383                 classIndex = literalIndexForJavaLangClass();
1384                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[DESIREDASSERTIONSTATUS_METHOD_NAME_AND_TYPE]) == 0) {
1385                         int nameIndex = literalIndex(QualifiedNamesConstants.DesiredAssertionStatus);
1386                         int typeIndex = literalIndex(QualifiedNamesConstants.DesiredAssertionStatusSignature);
1387                         nameAndTypeIndex = wellKnownMethodNameAndTypes[DESIREDASSERTIONSTATUS_METHOD_NAME_AND_TYPE] = currentIndex++;
1388                         writeU1(NameAndTypeTag);
1389                         writeU2(nameIndex);
1390                         writeU2(typeIndex);
1391                 }
1392                 index = wellKnownMethods[DESIREDASSERTIONSTATUS_CLASS_METHOD] = currentIndex++;
1393                 if (index > 0xFFFF){
1394                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1395                 }
1396                 // Write the method ref constant into the constant pool
1397                 // First add the tag
1398                 writeU1(MethodRefTag);
1399                 // Then write the class index
1400                 writeU2(classIndex);
1401                 // The write the nameAndType index
1402                 writeU2(nameAndTypeIndex);
1403         }
1404         return index;
1405 }
1406 /**
1407  * This method returns the index into the constantPool corresponding to the type descriptor.
1408  *
1409  * @param TypeBinding aTypeBinding
1410  * @return <CODE>int</CODE>
1411  */
1412 public int literalIndexForJavaLangClassNotFoundException() {
1413         int index;
1414         if ((index = wellKnownTypes[JAVA_LANG_CLASSNOTFOUNDEXCEPTION_TYPE]) == 0) {
1415                 int nameIndex;
1416                 // The entry doesn't exit yet
1417                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangClassNotFoundExceptionConstantPoolName);
1418                 index = wellKnownTypes[JAVA_LANG_CLASSNOTFOUNDEXCEPTION_TYPE] = currentIndex++;
1419                 if (index > 0xFFFF){
1420                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1421                 }
1422                 writeU1(ClassTag);
1423                 // Then add the 8 bytes representing the long
1424                 writeU2(nameIndex);
1425         }
1426         return index;
1427 }
1428 /**
1429  * This method returns the index into the constantPool corresponding to the type descriptor.
1430  *
1431  * @param TypeBinding aTypeBinding
1432  * @return <CODE>int</CODE>
1433  */
1434 public int literalIndexForJavaLangDouble() {
1435         int index;
1436         if ((index = wellKnownTypes[JAVA_LANG_DOUBLE_TYPE]) == 0) {
1437                 int nameIndex;
1438                 // The entry doesn't exit yet
1439                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangDoubleConstantPoolName);
1440                 index = wellKnownTypes[JAVA_LANG_DOUBLE_TYPE] = currentIndex++;
1441                 if (index > 0xFFFF){
1442                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1443                 }
1444                 writeU1(ClassTag);
1445                 // Then add the 8 bytes representing the long
1446                 writeU2(nameIndex);
1447         }
1448         return index;
1449 }
1450 /**
1451  * This method returns the index into the constantPool 
1452  * corresponding to the field binding aFieldBinding.
1453  *
1454  * @return <CODE>int</CODE>
1455  */
1456 public int literalIndexForJavaLangDoubleTYPE() {
1457         int index;
1458         if ((index = wellKnownFields[TYPE_DOUBLE_FIELD]) == 0) {
1459                 int nameAndTypeIndex;
1460                 int classIndex;
1461                 // The entry doesn't exit yet
1462                 classIndex = literalIndexForJavaLangDouble();
1463                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1464                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1465                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1466                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1467                         writeU1(NameAndTypeTag);
1468                         writeU2(nameIndex);
1469                         writeU2(typeIndex);
1470                 }
1471                 index = wellKnownFields[TYPE_DOUBLE_FIELD] = currentIndex++;
1472                 if (index > 0xFFFF){
1473                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1474                 }
1475                 writeU1(FieldRefTag);
1476                 writeU2(classIndex);
1477                 writeU2(nameAndTypeIndex);
1478         }
1479         return index;
1480 }
1481 /**
1482  * This method returns the index into the constantPool corresponding to the type descriptor.
1483  *
1484  * @param TypeBinding aTypeBinding
1485  * @return <CODE>int</CODE>
1486  */
1487 public int literalIndexForJavaLangError() {
1488         int index;
1489         if ((index = wellKnownTypes[JAVA_LANG_ERROR_TYPE]) == 0) {
1490                 int nameIndex;
1491                 // The entry doesn't exit yet
1492                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangErrorConstantPoolName);
1493                 index = wellKnownTypes[JAVA_LANG_ERROR_TYPE] = currentIndex++;
1494                 if (index > 0xFFFF){
1495                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1496                 }
1497                 writeU1(ClassTag);
1498                 // Then add the 8 bytes representing the long
1499                 writeU2(nameIndex);
1500         }
1501         return index;
1502 }
1503 /**
1504  * This method returns the index into the constantPool corresponding to the 
1505  * method descriptor. It can be either an interface method reference constant
1506  * or a method reference constant.
1507  *
1508  * @return <CODE>int</CODE>
1509  */
1510 public int literalIndexForJavaLangErrorConstructor() {
1511         int index;
1512         int nameAndTypeIndex;
1513         int classIndex;
1514         // Looking into the method ref table
1515         if ((index = wellKnownMethods[JAVALANGERROR_CONSTR_METHOD]) == 0) {
1516                 classIndex = literalIndexForJavaLangError();
1517                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE]) == 0) {
1518                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1519                         int typeIndex = literalIndex(QualifiedNamesConstants.StringConstructorSignature);
1520                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE] = currentIndex++;
1521                         writeU1(NameAndTypeTag);
1522                         writeU2(nameIndex);
1523                         writeU2(typeIndex);
1524                 }
1525                 index = wellKnownMethods[JAVALANGERROR_CONSTR_METHOD] = currentIndex++;
1526                 if (index > 0xFFFF){
1527                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1528                 }
1529                 // Write the method ref constant into the constant pool
1530                 // First add the tag
1531                 writeU1(MethodRefTag);
1532                 // Then write the class index
1533                 writeU2(classIndex);
1534                 // The write the nameAndType index
1535                 writeU2(nameAndTypeIndex);
1536         }
1537         return index;
1538 }
1539 public int literalIndexForJavaLangException() {
1540         int index;
1541         if ((index = wellKnownTypes[JAVA_LANG_EXCEPTION_TYPE]) == 0) {
1542                 // The entry doesn't exit yet
1543                 int nameIndex = literalIndex(QualifiedNamesConstants.JavaLangExceptionConstantPoolName);
1544                 index = wellKnownTypes[JAVA_LANG_EXCEPTION_TYPE] = currentIndex++;
1545                 if (index > 0xFFFF){
1546                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1547                 }
1548                 writeU1(ClassTag);
1549                 // Then add the 8 bytes representing the long
1550                 writeU2(nameIndex);
1551         }
1552         return index;
1553 }
1554 /**
1555  * This method returns the index into the constantPool corresponding to the type descriptor.
1556  *
1557  * @param TypeBinding aTypeBinding
1558  * @return <CODE>int</CODE>
1559  */
1560 public int literalIndexForJavaLangFloat() {
1561         int index;
1562         if ((index = wellKnownTypes[JAVA_LANG_FLOAT_TYPE]) == 0) {
1563                 int nameIndex;
1564                 // The entry doesn't exit yet
1565                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangFloatConstantPoolName);
1566                 index = wellKnownTypes[JAVA_LANG_FLOAT_TYPE] = currentIndex++;
1567                 if (index > 0xFFFF){
1568                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1569                 }
1570                 writeU1(ClassTag);
1571                 // Then add the 8 bytes representing the long
1572                 writeU2(nameIndex);
1573         }
1574         return index;
1575 }
1576 /**
1577  * This method returns the index into the constantPool 
1578  * corresponding to the field binding aFieldBinding.
1579  *
1580  * @return <CODE>int</CODE>
1581  */
1582 public int literalIndexForJavaLangFloatTYPE() {
1583         int index;
1584         if ((index = wellKnownFields[TYPE_FLOAT_FIELD]) == 0) {
1585                 int nameAndTypeIndex;
1586                 int classIndex;
1587                 // The entry doesn't exit yet
1588                 classIndex = literalIndexForJavaLangFloat();
1589                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1590                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1591                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1592                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1593                         writeU1(NameAndTypeTag);
1594                         writeU2(nameIndex);
1595                         writeU2(typeIndex);
1596                 }
1597                 index = wellKnownFields[TYPE_FLOAT_FIELD] = currentIndex++;
1598                 if (index > 0xFFFF){
1599                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1600                 }
1601                 writeU1(FieldRefTag);
1602                 writeU2(classIndex);
1603                 writeU2(nameAndTypeIndex);
1604         }
1605         return index;
1606 }
1607 /**
1608  * This method returns the index into the constantPool corresponding to the type descriptor.
1609  *
1610  * @param TypeBinding aTypeBinding
1611  * @return <CODE>int</CODE>
1612  */
1613 public int literalIndexForJavaLangInteger() {
1614         int index;
1615         if ((index = wellKnownTypes[JAVA_LANG_INTEGER_TYPE]) == 0) {
1616                 int nameIndex;
1617                 // The entry doesn't exit yet
1618                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangIntegerConstantPoolName);
1619                 index = wellKnownTypes[JAVA_LANG_INTEGER_TYPE] = currentIndex++;
1620                 if (index > 0xFFFF){
1621                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1622                 }
1623                 writeU1(ClassTag);
1624                 // Then add the 8 bytes representing the long
1625                 writeU2(nameIndex);
1626         }
1627         return index;
1628 }
1629 /**
1630  * This method returns the index into the constantPool 
1631  * corresponding to the field binding aFieldBinding.
1632  *
1633  * @return <CODE>int</CODE>
1634  */
1635 public int literalIndexForJavaLangIntegerTYPE() {
1636         int index;
1637         if ((index = wellKnownFields[TYPE_INTEGER_FIELD]) == 0) {
1638                 int nameAndTypeIndex;
1639                 int classIndex;
1640                 // The entry doesn't exit yet
1641                 classIndex = literalIndexForJavaLangInteger();
1642                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1643                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1644                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1645                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1646                         writeU1(NameAndTypeTag);
1647                         writeU2(nameIndex);
1648                         writeU2(typeIndex);
1649                 }
1650                 index = wellKnownFields[TYPE_INTEGER_FIELD] = currentIndex++;
1651                 if (index > 0xFFFF){
1652                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1653                 }
1654                 writeU1(FieldRefTag);
1655                 writeU2(classIndex);
1656                 writeU2(nameAndTypeIndex);
1657         }
1658         return index;
1659 }
1660 /**
1661  * This method returns the index into the constantPool corresponding to the type descriptor.
1662  *
1663  * @param TypeBinding aTypeBinding
1664  * @return <CODE>int</CODE>
1665  */
1666 public int literalIndexForJavaLangLong() {
1667         int index;
1668         if ((index = wellKnownTypes[JAVA_LANG_LONG_TYPE]) == 0) {
1669                 int nameIndex;
1670                 // The entry doesn't exit yet
1671                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangLongConstantPoolName);
1672                 index = wellKnownTypes[JAVA_LANG_LONG_TYPE] = currentIndex++;
1673                 if (index > 0xFFFF){
1674                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1675                 }
1676                 writeU1(ClassTag);
1677                 // Then add the 8 bytes representing the long
1678                 writeU2(nameIndex);
1679         }
1680         return index;
1681 }
1682 /**
1683  * This method returns the index into the constantPool 
1684  * corresponding to the field binding aFieldBinding.
1685  *
1686  * @return <CODE>int</CODE>
1687  */
1688 public int literalIndexForJavaLangLongTYPE() {
1689         int index;
1690         if ((index = wellKnownFields[TYPE_LONG_FIELD]) == 0) {
1691                 int nameAndTypeIndex;
1692                 int classIndex;
1693                 // The entry doesn't exit yet
1694                 classIndex = literalIndexForJavaLangLong();
1695                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
1696                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
1697                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
1698                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
1699                         writeU1(NameAndTypeTag);
1700                         writeU2(nameIndex);
1701                         writeU2(typeIndex);
1702                 }
1703                 index = wellKnownFields[TYPE_LONG_FIELD] = currentIndex++;
1704                 if (index > 0xFFFF){
1705                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1706                 }
1707                 writeU1(FieldRefTag);
1708                 writeU2(classIndex);
1709                 writeU2(nameAndTypeIndex);
1710         }
1711         return index;
1712 }
1713 /**
1714  * This method returns the index into the constantPool corresponding to the type descriptor.
1715  *
1716  * @param TypeBinding aTypeBinding
1717  * @return <CODE>int</CODE>
1718  */
1719 public int literalIndexForJavaLangNoClassDefFoundError() {
1720         int index;
1721         if ((index = wellKnownTypes[JAVA_LANG_NOCLASSDEFFOUNDERROR_TYPE]) == 0) {
1722                 int nameIndex;
1723                 // The entry doesn't exit yet
1724                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangNoClassDefFoundErrorConstantPoolName);
1725                 index = wellKnownTypes[JAVA_LANG_NOCLASSDEFFOUNDERROR_TYPE] = currentIndex++;
1726                 if (index > 0xFFFF){
1727                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1728                 }
1729                 writeU1(ClassTag);
1730                 // Then add the 8 bytes representing the long
1731                 writeU2(nameIndex);
1732         }
1733         return index;
1734 }
1735
1736 /**
1737  * This method returns the index into the constantPool corresponding to the type descriptor.
1738  *
1739  * @param TypeBinding aTypeBinding
1740  * @return <CODE>int</CODE>
1741  */
1742 public int literalIndexForJavaLangAssertionError() {
1743         int index;
1744         if ((index = wellKnownTypes[JAVA_LANG_ASSERTIONERROR_TYPE]) == 0) {
1745                 int nameIndex;
1746                 // The entry doesn't exit yet
1747                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangAssertionErrorConstantPoolName);
1748                 index = wellKnownTypes[JAVA_LANG_ASSERTIONERROR_TYPE] = currentIndex++;
1749                 if (index > 0xFFFF){
1750                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1751                 }
1752                 writeU1(ClassTag);
1753                 // Then add the 8 bytes representing the long
1754                 writeU2(nameIndex);
1755         }
1756         return index;
1757 }
1758
1759 /**
1760  * This method returns the index into the constantPool corresponding to the type descriptor.
1761  *
1762  * @param TypeBinding aTypeBinding
1763  * @return <CODE>int</CODE>
1764  */
1765 public int literalIndexForJavaLangAssertionErrorConstructor(int typeBindingID) {
1766         int index = 0;
1767         int nameAndTypeIndex = 0;
1768         int classIndex = 0;
1769         switch (typeBindingID) {
1770                 case T_int :
1771                 case T_byte :
1772                 case T_short :
1773                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_INT_METHOD]) == 0) {
1774                                 classIndex = literalIndexForJavaLangAssertionError();
1775                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_INT_METHOD_NAME_AND_TYPE]) == 0) {
1776                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1777                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorIntConstrSignature);
1778                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_INT_METHOD_NAME_AND_TYPE] = currentIndex++;
1779                                         writeU1(NameAndTypeTag);
1780                                         writeU2(nameIndex);
1781                                         writeU2(typeIndex);
1782                                 }
1783                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_INT_METHOD] = currentIndex++;
1784                                 if (index > 0xFFFF){
1785                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1786                                 }
1787                                 // Write the method ref constant into the constant pool
1788                                 // First add the tag
1789                                 writeU1(MethodRefTag);
1790                                 // Then write the class index
1791                                 writeU2(classIndex);
1792                                 // The write the nameAndType index
1793                                 writeU2(nameAndTypeIndex);
1794                         }
1795                         break;
1796                 case T_long :
1797                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_LONG_METHOD]) == 0) {
1798                                 classIndex = literalIndexForJavaLangAssertionError();
1799                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_LONG_METHOD_NAME_AND_TYPE]) == 0) {
1800                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1801                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorLongConstrSignature);
1802                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_LONG_METHOD_NAME_AND_TYPE] = currentIndex++;
1803                                         writeU1(NameAndTypeTag);
1804                                         writeU2(nameIndex);
1805                                         writeU2(typeIndex);
1806                                 }
1807                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_LONG_METHOD] = currentIndex++;
1808                                 if (index > 0xFFFF){
1809                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1810                                 }
1811                                 // Write the method ref constant into the constant pool
1812                                 // First add the tag
1813                                 writeU1(MethodRefTag);
1814                                 // Then write the class index
1815                                 writeU2(classIndex);
1816                                 // The write the nameAndType index
1817                                 writeU2(nameAndTypeIndex);
1818                         }
1819                         break;
1820                 case T_float :
1821                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_FLOAT_METHOD]) == 0) {
1822                                 classIndex = literalIndexForJavaLangAssertionError();
1823                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_FLOAT_METHOD_NAME_AND_TYPE]) == 0) {
1824                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1825                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorFloatConstrSignature);
1826                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_FLOAT_METHOD_NAME_AND_TYPE] = currentIndex++;
1827                                         writeU1(NameAndTypeTag);
1828                                         writeU2(nameIndex);
1829                                         writeU2(typeIndex);
1830                                 }
1831                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_FLOAT_METHOD] = currentIndex++;
1832                                 if (index > 0xFFFF){
1833                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1834                                 }
1835                                 // Write the method ref constant into the constant pool
1836                                 // First add the tag
1837                                 writeU1(MethodRefTag);
1838                                 // Then write the class index
1839                                 writeU2(classIndex);
1840                                 // The write the nameAndType index
1841                                 writeU2(nameAndTypeIndex);
1842                         }
1843                         break;
1844                 case T_double :
1845                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_DOUBLE_METHOD]) == 0) {
1846                                 classIndex = literalIndexForJavaLangAssertionError();
1847                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_DOUBLE_METHOD_NAME_AND_TYPE]) == 0) {
1848                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1849                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorDoubleConstrSignature);
1850                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_DOUBLE_METHOD_NAME_AND_TYPE] = currentIndex++;
1851                                         writeU1(NameAndTypeTag);
1852                                         writeU2(nameIndex);
1853                                         writeU2(typeIndex);
1854                                 }
1855                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_DOUBLE_METHOD] = currentIndex++;
1856                                 if (index > 0xFFFF){
1857                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1858                                 }
1859                                 // Write the method ref constant into the constant pool
1860                                 // First add the tag
1861                                 writeU1(MethodRefTag);
1862                                 // Then write the class index
1863                                 writeU2(classIndex);
1864                                 // The write the nameAndType index
1865                                 writeU2(nameAndTypeIndex);
1866                         }
1867                         break;
1868                 case T_char :
1869                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_CHAR_METHOD]) == 0) {
1870                                 classIndex = literalIndexForJavaLangAssertionError();
1871                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_CHAR_METHOD_NAME_AND_TYPE]) == 0) {
1872                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1873                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorCharConstrSignature);
1874                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_CHAR_METHOD_NAME_AND_TYPE] = currentIndex++;
1875                                         writeU1(NameAndTypeTag);
1876                                         writeU2(nameIndex);
1877                                         writeU2(typeIndex);
1878                                 }
1879                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_CHAR_METHOD] = currentIndex++;
1880                                 if (index > 0xFFFF){
1881                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1882                                 }
1883                                 // Write the method ref constant into the constant pool
1884                                 // First add the tag
1885                                 writeU1(MethodRefTag);
1886                                 // Then write the class index
1887                                 writeU2(classIndex);
1888                                 // The write the nameAndType index
1889                                 writeU2(nameAndTypeIndex);
1890                         }
1891                         break;
1892                 case T_boolean :
1893                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_BOOLEAN_METHOD]) == 0) {
1894                                 classIndex = literalIndexForJavaLangAssertionError();
1895                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_BOOLEAN_METHOD_NAME_AND_TYPE]) == 0) {
1896                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1897                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorBooleanConstrSignature);
1898                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_BOOLEAN_METHOD_NAME_AND_TYPE] = currentIndex++;
1899                                         writeU1(NameAndTypeTag);
1900                                         writeU2(nameIndex);
1901                                         writeU2(typeIndex);
1902                                 }
1903                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_BOOLEAN_METHOD] = currentIndex++;
1904                                 if (index > 0xFFFF){
1905                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1906                                 }
1907                                 // Write the method ref constant into the constant pool
1908                                 // First add the tag
1909                                 writeU1(MethodRefTag);
1910                                 // Then write the class index
1911                                 writeU2(classIndex);
1912                                 // The write the nameAndType index
1913                                 writeU2(nameAndTypeIndex);
1914                         }
1915                         break;
1916                 //case T_Object :
1917                 //case T_String :
1918                 //case T_null :
1919                 default : 
1920                         if ((index = wellKnownMethods[ASSERTIONERROR_CONSTR_OBJECT_METHOD]) == 0) {
1921                                 classIndex = literalIndexForJavaLangAssertionError();
1922                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_OBJECT_METHOD_NAME_AND_TYPE]) == 0) {
1923                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1924                                         int typeIndex = literalIndex(QualifiedNamesConstants.AssertionErrorObjectConstrSignature);
1925                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_OBJECT_METHOD_NAME_AND_TYPE] = currentIndex++;
1926                                         writeU1(NameAndTypeTag);
1927                                         writeU2(nameIndex);
1928                                         writeU2(typeIndex);
1929                                 }
1930                                 index = wellKnownMethods[ASSERTIONERROR_CONSTR_OBJECT_METHOD] = currentIndex++;
1931                                 if (index > 0xFFFF){
1932                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1933                                 }
1934                                 // Write the method ref constant into the constant pool
1935                                 // First add the tag
1936                                 writeU1(MethodRefTag);
1937                                 // Then write the class index
1938                                 writeU2(classIndex);
1939                                 // The write the nameAndType index
1940                                 writeU2(nameAndTypeIndex);
1941                         }
1942         }
1943         return index;
1944 }
1945
1946 /**
1947  * This method returns the index into the constantPool corresponding to the 
1948  * method descriptor. It can be either an interface method reference constant
1949  * or a method reference constant.
1950  *
1951  * @return <CODE>int</CODE>
1952  */
1953 public int literalIndexForJavaLangAssertionErrorDefaultConstructor() {
1954         int index;
1955         int nameAndTypeIndex;
1956         int classIndex;
1957         // Looking into the method ref table
1958         if ((index = wellKnownMethods[ASSERTIONERROR_DEFAULT_CONSTR_METHOD]) == 0) {
1959                 classIndex = literalIndexForJavaLangAssertionError();
1960                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[DEFAULT_CONSTR_METHOD_NAME_AND_TYPE]) == 0) {
1961                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
1962                         int typeIndex = literalIndex(QualifiedNamesConstants.DefaultConstructorSignature);
1963                         nameAndTypeIndex = wellKnownMethodNameAndTypes[DEFAULT_CONSTR_METHOD_NAME_AND_TYPE] = currentIndex++;
1964                         writeU1(NameAndTypeTag);
1965                         writeU2(nameIndex);
1966                         writeU2(typeIndex);
1967                 }
1968                 index = wellKnownMethods[ASSERTIONERROR_DEFAULT_CONSTR_METHOD] = currentIndex++;
1969                 if (index > 0xFFFF){
1970                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
1971                 }
1972                 // Write the method ref constant into the constant pool
1973                 // First add the tag
1974                 writeU1(MethodRefTag);
1975                 // Then write the class index
1976                 writeU2(classIndex);
1977                 // The write the nameAndType index
1978                 writeU2(nameAndTypeIndex);
1979         }
1980         return index;
1981 }
1982
1983
1984 /**
1985  * This method returns the index into the constantPool corresponding to the 
1986  * method descriptor. It can be either an interface method reference constant
1987  * or a method reference constant.
1988  *
1989  * @return <CODE>int</CODE>
1990  */
1991 public int literalIndexForJavaLangNoClassDefFoundErrorStringConstructor() {
1992         int index;
1993         int nameAndTypeIndex;
1994         int classIndex;
1995         // Looking into the method ref table
1996         if ((index = wellKnownMethods[NOCLASSDEFFOUNDERROR_CONSTR_METHOD]) == 0) {
1997                 classIndex = literalIndexForJavaLangNoClassDefFoundError();
1998                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE]) == 0) {
1999                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
2000                         int typeIndex = literalIndex(QualifiedNamesConstants.StringConstructorSignature);
2001                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE] = currentIndex++;
2002                         writeU1(NameAndTypeTag);
2003                         writeU2(nameIndex);
2004                         writeU2(typeIndex);
2005                 }
2006                 index = wellKnownMethods[NOCLASSDEFFOUNDERROR_CONSTR_METHOD] = currentIndex++;
2007                 if (index > 0xFFFF){
2008                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2009                 }
2010                 // Write the method ref constant into the constant pool
2011                 // First add the tag
2012                 writeU1(MethodRefTag);
2013                 // Then write the class index
2014                 writeU2(classIndex);
2015                 // The write the nameAndType index
2016                 writeU2(nameAndTypeIndex);
2017         }
2018         return index;
2019 }
2020 /**
2021  * This method returns the index into the constantPool corresponding to the type descriptor.
2022  *
2023  * @param TypeBinding aTypeBinding
2024  * @return <CODE>int</CODE>
2025  */
2026 public int literalIndexForJavaLangObject() {
2027         int index;
2028         if ((index = wellKnownTypes[JAVA_LANG_OBJECT_TYPE]) == 0) {
2029                 int nameIndex;
2030                 // The entry doesn't exit yet
2031                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangObjectConstantPoolName);
2032                 index = wellKnownTypes[JAVA_LANG_OBJECT_TYPE] = currentIndex++;
2033                 if (index > 0xFFFF){
2034                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2035                 }
2036                 writeU1(ClassTag);
2037                 // Then add the 8 bytes representing the long
2038                 writeU2(nameIndex);
2039         }
2040         return index;
2041 }
2042 /**
2043  * This method returns the index into the constantPool corresponding to the type descriptor.
2044  *
2045  * @param TypeBinding aTypeBinding
2046  * @return <CODE>int</CODE>
2047  */
2048 public int literalIndexForJavaLangReflectConstructor() {
2049         int index;
2050         if ((index = wellKnownTypes[JAVA_LANG_REFLECT_CONSTRUCTOR_TYPE]) == 0) {
2051                 int nameIndex;
2052                 // The entry doesn't exit yet
2053                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangReflectConstructor);
2054                 index = wellKnownTypes[JAVA_LANG_REFLECT_CONSTRUCTOR_TYPE] = currentIndex++;
2055                 if (index > 0xFFFF){
2056                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2057                 }
2058                 writeU1(ClassTag);
2059                 // Then add the 8 bytes representing the long
2060                 writeU2(nameIndex);
2061         }
2062         return index;
2063 }
2064 public int literalIndexForJavaLangReflectConstructorNewInstance() {
2065         int index;
2066         int nameAndTypeIndex;
2067         int classIndex;
2068         // Looking into the method ref table
2069         if ((index = wellKnownMethods[NEWINSTANCE_CONSTRUCTOR_METHOD]) == 0) {
2070                 classIndex = literalIndexForJavaLangReflectConstructor();
2071                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[NEWINSTANCE_METHOD_NAME_AND_TYPE]) == 0) {
2072                         int nameIndex = literalIndex(QualifiedNamesConstants.NewInstance);
2073                         int typeIndex = literalIndex(QualifiedNamesConstants.NewInstanceSignature);
2074                         nameAndTypeIndex = wellKnownMethodNameAndTypes[NEWINSTANCE_METHOD_NAME_AND_TYPE] = currentIndex++;
2075                         writeU1(NameAndTypeTag);
2076                         writeU2(nameIndex);
2077                         writeU2(typeIndex);
2078                 }
2079                 index = wellKnownMethods[NEWINSTANCE_CONSTRUCTOR_METHOD] = currentIndex++;
2080                 if (index > 0xFFFF){
2081                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2082                 }
2083                 // Write the method ref constant into the constant pool
2084                 // First add the tag
2085                 writeU1(MethodRefTag);
2086                 // Then write the class index
2087                 writeU2(classIndex);
2088                 // The write the nameAndType index
2089                 writeU2(nameAndTypeIndex);
2090         }
2091         return index;
2092 }
2093 /**
2094  * This method returns the index into the constantPool corresponding to the type descriptor.
2095  *
2096  * @param TypeBinding aTypeBinding
2097  * @return <CODE>int</CODE>
2098  */
2099 public int literalIndexForJavaLangShort() {
2100         int index;
2101         if ((index = wellKnownTypes[JAVA_LANG_SHORT_TYPE]) == 0) {
2102                 int nameIndex;
2103                 // The entry doesn't exit yet
2104                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangShortConstantPoolName);
2105                 index = wellKnownTypes[JAVA_LANG_SHORT_TYPE] = currentIndex++;
2106                 if (index > 0xFFFF){
2107                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2108                 }
2109                 writeU1(ClassTag);
2110                 // Then add the 8 bytes representing the long
2111                 writeU2(nameIndex);
2112         }
2113         return index;
2114 }
2115 /**
2116  * This method returns the index into the constantPool 
2117  * corresponding to the field binding aFieldBinding.
2118  *
2119  * @return <CODE>int</CODE>
2120  */
2121 public int literalIndexForJavaLangShortTYPE() {
2122         int index;
2123         if ((index = wellKnownFields[TYPE_SHORT_FIELD]) == 0) {
2124                 int nameAndTypeIndex;
2125                 int classIndex;
2126                 // The entry doesn't exit yet
2127                 classIndex = literalIndexForJavaLangShort();
2128                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
2129                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
2130                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
2131                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
2132                         writeU1(NameAndTypeTag);
2133                         writeU2(nameIndex);
2134                         writeU2(typeIndex);
2135                 }
2136                 index = wellKnownFields[TYPE_SHORT_FIELD] = currentIndex++;
2137                 if (index > 0xFFFF){
2138                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2139                 }
2140                 writeU1(FieldRefTag);
2141                 writeU2(classIndex);
2142                 writeU2(nameAndTypeIndex);
2143         }
2144         return index;
2145 }
2146 /**
2147  * This method returns the index into the constantPool corresponding to the type descriptor.
2148  *
2149  * @param TypeBinding aTypeBinding
2150  * @return <CODE>int</CODE>
2151  */
2152 public int literalIndexForJavaLangString() {
2153         int index;
2154         if ((index = wellKnownTypes[JAVA_LANG_STRING_TYPE]) == 0) {
2155                 int nameIndex;
2156                 // The entry doesn't exit yet
2157                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangStringConstantPoolName);
2158                 index = wellKnownTypes[JAVA_LANG_STRING_TYPE] = currentIndex++;
2159                 if (index > 0xFFFF){
2160                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2161                 }
2162                 writeU1(ClassTag);
2163                 // Then add the 8 bytes representing the long
2164                 writeU2(nameIndex);
2165         }
2166         return index;
2167 }
2168 /**
2169  * This method returns the index into the constantPool corresponding to the type descriptor.
2170  *
2171  * @param TypeBinding aTypeBinding
2172  * @return <CODE>int</CODE>
2173  */
2174 public int literalIndexForJavaLangStringBuffer() {
2175         int index;
2176         if ((index = wellKnownTypes[JAVA_LANG_STRINGBUFFER_TYPE]) == 0) {
2177                 int nameIndex;
2178                 // The entry doesn't exit yet
2179                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangStringBufferConstantPoolName);
2180                 index = wellKnownTypes[JAVA_LANG_STRINGBUFFER_TYPE] = currentIndex++;
2181                 if (index > 0xFFFF){
2182                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2183                 }
2184                 writeU1(ClassTag);
2185                 // Then add the 8 bytes representing the long
2186                 writeU2(nameIndex);
2187         }
2188         return index;
2189 }
2190 /**
2191  * This method returns the index into the constantPool corresponding to the 
2192  * method descriptor. It can be either an interface method reference constant
2193  * or a method reference constant.
2194  *
2195  * @return <CODE>int</CODE>
2196  */
2197 public int literalIndexForJavaLangStringBufferAppend(int typeID) {
2198         int index = 0;
2199         int nameAndTypeIndex = 0;
2200         int classIndex = 0;
2201         switch (typeID) {
2202                 case T_int :
2203                 case T_byte :
2204                 case T_short :
2205                         if ((index = wellKnownMethods[APPEND_INT_METHOD]) == 0) {
2206                                 classIndex = literalIndexForJavaLangStringBuffer();
2207                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_INT_METHOD_NAME_AND_TYPE]) == 0) {
2208                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2209                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendIntSignature);
2210                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_INT_METHOD_NAME_AND_TYPE] = currentIndex++;
2211                                         writeU1(NameAndTypeTag);
2212                                         writeU2(nameIndex);
2213                                         writeU2(typeIndex);
2214                                 }
2215                                 index = wellKnownMethods[APPEND_INT_METHOD] = currentIndex++;
2216                                 if (index > 0xFFFF){
2217                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2218                                 }
2219                                 // Write the method ref constant into the constant pool
2220                                 // First add the tag
2221                                 writeU1(MethodRefTag);
2222                                 // Then write the class index
2223                                 writeU2(classIndex);
2224                                 // The write the nameAndType index
2225                                 writeU2(nameAndTypeIndex);
2226                         }
2227                         break;
2228                 case T_long :
2229                         if ((index = wellKnownMethods[APPEND_LONG_METHOD]) == 0) {
2230                                 classIndex = literalIndexForJavaLangStringBuffer();
2231                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_LONG_METHOD_NAME_AND_TYPE]) == 0) {
2232                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2233                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendLongSignature);
2234                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_LONG_METHOD_NAME_AND_TYPE] = currentIndex++;
2235                                         writeU1(NameAndTypeTag);
2236                                         writeU2(nameIndex);
2237                                         writeU2(typeIndex);
2238                                 }
2239                                 index = wellKnownMethods[APPEND_LONG_METHOD] = currentIndex++;
2240                                 if (index > 0xFFFF){
2241                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2242                                 }
2243                                 // Write the method ref constant into the constant pool
2244                                 // First add the tag
2245                                 writeU1(MethodRefTag);
2246                                 // Then write the class index
2247                                 writeU2(classIndex);
2248                                 // The write the nameAndType index
2249                                 writeU2(nameAndTypeIndex);
2250                         }
2251                         break;
2252                 case T_float :
2253                         if ((index = wellKnownMethods[APPEND_FLOAT_METHOD]) == 0) {
2254                                 classIndex = literalIndexForJavaLangStringBuffer();
2255                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_FLOAT_METHOD_NAME_AND_TYPE]) == 0) {
2256                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2257                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendFloatSignature);
2258                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_FLOAT_METHOD_NAME_AND_TYPE] = currentIndex++;
2259                                         writeU1(NameAndTypeTag);
2260                                         writeU2(nameIndex);
2261                                         writeU2(typeIndex);
2262                                 }
2263                                 index = wellKnownMethods[APPEND_FLOAT_METHOD] = currentIndex++;
2264                                 if (index > 0xFFFF){
2265                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2266                                 }
2267                                 // Write the method ref constant into the constant pool
2268                                 // First add the tag
2269                                 writeU1(MethodRefTag);
2270                                 // Then write the class index
2271                                 writeU2(classIndex);
2272                                 // The write the nameAndType index
2273                                 writeU2(nameAndTypeIndex);
2274                         }
2275                         break;
2276                 case T_double :
2277                         if ((index = wellKnownMethods[APPEND_DOUBLE_METHOD]) == 0) {
2278                                 classIndex = literalIndexForJavaLangStringBuffer();
2279                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_DOUBLE_METHOD_NAME_AND_TYPE]) == 0) {
2280                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2281                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendDoubleSignature);
2282                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_DOUBLE_METHOD_NAME_AND_TYPE] = currentIndex++;
2283                                         writeU1(NameAndTypeTag);
2284                                         writeU2(nameIndex);
2285                                         writeU2(typeIndex);
2286                                 }
2287                                 index = wellKnownMethods[APPEND_DOUBLE_METHOD] = currentIndex++;
2288                                 if (index > 0xFFFF){
2289                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2290                                 }
2291                                 // Write the method ref constant into the constant pool
2292                                 // First add the tag
2293                                 writeU1(MethodRefTag);
2294                                 // Then write the class index
2295                                 writeU2(classIndex);
2296                                 // The write the nameAndType index
2297                                 writeU2(nameAndTypeIndex);
2298                         }
2299                         break;
2300                 case T_char :
2301                         if ((index = wellKnownMethods[APPEND_CHAR_METHOD]) == 0) {
2302                                 classIndex = literalIndexForJavaLangStringBuffer();
2303                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_CHAR_METHOD_NAME_AND_TYPE]) == 0) {
2304                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2305                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendCharSignature);
2306                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_CHAR_METHOD_NAME_AND_TYPE] = currentIndex++;
2307                                         writeU1(NameAndTypeTag);
2308                                         writeU2(nameIndex);
2309                                         writeU2(typeIndex);
2310                                 }
2311                                 index = wellKnownMethods[APPEND_CHAR_METHOD] = currentIndex++;
2312                                 if (index > 0xFFFF){
2313                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2314                                 }
2315                                 // Write the method ref constant into the constant pool
2316                                 // First add the tag
2317                                 writeU1(MethodRefTag);
2318                                 // Then write the class index
2319                                 writeU2(classIndex);
2320                                 // The write the nameAndType index
2321                                 writeU2(nameAndTypeIndex);
2322                         }
2323                         break;
2324                 case T_boolean :
2325                         if ((index = wellKnownMethods[APPEND_BOOLEAN_METHOD]) == 0) {
2326                                 classIndex = literalIndexForJavaLangStringBuffer();
2327                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_BOOLEAN_METHOD_NAME_AND_TYPE]) == 0) {
2328                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2329                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendBooleanSignature);
2330                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_BOOLEAN_METHOD_NAME_AND_TYPE] = currentIndex++;
2331                                         writeU1(NameAndTypeTag);
2332                                         writeU2(nameIndex);
2333                                         writeU2(typeIndex);
2334                                 }
2335                                 index = wellKnownMethods[APPEND_BOOLEAN_METHOD] = currentIndex++;
2336                                 if (index > 0xFFFF){
2337                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2338                                 }
2339                                 // Write the method ref constant into the constant pool
2340                                 // First add the tag
2341                                 writeU1(MethodRefTag);
2342                                 // Then write the class index
2343                                 writeU2(classIndex);
2344                                 // The write the nameAndType index
2345                                 writeU2(nameAndTypeIndex);
2346                         }
2347                         break;
2348                 case T_Object :
2349                         if ((index = wellKnownMethods[APPEND_OBJECT_METHOD]) == 0) {
2350                                 classIndex = literalIndexForJavaLangStringBuffer();
2351                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_OBJECT_METHOD_NAME_AND_TYPE]) == 0) {
2352                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2353                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendObjectSignature);
2354                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_OBJECT_METHOD_NAME_AND_TYPE] = currentIndex++;
2355                                         writeU1(NameAndTypeTag);
2356                                         writeU2(nameIndex);
2357                                         writeU2(typeIndex);
2358                                 }
2359                                 index = wellKnownMethods[APPEND_OBJECT_METHOD] = currentIndex++;
2360                                 if (index > 0xFFFF){
2361                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2362                                 }
2363                                 // Write the method ref constant into the constant pool
2364                                 // First add the tag
2365                                 writeU1(MethodRefTag);
2366                                 // Then write the class index
2367                                 writeU2(classIndex);
2368                                 // The write the nameAndType index
2369                                 writeU2(nameAndTypeIndex);
2370                         }
2371                         break;
2372                 case T_String :
2373                 case T_null :
2374                         if ((index = wellKnownMethods[APPEND_STRING_METHOD]) == 0) {
2375                                 classIndex = literalIndexForJavaLangStringBuffer();
2376                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_STRING_METHOD_NAME_AND_TYPE]) == 0) {
2377                                         int nameIndex = literalIndex(QualifiedNamesConstants.Append);
2378                                         int typeIndex = literalIndex(QualifiedNamesConstants.AppendStringSignature);
2379                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[APPEND_STRING_METHOD_NAME_AND_TYPE] = currentIndex++;
2380                                         writeU1(NameAndTypeTag);
2381                                         writeU2(nameIndex);
2382                                         writeU2(typeIndex);
2383                                 }
2384                                 index = wellKnownMethods[APPEND_STRING_METHOD] = currentIndex++;
2385                                 if (index > 0xFFFF){
2386                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2387                                 }
2388                                 // Write the method ref constant into the constant pool
2389                                 // First add the tag
2390                                 writeU1(MethodRefTag);
2391                                 // Then write the class index
2392                                 writeU2(classIndex);
2393                                 // The write the nameAndType index
2394                                 writeU2(nameAndTypeIndex);
2395                         }
2396                         break;
2397         }
2398         return index;
2399 }
2400 /**
2401  * This method returns the index into the constantPool corresponding to the 
2402  * method descriptor. It can be either an interface method reference constant
2403  * or a method reference constant.
2404  *
2405  * @return <CODE>int</CODE>
2406  */
2407 public int literalIndexForJavaLangStringBufferConstructor() {
2408         int index;
2409         int nameAndTypeIndex;
2410         int classIndex;
2411         // Looking into the method ref table
2412         if ((index = wellKnownMethods[STRINGBUFFER_STRING_CONSTR_METHOD]) == 0) {
2413                 classIndex = literalIndexForJavaLangStringBuffer();
2414                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE]) == 0) {
2415                                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
2416                                         int typeIndex = literalIndex(QualifiedNamesConstants.StringConstructorSignature);
2417                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[CONSTR_STRING_METHOD_NAME_AND_TYPE] = currentIndex++;
2418                                         writeU1(NameAndTypeTag);
2419                                         writeU2(nameIndex);
2420                                         writeU2(typeIndex);
2421                                 }
2422                 index = wellKnownMethods[STRINGBUFFER_STRING_CONSTR_METHOD] = currentIndex++;
2423                 if (index > 0xFFFF){
2424                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2425                 }
2426                 // Write the method ref constant into the constant pool
2427                 // First add the tag
2428                 writeU1(MethodRefTag);
2429                 // Then write the class index
2430                 writeU2(classIndex);
2431                 // The write the nameAndType index
2432                 writeU2(nameAndTypeIndex);
2433         }
2434         return index;
2435 }
2436 /**
2437  * This method returns the index into the constantPool corresponding to the 
2438  * method descriptor. It can be either an interface method reference constant
2439  * or a method reference constant.
2440  *
2441  * @return <CODE>int</CODE>
2442  */
2443 public int literalIndexForJavaLangStringBufferDefaultConstructor() {
2444         int index;
2445         int nameAndTypeIndex;
2446         int classIndex;
2447         // Looking into the method ref table
2448         if ((index = wellKnownMethods[STRINGBUFFER_DEFAULT_CONSTR_METHOD]) == 0) {
2449                 classIndex = literalIndexForJavaLangStringBuffer();
2450                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[DEFAULT_CONSTR_METHOD_NAME_AND_TYPE]) == 0) {
2451                         int nameIndex = literalIndex(QualifiedNamesConstants.Init);
2452                         int typeIndex = literalIndex(QualifiedNamesConstants.DefaultConstructorSignature);
2453                         nameAndTypeIndex = wellKnownMethodNameAndTypes[DEFAULT_CONSTR_METHOD_NAME_AND_TYPE] = currentIndex++;
2454                         writeU1(NameAndTypeTag);
2455                         writeU2(nameIndex);
2456                         writeU2(typeIndex);
2457                 }
2458                 index = wellKnownMethods[STRINGBUFFER_DEFAULT_CONSTR_METHOD] = currentIndex++;
2459                 if (index > 0xFFFF){
2460                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2461                 }
2462                 // Write the method ref constant into the constant pool
2463                 // First add the tag
2464                 writeU1(MethodRefTag);
2465                 // Then write the class index
2466                 writeU2(classIndex);
2467                 // The write the nameAndType index
2468                 writeU2(nameAndTypeIndex);
2469         }
2470         return index;
2471 }
2472 /**
2473  * This method returns the index into the constantPool corresponding to the 
2474  * method descriptor. It can be either an interface method reference constant
2475  * or a method reference constant.
2476  *
2477  * @return <CODE>int</CODE>
2478  */
2479 public int literalIndexForJavaLangStringBufferToString() {
2480         int index;
2481         int nameAndTypeIndex;
2482         int classIndex;
2483         // Looking into the method ref table
2484         if ((index = wellKnownMethods[STRINGBUFFER_TOSTRING_METHOD]) == 0) {
2485                 classIndex = literalIndexForJavaLangStringBuffer();
2486                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[TOSTRING_METHOD_NAME_AND_TYPE]) == 0) {
2487                         int nameIndex = literalIndex(QualifiedNamesConstants.ToString);
2488                         int typeIndex = literalIndex(QualifiedNamesConstants.ToStringSignature);
2489                         nameAndTypeIndex = wellKnownMethodNameAndTypes[TOSTRING_METHOD_NAME_AND_TYPE] = currentIndex++;
2490                         writeU1(NameAndTypeTag);
2491                         writeU2(nameIndex);
2492                         writeU2(typeIndex);
2493                 }
2494                 index = wellKnownMethods[STRINGBUFFER_TOSTRING_METHOD] = currentIndex++;
2495                 if (index > 0xFFFF){
2496                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2497                 }
2498                 // Write the method ref constant into the constant pool
2499                 // First add the tag
2500                 writeU1(MethodRefTag);
2501                 // Then write the class index
2502                 writeU2(classIndex);
2503                 // The write the nameAndType index
2504                 writeU2(nameAndTypeIndex);
2505         }
2506         return index;
2507 }
2508 /**
2509  * This method returns the index into the constantPool corresponding to the 
2510  * method descriptor. It can be either an interface method reference constant
2511  * or a method reference constant.
2512  *
2513  * @return <CODE>int</CODE>
2514  */
2515 public int literalIndexForJavaLangStringIntern() {
2516         int index;
2517         int nameAndTypeIndex;
2518         int classIndex;
2519         // Looking into the method ref table
2520         if ((index = wellKnownMethods[STRING_INTERN_METHOD]) == 0) {
2521                 classIndex = literalIndexForJavaLangString();
2522                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[INTERN_METHOD_NAME_AND_TYPE]) == 0) {
2523                         int nameIndex = literalIndex(QualifiedNamesConstants.Intern);
2524                         int typeIndex = literalIndex(QualifiedNamesConstants.InternSignature);
2525                         nameAndTypeIndex = wellKnownMethodNameAndTypes[INTERN_METHOD_NAME_AND_TYPE] = currentIndex++;
2526                         writeU1(NameAndTypeTag);
2527                         writeU2(nameIndex);
2528                         writeU2(typeIndex);
2529                 }
2530                 index = wellKnownMethods[STRING_INTERN_METHOD] = currentIndex++;
2531                 if (index > 0xFFFF){
2532                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2533                 }
2534                 // Write the method ref constant into the constant pool
2535                 // First add the tag
2536                 writeU1(MethodRefTag);
2537                 // Then write the class index
2538                 writeU2(classIndex);
2539                 // The write the nameAndType index
2540                 writeU2(nameAndTypeIndex);
2541         }
2542         return index;
2543 }
2544 /**
2545  * This method returns the index into the constantPool corresponding to the 
2546  * method descriptor. It can be either an interface method reference constant
2547  * or a method reference constant.
2548  *
2549  * @return <CODE>int</CODE>
2550  */
2551 public int literalIndexForJavaLangStringValueOf(int typeID) {
2552         int index = 0;
2553         int nameAndTypeIndex = 0;
2554         int classIndex = literalIndexForJavaLangString();
2555         switch (typeID) {
2556                 case T_int :
2557                 case T_byte :
2558                 case T_short :
2559                         if ((index = wellKnownMethods[VALUEOF_INT_METHOD]) == 0) {
2560                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_INT_METHOD_NAME_AND_TYPE]) == 0) {
2561                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2562                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfIntSignature);
2563                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_INT_METHOD_NAME_AND_TYPE] = currentIndex++;
2564                                         writeU1(NameAndTypeTag);
2565                                         writeU2(nameIndex);
2566                                         writeU2(typeIndex);
2567                                 }
2568                                 index = wellKnownMethods[VALUEOF_INT_METHOD] = currentIndex++;
2569                                 if (index > 0xFFFF){
2570                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2571                                 }
2572                                 // Write the method ref constant into the constant pool
2573                                 // First add the tag
2574                                 writeU1(MethodRefTag);
2575                                 // Then write the class index
2576                                 writeU2(classIndex);
2577                                 // The write the nameAndType index
2578                                 writeU2(nameAndTypeIndex);
2579                         }
2580                         break;
2581                 case T_long :
2582                         if ((index = wellKnownMethods[VALUEOF_LONG_METHOD]) == 0) {
2583                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_LONG_METHOD_NAME_AND_TYPE]) == 0) {
2584                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2585                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfLongSignature);
2586                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_LONG_METHOD_NAME_AND_TYPE] = currentIndex++;
2587                                         writeU1(NameAndTypeTag);
2588                                         writeU2(nameIndex);
2589                                         writeU2(typeIndex);
2590                                 }
2591                                 index = wellKnownMethods[VALUEOF_LONG_METHOD] = currentIndex++;
2592                                 if (index > 0xFFFF){
2593                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2594                                 }
2595                                 // Write the method ref constant into the constant pool
2596                                 // First add the tag
2597                                 writeU1(MethodRefTag);
2598                                 // Then write the class index
2599                                 writeU2(classIndex);
2600                                 // The write the nameAndType index
2601                                 writeU2(nameAndTypeIndex);
2602                         }
2603                         break;
2604                 case T_float :
2605                         if ((index = wellKnownMethods[VALUEOF_FLOAT_METHOD]) == 0) {
2606                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_FLOAT_METHOD_NAME_AND_TYPE]) == 0) {
2607                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2608                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfFloatSignature);
2609                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_FLOAT_METHOD_NAME_AND_TYPE] = currentIndex++;
2610                                         writeU1(NameAndTypeTag);
2611                                         writeU2(nameIndex);
2612                                         writeU2(typeIndex);
2613                                 }
2614                                 index = wellKnownMethods[VALUEOF_FLOAT_METHOD] = currentIndex++;
2615                                 if (index > 0xFFFF){
2616                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2617                                 }
2618                                 // Write the method ref constant into the constant pool
2619                                 // First add the tag
2620                                 writeU1(MethodRefTag);
2621                                 // Then write the class index
2622                                 writeU2(classIndex);
2623                                 // The write the nameAndType index
2624                                 writeU2(nameAndTypeIndex);
2625                         }
2626                         break;
2627                 case T_double :
2628                         if ((index = wellKnownMethods[VALUEOF_DOUBLE_METHOD]) == 0) {
2629                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_DOUBLE_METHOD_NAME_AND_TYPE]) == 0) {
2630                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2631                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfDoubleSignature);
2632                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_DOUBLE_METHOD_NAME_AND_TYPE] = currentIndex++;
2633                                         writeU1(NameAndTypeTag);
2634                                         writeU2(nameIndex);
2635                                         writeU2(typeIndex);
2636                                 }
2637                                 index = wellKnownMethods[VALUEOF_DOUBLE_METHOD] = currentIndex++;
2638                                 if (index > 0xFFFF){
2639                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2640                                 }
2641                                 // Write the method ref constant into the constant pool
2642                                 // First add the tag
2643                                 writeU1(MethodRefTag);
2644                                 // Then write the class index
2645                                 writeU2(classIndex);
2646                                 // The write the nameAndType index
2647                                 writeU2(nameAndTypeIndex);
2648                         }
2649                         break;
2650                 case T_char :
2651                         if ((index = wellKnownMethods[VALUEOF_CHAR_METHOD]) == 0) {
2652                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_CHAR_METHOD_NAME_AND_TYPE]) == 0) {
2653                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2654                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfCharSignature);
2655                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_CHAR_METHOD_NAME_AND_TYPE] = currentIndex++;
2656                                         writeU1(NameAndTypeTag);
2657                                         writeU2(nameIndex);
2658                                         writeU2(typeIndex);
2659                                 }
2660                                 index = wellKnownMethods[VALUEOF_CHAR_METHOD] = currentIndex++;
2661                                 if (index > 0xFFFF){
2662                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2663                                 }
2664                                 // Write the method ref constant into the constant pool
2665                                 // First add the tag
2666                                 writeU1(MethodRefTag);
2667                                 // Then write the class index
2668                                 writeU2(classIndex);
2669                                 // The write the nameAndType index
2670                                 writeU2(nameAndTypeIndex);
2671                         }
2672                         break;
2673                 case T_boolean :
2674                         if ((index = wellKnownMethods[VALUEOF_BOOLEAN_METHOD]) == 0) {
2675                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_BOOLEAN_METHOD_NAME_AND_TYPE]) == 0) {
2676                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2677                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfBooleanSignature);
2678                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_BOOLEAN_METHOD_NAME_AND_TYPE] = currentIndex++;
2679                                         writeU1(NameAndTypeTag);
2680                                         writeU2(nameIndex);
2681                                         writeU2(typeIndex);
2682                                 }
2683                                 index = wellKnownMethods[VALUEOF_BOOLEAN_METHOD] = currentIndex++;
2684                                 if (index > 0xFFFF){
2685                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2686                                 }
2687                                 // Write the method ref constant into the constant pool
2688                                 // First add the tag
2689                                 writeU1(MethodRefTag);
2690                                 // Then write the class index
2691                                 writeU2(classIndex);
2692                                 // The write the nameAndType index
2693                                 writeU2(nameAndTypeIndex);
2694                         }
2695                         break;
2696                 case T_Object :
2697                         if ((index = wellKnownMethods[VALUEOF_OBJECT_METHOD]) == 0) {
2698                                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_OBJECT_METHOD_NAME_AND_TYPE]) == 0) {
2699                                         int nameIndex = literalIndex(QualifiedNamesConstants.ValueOf);
2700                                         int typeIndex = literalIndex(QualifiedNamesConstants.ValueOfObjectSignature);
2701                                         nameAndTypeIndex = wellKnownMethodNameAndTypes[VALUEOF_OBJECT_METHOD_NAME_AND_TYPE] = currentIndex++;
2702                                         writeU1(NameAndTypeTag);
2703                                         writeU2(nameIndex);
2704                                         writeU2(typeIndex);
2705                                 }
2706                                 index = wellKnownMethods[VALUEOF_OBJECT_METHOD] = currentIndex++;
2707                                 if (index > 0xFFFF){
2708                                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2709                                 }
2710                                 // Write the method ref constant into the constant pool
2711                                 // First add the tag
2712                                 writeU1(MethodRefTag);
2713                                 // Then write the class index
2714                                 writeU2(classIndex);
2715                                 // The write the nameAndType index
2716                                 writeU2(nameAndTypeIndex);
2717                         }
2718                         break;
2719         }
2720         return index;
2721 }
2722 /**
2723  * This method returns the index into the constantPool corresponding to the type descriptor.
2724  *
2725  * @param TypeBinding aTypeBinding
2726  * @return <CODE>int</CODE>
2727  */
2728 public int literalIndexForJavaLangSystem() {
2729         int index;
2730         if ((index = wellKnownTypes[JAVA_LANG_SYSTEM_TYPE]) == 0) {
2731                 int nameIndex;
2732                 // The entry doesn't exit yet
2733                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangSystemConstantPoolName);
2734                 index = wellKnownTypes[JAVA_LANG_SYSTEM_TYPE] = currentIndex++;
2735                 if (index > 0xFFFF){
2736                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2737                 }
2738                 writeU1(ClassTag);
2739                 // Then add the 8 bytes representing the long
2740                 writeU2(nameIndex);
2741         }
2742         return index;
2743 }
2744 /**
2745  * This method returns the index into the constantPool corresponding to the 
2746  * method descriptor. It can be either an interface method reference constant
2747  * or a method reference constant.
2748  *
2749  * @return <CODE>int</CODE>
2750  */
2751 public int literalIndexForJavaLangSystemExitInt() {
2752         int index;
2753         int nameAndTypeIndex;
2754         int classIndex;
2755         // Looking into the method ref table
2756         if ((index = wellKnownMethods[SYSTEM_EXIT_METHOD]) == 0) {
2757                 classIndex = literalIndexForJavaLangSystem();
2758                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[EXIT_METHOD_NAME_AND_TYPE]) == 0) {
2759                         int nameIndex = literalIndex(QualifiedNamesConstants.Exit);
2760                         int typeIndex = literalIndex(QualifiedNamesConstants.ExitIntSignature);
2761                         nameAndTypeIndex = wellKnownMethodNameAndTypes[EXIT_METHOD_NAME_AND_TYPE] = currentIndex++;
2762                         writeU1(NameAndTypeTag);
2763                         writeU2(nameIndex);
2764                         writeU2(typeIndex);
2765                 }
2766                 index = wellKnownMethods[SYSTEM_EXIT_METHOD] = currentIndex++;
2767                 if (index > 0xFFFF){
2768                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2769                 }
2770                 // Write the method ref constant into the constant pool
2771                 // First add the tag
2772                 writeU1(MethodRefTag);
2773                 // Then write the class index
2774                 writeU2(classIndex);
2775                 // The write the nameAndType index
2776                 writeU2(nameAndTypeIndex);
2777         }
2778         return index;
2779 }
2780 /**
2781  * This method returns the index into the constantPool 
2782  * corresponding to the field binding aFieldBinding.
2783  *
2784  * @return <CODE>int</CODE>
2785  */
2786 public int literalIndexForJavaLangSystemOut() {
2787         int index;
2788         if ((index = wellKnownFields[OUT_SYSTEM_FIELD]) == 0) {
2789                 int nameAndTypeIndex;
2790                 int classIndex;
2791                 // The entry doesn't exit yet
2792                 classIndex = literalIndexForJavaLangSystem();
2793                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[OUT_SYSTEM_NAME_AND_TYPE]) == 0) {
2794                         int nameIndex = literalIndex(QualifiedNamesConstants.Out);
2795                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaIoPrintStreamSignature);
2796                         nameAndTypeIndex = wellKnownMethodNameAndTypes[OUT_SYSTEM_NAME_AND_TYPE] = currentIndex++;
2797                         writeU1(NameAndTypeTag);
2798                         writeU2(nameIndex);
2799                         writeU2(typeIndex);
2800                 }
2801                 index = wellKnownFields[OUT_SYSTEM_FIELD] = currentIndex++;
2802                 if (index > 0xFFFF){
2803                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2804                 }
2805                 writeU1(FieldRefTag);
2806                 writeU2(classIndex);
2807                 writeU2(nameAndTypeIndex);
2808         }
2809         return index;
2810 }
2811 /**
2812  * This method returns the index into the constantPool corresponding to the type descriptor.
2813  *
2814  * @param TypeBinding aTypeBinding
2815  * @return <CODE>int</CODE>
2816  */
2817 public int literalIndexForJavaLangThrowable() {
2818         int index;
2819         if ((index = wellKnownTypes[JAVA_LANG_THROWABLE_TYPE]) == 0) {
2820                 int nameIndex;
2821                 // The entry doesn't exit yet
2822                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangThrowableConstantPoolName);
2823                 index = wellKnownTypes[JAVA_LANG_THROWABLE_TYPE] = currentIndex++;
2824                 if (index > 0xFFFF){
2825                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2826                 }
2827                 writeU1(ClassTag);
2828                 // Then add the 8 bytes representing the long
2829                 writeU2(nameIndex);
2830         }
2831         return index;
2832 }
2833 /**
2834  * This method returns the index into the constantPool corresponding to the 
2835  * method descriptor. It can be either an interface method reference constant
2836  * or a method reference constant.
2837  *
2838  * @return <CODE>int</CODE>
2839  */
2840 public int literalIndexForJavaLangThrowableGetMessage() {
2841         int index;
2842         int nameAndTypeIndex;
2843         int classIndex;
2844         // Looking into the method ref table
2845         if ((index = wellKnownMethods[THROWABLE_GETMESSAGE_METHOD]) == 0) {
2846                 classIndex = literalIndexForJavaLangThrowable();
2847                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[GETMESSAGE_METHOD_NAME_AND_TYPE]) == 0) {
2848                         int nameIndex = literalIndex(QualifiedNamesConstants.GetMessage);
2849                         int typeIndex = literalIndex(QualifiedNamesConstants.GetMessageSignature);
2850                         nameAndTypeIndex = wellKnownMethodNameAndTypes[GETMESSAGE_METHOD_NAME_AND_TYPE] = currentIndex++;
2851                         writeU1(NameAndTypeTag);
2852                         writeU2(nameIndex);
2853                         writeU2(typeIndex);
2854                 }
2855                 index = wellKnownMethods[THROWABLE_GETMESSAGE_METHOD] = currentIndex++;
2856                 if (index > 0xFFFF){
2857                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2858                 }
2859                 // Write the method ref constant into the constant pool
2860                 // First add the tag
2861                 writeU1(MethodRefTag);
2862                 // Then write the class index
2863                 writeU2(classIndex);
2864                 // The write the nameAndType index
2865                 writeU2(nameAndTypeIndex);
2866         }
2867         return index;
2868 }
2869 /**
2870  * This method returns the index into the constantPool corresponding to the type descriptor.
2871  *
2872  * @param TypeBinding aTypeBinding
2873  * @return <CODE>int</CODE>
2874  */
2875 public int literalIndexForJavaLangVoid() {
2876         int index;
2877         if ((index = wellKnownTypes[JAVA_LANG_VOID_TYPE]) == 0) {
2878                 int nameIndex;
2879                 // The entry doesn't exit yet
2880                 nameIndex = literalIndex(QualifiedNamesConstants.JavaLangVoidConstantPoolName);
2881                 index = wellKnownTypes[JAVA_LANG_VOID_TYPE] = currentIndex++;
2882                 if (index > 0xFFFF){
2883                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2884                 }
2885                 writeU1(ClassTag);
2886                 // Then add the 8 bytes representing the long
2887                 writeU2(nameIndex);
2888         }
2889         return index;
2890 }
2891 /**
2892  * This method returns the index into the constantPool 
2893  * corresponding to the field binding aFieldBinding.
2894  *
2895  * @return <CODE>int</CODE>
2896  */
2897 public int literalIndexForJavaLangVoidTYPE() {
2898         int index;
2899         if ((index = wellKnownFields[TYPE_VOID_FIELD]) == 0) {
2900                 int nameAndTypeIndex;
2901                 int classIndex;
2902                 // The entry doesn't exit yet
2903                 classIndex = literalIndexForJavaLangVoid();
2904                 if ((nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE]) == 0) {
2905                         int nameIndex = literalIndex(QualifiedNamesConstants.TYPE);
2906                         int typeIndex = literalIndex(QualifiedNamesConstants.JavaLangClassSignature);
2907                         nameAndTypeIndex = wellKnownFieldNameAndTypes[TYPE_JAVALANGCLASS_NAME_AND_TYPE] = currentIndex++;
2908                         writeU1(NameAndTypeTag);
2909                         writeU2(nameIndex);
2910                         writeU2(typeIndex);
2911                 }
2912                 index = wellKnownFields[TYPE_VOID_FIELD] = currentIndex++;
2913                 if (index > 0xFFFF){
2914                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2915                 }
2916                 writeU1(FieldRefTag);
2917                 writeU2(classIndex);
2918                 writeU2(nameAndTypeIndex);
2919         }
2920         return index;
2921 }
2922 /**
2923  * This method returns the index into the constantPool corresponding to the type descriptor.
2924  *
2925  * @param char[] stringName
2926  * @return <CODE>int</CODE>
2927  */
2928 public int literalIndexForLdc(char[] stringCharArray) {
2929         int index;
2930         if ((index = stringCache.get(stringCharArray)) < 0) {
2931                 int stringIndex;
2932                 // The entry doesn't exit yet
2933                 if ((stringIndex = UTF8Cache.get(stringCharArray)) < 0) {
2934                         // The entry doesn't exit yet
2935                         // Write the tag first
2936                         writeU1(Utf8Tag);
2937                         // Then the size of the stringName array
2938                         int savedCurrentOffset = currentOffset;
2939                         if (currentOffset + 2 >= poolContent.length) {
2940                                 // we need to resize the poolContent array because we won't have
2941                                 // enough space to write the length
2942                                 int length = poolContent.length;
2943                                 System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
2944                         }
2945                         currentOffset += 2;
2946                         int length = 0;
2947                         for (int i = 0; i < stringCharArray.length; i++) {
2948                                 char current = stringCharArray[i];
2949                                 if ((current >= 0x0001) && (current <= 0x007F)) {
2950                                         // we only need one byte: ASCII table
2951                                         writeU1(current);
2952                                         length++;
2953                                 } else
2954                                         if (current > 0x07FF) {
2955                                                 // we need 3 bytes
2956                                                 length += 3;
2957                                                 writeU1(0xE0 | ((current >> 12) & 0x0F)); // 0xE0 = 1110 0000
2958                                                 writeU1(0x80 | ((current >> 6) & 0x3F)); // 0x80 = 1000 0000
2959                                                 writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
2960                                         } else {
2961                                                 // we can be 0 or between 0x0080 and 0x07FF
2962                                                 // In that case we only need 2 bytes
2963                                                 length += 2;
2964                                                 writeU1(0xC0 | ((current >> 6) & 0x1F)); // 0xC0 = 1100 0000
2965                                                 writeU1(0x80 | (current & 0x3F)); // 0x80 = 1000 0000
2966                                         }
2967                         }
2968                         if (length >= 65535) {
2969                                 currentOffset = savedCurrentOffset - 1;
2970                                 return -1;
2971                         }
2972                         stringIndex = UTF8Cache.put(stringCharArray, currentIndex++);
2973                         // Now we know the length that we have to write in the constant pool
2974                         // we use savedCurrentOffset to do that
2975                         if (length > 65535) {
2976                                 return 0;
2977                         }
2978                         poolContent[savedCurrentOffset] = (byte) (length >> 8);
2979                         poolContent[savedCurrentOffset + 1] = (byte) length;
2980                 }
2981                 index = stringCache.put(stringCharArray, currentIndex++);
2982                 if (index > 0xFFFF){
2983                         this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
2984                 }
2985                 // Write the tag first
2986                 writeU1(StringTag);
2987                 // Then the string index
2988                 writeU2(stringIndex);
2989         }
2990         return index;
2991 }
2992 /**
2993  * This method returns the index into the constantPool corresponding 
2994  * nameAndType constant with nameIndex, typeIndex.
2995  *
2996  * @param int nameIndex
2997  * @param int nameIndex
2998  * @param org.eclipse.jdt.internal.compiler.lookup.MethodBinding a methodBinding
2999  * @return <CODE>int</CODE>
3000  */
3001 public int literalIndexForMethods(int nameIndex, int typeIndex, MethodBinding key) {
3002         int index;
3003         int indexOfWellKnownMethodNameAndType;
3004         if ((indexOfWellKnownMethodNameAndType = indexOfWellKnownMethodNameAndType(key)) == -1) {
3005                 // check if the entry exists
3006                 if ((index = nameAndTypeCacheForMethods.get(key)) == -1) {
3007                         // The entry doesn't exit yet
3008                         index = nameAndTypeCacheForMethods.put(key, currentIndex++);
3009                         if (index > 0xFFFF){
3010                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
3011                         }
3012                         writeU1(NameAndTypeTag);
3013                         writeU2(nameIndex);
3014                         writeU2(typeIndex);
3015                 }
3016         } else {
3017                 if ((index = wellKnownMethodNameAndTypes[indexOfWellKnownMethodNameAndType]) == 0) {
3018                         index = wellKnownMethodNameAndTypes[indexOfWellKnownMethodNameAndType] = currentIndex++;
3019                         if (index > 0xFFFF){
3020                                 this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType());
3021                         }
3022                         writeU1(NameAndTypeTag);
3023                         writeU2(nameIndex);
3024                         writeU2(typeIndex);
3025                 }
3026         }
3027         return index;
3028 }
3029 /**
3030  * This method returns the index into the constantPool corresponding to the 
3031  * method descriptor. It can be either an interface method reference constant
3032  * or a method reference constant.
3033  *
3034  * @return <CODE>int</CODE>
3035  */
3036 public int literalIndexForJavaLangObjectGetClass() {
3037         int index;
3038         int nameAndTypeIndex;
3039         int classIndex;
3040         // Looking into the method ref table
3041         if ((index = wellKnownMethods[GETCLASS_OBJECT_METHOD]) == 0) {
3042                 classIndex = literalIndexForJavaLangObject();
3043                 if ((nameAndTypeIndex = wellKnownMethodNameAndTypes[GETCLASS_OBJECT_METHOD_NAME_AND_TYPE]) == 0) {
3044                         int nameIndex = literalIndex(QualifiedNamesConstants.GetClass);
3045                         int typeIndex = literalIndex(QualifiedNamesConstants.GetClassSignature);
3046                         nameAndTypeIndex = wellKnownMethodNameAndTypes[GETCLASS_OBJECT_METHOD_NAME_AND_TYPE] = currentIndex++;
3047                         writeU1(NameAndTypeTag);
3048                         writeU2(nameIndex);
3049                         writeU2(typeIndex);
3050                 }
3051                 index = wellKnownMethods[GETCLASS_OBJECT_METHOD] = currentIndex++;
3052                 // Write the method ref constant into the constant pool
3053                 // First add the tag
3054                 writeU1(MethodRefTag);
3055                 // Then write the class index
3056                 writeU2(classIndex);
3057                 // The write the nameAndType index
3058                 writeU2(nameAndTypeIndex);
3059         }
3060         return index;
3061 }
3062 /**
3063  * This method is used to clean the receiver in case of a clinit header is generated, but the 
3064  * clinit has no code.
3065  * This implementation assumes that the clinit is the first method to be generated.
3066  * @see org.eclipse.jdt.internal.compiler.ast.TypeDeclaration#addClinit()
3067  */
3068 public void resetForClinit(int constantPoolIndex, int constantPoolOffset) {
3069         currentIndex = constantPoolIndex;
3070         currentOffset = constantPoolOffset;
3071         if (UTF8Cache.get(AttributeNamesConstants.CodeName) >= constantPoolIndex) {
3072                 UTF8Cache.remove(AttributeNamesConstants.CodeName);
3073         }
3074         if (UTF8Cache.get(QualifiedNamesConstants.ClinitSignature) >= constantPoolIndex) {
3075                 UTF8Cache.remove(QualifiedNamesConstants.ClinitSignature);
3076         }
3077         if (UTF8Cache.get(QualifiedNamesConstants.Clinit) >= constantPoolIndex) {
3078                 UTF8Cache.remove(QualifiedNamesConstants.Clinit);
3079         }
3080 }
3081 /**
3082  * Write a unsigned byte into the byte array
3083  * 
3084  * @param <CODE>int</CODE> The value to write into the byte array
3085  */
3086 protected final void writeU1(int value) {
3087         try {
3088                 poolContent[currentOffset++] = (byte) value;
3089         } catch (IndexOutOfBoundsException e) {
3090                 //currentOffset has been ++ already (see the -1)
3091                 int length = poolContent.length;
3092                 System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
3093                 poolContent[currentOffset - 1] = (byte) value;
3094         }
3095 }
3096 /**
3097  * Write a unsigned byte into the byte array
3098  * 
3099  * @param <CODE>int</CODE> The value to write into the byte array
3100  */
3101 protected final void writeU2(int value) {
3102         //first byte
3103         try {
3104                 poolContent[currentOffset++] = (byte) (value >> 8);
3105         } catch (IndexOutOfBoundsException e) {
3106                  //currentOffset has been ++ already (see the -1)
3107                 int length = poolContent.length;
3108                 System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
3109                 poolContent[currentOffset - 1] = (byte) (value >> 8);
3110         }
3111         try {
3112                 poolContent[currentOffset++] = (byte) value;
3113         } catch (IndexOutOfBoundsException e) {
3114                  //currentOffset has been ++ already (see the -1)
3115                 int length = poolContent.length;
3116                 System.arraycopy(poolContent, 0, (poolContent = new byte[length + CONSTANTPOOL_GROW_SIZE]), 0, length);
3117                 poolContent[currentOffset - 1] = (byte) value;
3118         }
3119 }
3120 }