Lines 26-31
Link Here
|
26 |
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; |
26 |
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; |
27 |
import org.eclipse.jdt.internal.compiler.lookup.MethodScope; |
27 |
import org.eclipse.jdt.internal.compiler.lookup.MethodScope; |
28 |
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; |
28 |
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; |
|
|
29 |
import org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding; |
29 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
30 |
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
30 |
import org.eclipse.jdt.internal.compiler.parser.Parser; |
31 |
import org.eclipse.jdt.internal.compiler.parser.Parser; |
31 |
import org.eclipse.jdt.internal.compiler.problem.AbortMethod; |
32 |
import org.eclipse.jdt.internal.compiler.problem.AbortMethod; |
Lines 191-206
Link Here
|
191 |
// generate static fields/initializers/enum constants |
192 |
// generate static fields/initializers/enum constants |
192 |
final FieldDeclaration[] fieldDeclarations = declaringType.fields; |
193 |
final FieldDeclaration[] fieldDeclarations = declaringType.fields; |
193 |
BlockScope lastInitializerScope = null; |
194 |
BlockScope lastInitializerScope = null; |
|
|
195 |
int remainingFieldCount = 0; |
194 |
if (TypeDeclaration.kind(declaringType.modifiers) == TypeDeclaration.ENUM_DECL) { |
196 |
if (TypeDeclaration.kind(declaringType.modifiers) == TypeDeclaration.ENUM_DECL) { |
195 |
int enumCount = 0; |
197 |
int enumCount = declaringType.enumConstantsCounter; |
196 |
int remainingFieldCount = 0; |
198 |
if (enumCount > 2000) { |
197 |
if (fieldDeclarations != null) { |
199 |
// generate synthetic methods to initialize all the enum constants |
|
|
200 |
int begin = -1; |
201 |
int count = 0; |
202 |
if (fieldDeclarations != null) { |
203 |
int max = fieldDeclarations.length; |
204 |
for (int i = 0; i < max; i++) { |
205 |
FieldDeclaration fieldDecl = fieldDeclarations[i]; |
206 |
if (fieldDecl.isStatic()) { |
207 |
if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { |
208 |
if (begin == -1) { |
209 |
begin = i; |
210 |
} |
211 |
count++; |
212 |
if (count > 2000) { |
213 |
SyntheticMethodBinding syntheticMethod = declaringType.binding.addSyntheticMethodForEnumInitialization(begin, i); |
214 |
codeStream.invoke(Opcodes.OPC_invokestatic, syntheticMethod, null /* default declaringClass */); |
215 |
begin = -1; |
216 |
count = 0; |
217 |
} |
218 |
} |
219 |
} |
220 |
} |
221 |
if (count != 0) { |
222 |
// add last synthetic method |
223 |
SyntheticMethodBinding syntheticMethod = declaringType.binding.addSyntheticMethodForEnumInitialization(begin, max); |
224 |
codeStream.invoke(Opcodes.OPC_invokestatic, syntheticMethod, null /* default declaringClass */); |
225 |
} |
226 |
} |
227 |
} else if (fieldDeclarations != null) { |
198 |
for (int i = 0, max = fieldDeclarations.length; i < max; i++) { |
228 |
for (int i = 0, max = fieldDeclarations.length; i < max; i++) { |
199 |
FieldDeclaration fieldDecl = fieldDeclarations[i]; |
229 |
FieldDeclaration fieldDecl = fieldDeclarations[i]; |
200 |
if (fieldDecl.isStatic()) { |
230 |
if (fieldDecl.isStatic()) { |
201 |
if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { |
231 |
if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { |
202 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
232 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
203 |
enumCount++; |
|
|
204 |
} else { |
233 |
} else { |
205 |
remainingFieldCount++; |
234 |
remainingFieldCount++; |
206 |
} |
235 |
} |
Lines 228-247
Link Here
|
228 |
codeStream.fieldAccess(Opcodes.OPC_putstatic, declaringType.enumValuesSyntheticfield, null /* default declaringClass */); |
257 |
codeStream.fieldAccess(Opcodes.OPC_putstatic, declaringType.enumValuesSyntheticfield, null /* default declaringClass */); |
229 |
if (remainingFieldCount != 0) { |
258 |
if (remainingFieldCount != 0) { |
230 |
// if fields that are not enum constants need to be generated (static initializer/static field) |
259 |
// if fields that are not enum constants need to be generated (static initializer/static field) |
231 |
for (int i = 0, max = fieldDeclarations.length; i < max; i++) { |
260 |
for (int i = 0, max = fieldDeclarations.length; i < max && remainingFieldCount >= 0; i++) { |
232 |
FieldDeclaration fieldDecl = fieldDeclarations[i]; |
261 |
FieldDeclaration fieldDecl = fieldDeclarations[i]; |
233 |
switch (fieldDecl.getKind()) { |
262 |
switch (fieldDecl.getKind()) { |
234 |
case AbstractVariableDeclaration.ENUM_CONSTANT : |
263 |
case AbstractVariableDeclaration.ENUM_CONSTANT : |
235 |
break; |
264 |
break; |
236 |
case AbstractVariableDeclaration.INITIALIZER : |
265 |
case AbstractVariableDeclaration.INITIALIZER : |
237 |
if (!fieldDecl.isStatic()) |
266 |
if (!fieldDecl.isStatic()) { |
238 |
break; |
267 |
break; |
|
|
268 |
} |
269 |
remainingFieldCount--; |
239 |
lastInitializerScope = ((Initializer) fieldDecl).block.scope; |
270 |
lastInitializerScope = ((Initializer) fieldDecl).block.scope; |
240 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
271 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
241 |
break; |
272 |
break; |
242 |
case AbstractVariableDeclaration.FIELD : |
273 |
case AbstractVariableDeclaration.FIELD : |
243 |
if (!fieldDecl.binding.isStatic()) |
274 |
if (!fieldDecl.binding.isStatic()) { |
244 |
break; |
275 |
break; |
|
|
276 |
} |
277 |
remainingFieldCount--; |
245 |
lastInitializerScope = null; |
278 |
lastInitializerScope = null; |
246 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
279 |
fieldDecl.generateCode(staticInitializerScope, codeStream); |
247 |
break; |
280 |
break; |