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