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