|
22 | 22 | import org.apache.groovy.ast.tools.ExpressionUtils; |
23 | 23 | import org.codehaus.groovy.GroovyBugError; |
24 | 24 | import org.codehaus.groovy.ast.ASTNode; |
25 | | -import org.codehaus.groovy.ast.ClassHelper; |
26 | 25 | import org.codehaus.groovy.ast.ClassNode; |
27 | 26 | import org.codehaus.groovy.ast.FieldNode; |
28 | 27 | import org.codehaus.groovy.ast.InnerClassNode; |
|
58 | 57 | import groovyjarjarasm.asm.MethodVisitor; |
59 | 58 | import groovyjarjarasm.asm.Opcodes; |
60 | 59 |
|
61 | | -import java.lang.reflect.Modifier; |
62 | 60 | import java.util.ArrayList; |
63 | 61 | import java.util.Collection; |
64 | 62 | import java.util.List; |
|
86 | 84 | import static org.codehaus.groovy.ast.ClassHelper.isPrimitiveType; |
87 | 85 | import static org.codehaus.groovy.ast.ClassHelper.make; |
88 | 86 | import static org.codehaus.groovy.ast.tools.GeneralUtils.args; |
| 87 | +import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX; |
89 | 88 | import static org.codehaus.groovy.ast.tools.GeneralUtils.callX; |
| 89 | +import static org.codehaus.groovy.ast.tools.GeneralUtils.classX; |
90 | 90 | import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; |
91 | 91 | import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements; |
92 | 92 | import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX; |
@@ -378,39 +378,38 @@ private boolean makeGetPrivateFieldWithBridgeMethod(final Expression receiver, f |
378 | 378 | if (field == null && implicitThis && outerClass != null && !receiverType.isStaticClass()) { |
379 | 379 | Expression pexp; |
380 | 380 | if (controller.isInClosure()) { |
381 | | - MethodCallExpression mce = new MethodCallExpression( |
382 | | - new VariableExpression("this"), |
383 | | - "getThisObject", |
384 | | - ArgumentListExpression.EMPTY_ARGUMENTS |
385 | | - ); |
386 | | - mce.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, controller.getOutermostClass()); |
387 | | - mce.setImplicitThis(true); |
388 | | - mce.setMethodTarget(CLOSURE_GETTHISOBJECT_METHOD); |
389 | | - pexp = new CastExpression(controller.getOutermostClass(),mce); |
| 381 | + MethodCallExpression call = callThisX("getThisObject"); |
| 382 | + call.setImplicitThis(true); |
| 383 | + call.setMethodTarget(CLOSURE_GETTHISOBJECT_METHOD); |
| 384 | + call.setNodeMetaData(StaticTypesMarker.INFERRED_TYPE, controller.getOutermostClass()); |
| 385 | + pexp = new CastExpression(controller.getOutermostClass(), call); |
390 | 386 | } else { |
391 | | - pexp = new PropertyExpression( |
392 | | - new ClassExpression(outerClass), |
393 | | - "this" |
394 | | - ); |
395 | | - ((PropertyExpression)pexp).setImplicitThis(true); |
| 387 | + pexp = new PropertyExpression(classX(outerClass), "this"); |
396 | 388 | } |
397 | 389 | pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, outerClass); |
398 | 390 | pexp.setSourcePosition(receiver); |
399 | 391 | return makeGetPrivateFieldWithBridgeMethod(pexp, outerClass, fieldName, safe, true); |
400 | 392 | } |
401 | 393 | ClassNode classNode = controller.getClassNode(); |
402 | | - if (field != null && Modifier.isPrivate(field.getModifiers()) && !receiverType.equals(classNode) |
403 | | - && (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType, classNode) || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode,receiverType))) { |
| 394 | + if (field != null && field.isPrivate() && !receiverType.equals(classNode) |
| 395 | + && (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType, classNode) |
| 396 | + || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode, receiverType))) { |
404 | 397 | Map<String, MethodNode> accessors = receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_ACCESSORS); |
405 | | - if (accessors!=null) { |
| 398 | + if (accessors != null) { |
406 | 399 | MethodNode methodNode = accessors.get(fieldName); |
407 | | - if (methodNode!=null) { |
408 | | - MethodCallExpression mce = new MethodCallExpression(receiver, methodNode.getName(), |
409 | | - new ArgumentListExpression(field.isStatic() ? new ConstantExpression(null) : receiver)); |
410 | | - mce.setMethodTarget(methodNode); |
411 | | - mce.setSafe(safe); |
412 | | - mce.setImplicitThis(implicitThis); |
413 | | - mce.visit(controller.getAcg()); |
| 400 | + if (methodNode != null) { |
| 401 | + Expression thisObject; |
| 402 | + if (field.isStatic()) { |
| 403 | + thisObject = nullX(); |
| 404 | + } else if (!ExpressionUtils.isThisExpression(receiver)) { |
| 405 | + thisObject = receiver; |
| 406 | + } else { // GROOVY-7304, GROOVY-9771, GROOVY-9872, et al. |
| 407 | + thisObject = new PropertyExpression(classX(receiverType), "this"); |
| 408 | + } |
| 409 | + |
| 410 | + MethodCallExpression methodCall = callX(classX(receiverType), methodNode.getName(), thisObject); |
| 411 | + methodCall.setMethodTarget(methodNode); |
| 412 | + methodCall.visit(controller.getAcg()); |
414 | 413 | return true; |
415 | 414 | } |
416 | 415 | } |
@@ -583,7 +582,7 @@ boolean makeGetField(final Expression receiver, final ClassNode receiverType, fi |
583 | 582 | } |
584 | 583 | mv.visitFieldInsn(GETFIELD, BytecodeHelper.getClassInternalName(field.getOwner()), fieldName, BytecodeHelper.getTypeDescription(replacementType)); |
585 | 584 | if (safe) { |
586 | | - if (ClassHelper.isPrimitiveType(replacementType)) { |
| 585 | + if (isPrimitiveType(replacementType)) { |
587 | 586 | operandStack.replace(replacementType); |
588 | 587 | operandStack.box(); |
589 | 588 | replacementType = operandStack.getTopOperand(); |
|
0 commit comments