|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -226,6 +226,8 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
|
226 | 226 | cf.loadTarget(mv);
|
227 | 227 | }
|
228 | 228 |
|
| 229 | + SpelNodeImpl index = this.children[0]; |
| 230 | + |
229 | 231 | if (this.indexedType == IndexedType.ARRAY) {
|
230 | 232 | int insn;
|
231 | 233 | if ("D".equals(this.exitTypeDescriptor)) {
|
@@ -262,33 +264,29 @@ else if ("C".equals(this.exitTypeDescriptor)) {
|
262 | 264 | //depthPlusOne(exitTypeDescriptor)+"Ljava/lang/Object;");
|
263 | 265 | insn = AALOAD;
|
264 | 266 | }
|
265 |
| - SpelNodeImpl index = this.children[0]; |
266 |
| - cf.enterCompilationScope(); |
267 |
| - index.generateCode(mv, cf); |
268 |
| - cf.exitCompilationScope(); |
| 267 | + |
| 268 | + generateIndexCode(mv, cf, index, int.class); |
269 | 269 | mv.visitInsn(insn);
|
270 | 270 | }
|
271 | 271 |
|
272 | 272 | else if (this.indexedType == IndexedType.LIST) {
|
273 | 273 | mv.visitTypeInsn(CHECKCAST, "java/util/List");
|
274 |
| - cf.enterCompilationScope(); |
275 |
| - this.children[0].generateCode(mv, cf); |
276 |
| - cf.exitCompilationScope(); |
| 274 | + generateIndexCode(mv, cf, index, int.class); |
277 | 275 | mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true);
|
278 | 276 | }
|
279 | 277 |
|
280 | 278 | else if (this.indexedType == IndexedType.MAP) {
|
281 | 279 | mv.visitTypeInsn(CHECKCAST, "java/util/Map");
|
282 | 280 | // Special case when the key is an unquoted string literal that will be parsed as
|
283 | 281 | // a property/field reference
|
284 |
| - if ((this.children[0] instanceof PropertyOrFieldReference)) { |
| 282 | + if (index instanceof PropertyOrFieldReference) { |
285 | 283 | PropertyOrFieldReference reference = (PropertyOrFieldReference) this.children[0];
|
286 | 284 | String mapKeyName = reference.getName();
|
287 | 285 | mv.visitLdcInsn(mapKeyName);
|
288 | 286 | }
|
289 | 287 | else {
|
290 | 288 | cf.enterCompilationScope();
|
291 |
| - this.children[0].generateCode(mv, cf); |
| 289 | + index.generateCode(mv, cf); |
292 | 290 | cf.exitCompilationScope();
|
293 | 291 | }
|
294 | 292 | mv.visitMethodInsn(
|
@@ -325,6 +323,11 @@ else if (this.indexedType == IndexedType.OBJECT) {
|
325 | 323 | cf.pushDescriptor(this.exitTypeDescriptor);
|
326 | 324 | }
|
327 | 325 |
|
| 326 | + private void generateIndexCode(MethodVisitor mv, CodeFlow cf, SpelNodeImpl indexNode, Class<?> indexType) { |
| 327 | + String indexDesc = CodeFlow.toDescriptor(indexType); |
| 328 | + generateCodeForArgument(mv, cf, indexNode, indexDesc); |
| 329 | + } |
| 330 | + |
328 | 331 | @Override
|
329 | 332 | public String toStringAST() {
|
330 | 333 | StringJoiner sj = new StringJoiner(",", "[", "]");
|
|
0 commit comments