private Expression record(Expression expr) {
    // replace expr with $spock_valueRecorder.record($spock_valueRecorder.startRecordingValue(recordCount++), <expr>)
    MethodCallExpression result = createDirectMethodCall(
      new VariableExpression(valueRecorderName),
      resources.getAstNodeCache().ValueRecorder_Record,
      new ArgumentListExpression(
        createDirectMethodCall(
          new VariableExpression(valueRecorderName),
          resources.getAstNodeCache().ValueRecorder_StartRecordingValue,
          new ArgumentListExpression(primitiveConstExpression(recordCount++))
        ),
        expr));

    // maintain type casts to preserve method disambiguation
    // for example when giving a casted null as argument
    if (expr instanceof CastExpression) {
      return new CastExpression(expr.getType(), result);
    } else {
      return result;
    }
  }
Rewrites explicit ("assert x > 3") and implicit ("x > 3") condition
statements. Replacing the original statement with the rewritten one is up
to clients.

@author Peter Niederwieser
spock-core/src/main/java/org/spockframework/compiler/ConditionRewriter.java