private boolean storeProperty(PropertyNode propertyNode, PropertyExpression expressionToStoreOn, ClassNode receiver, ClassCodeVisitorSupport visitor, String delegationData) { if (propertyNode == null) return false; if (visitor != null) visitor.visitProperty(propertyNode); storeWithResolve(propertyNode.getOriginType(), receiver, propertyNode.getDeclaringClass(), propertyNode.isStatic(), expressionToStoreOn); if (delegationData != null) { expressionToStoreOn.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); } return true; }
/** * Instructs the type checker that a property access is dynamic. * Calling this method automatically sets the handled flag to true. * @param pexp the property or attribute expression * @param returnType the type of the property */ public void makeDynamic(PropertyExpression pexp, ClassNode returnType) { context.getEnclosingMethod().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); pexp.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); storeType(pexp, returnType); setHandled(true); if (debug) { LOG.info("Turning '"+pexp.getText()+"' into a dynamic property access of type "+returnType.toString(false)); } }
private boolean storeField(FieldNode field, boolean returnTrueIfFieldExists, PropertyExpression expressionToStoreOn, ClassNode receiver, ClassCodeVisitorSupport visitor, String delegationData, boolean lhsOfAssignment) { if (field == null || !returnTrueIfFieldExists) return false; if (visitor != null) visitor.visitField(field); storeWithResolve(field.getOriginType(), receiver, field.getDeclaringClass(), field.isStatic(), expressionToStoreOn); checkOrMarkPrivateAccess(expressionToStoreOn, field, lhsOfAssignment); if (delegationData != null) { expressionToStoreOn.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); } return true; }
pexp.setImplicitThis(true); for (int i=1; i<propertyPath.length;i++) { pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, CLOSURE_TYPE); pexp = new PropertyExpression(pexp, propertyPath[i]); pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, implicitReceiver); origin.removeNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER); if (origin instanceof PropertyExpression) { rewritten.setImplicitThis(false); rewritten.visit(controller.getAcg()); rewritten.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, origin.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE)); return true;
private static Expression tryTransformPrivateFieldAccess(VariableExpression expr) { FieldNode field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS); if (field == null) { field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_MUTATION); } if (field != null) { // access to a private field from a section of code that normally doesn't have access to it, like a // closure or an inner class VariableExpression receiver = new VariableExpression("this"); PropertyExpression pexp = new PropertyExpression( receiver, expr.getName() ); pexp.setImplicitThis(true); pexp.getProperty().setSourcePosition(expr); // put the receiver inferred type so that the class writer knows that it will have to call a bridge method receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getDeclaringClass()); // add inferred type information pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getOriginType()); return pexp; } return null; } }
String delegationData = receiver.getData(); if (delegationData != null) pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); return true; pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); pexp.putNodeMetaData(StaticTypesMarker.READONLY_PROPERTY, true); if (delegationData != null) pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); return true;