private int extractVariableNumber(Expression expr){
    if (!(expr instanceof MethodCallExpression)) return -1;
    MethodCallExpression methodExpr = (MethodCallExpression) expr;
    Expression targetExpr = methodExpr.getObjectExpression();
    if (!(targetExpr instanceof VariableExpression)) return -1;
    VariableExpression var = (VariableExpression)targetExpr;
    if (!valueRecorderName.equals(var.getName())) return -1;
    if(!ValueRecorder.RECORD.equals(methodExpr.getMethodAsString())) return -1;
    Expression startRecordingEpr = ((ArgumentListExpression) methodExpr.getArguments()).getExpression(0);
    if (!(startRecordingEpr instanceof MethodCallExpression)) return -1;
    MethodCallExpression startRecording = (MethodCallExpression) startRecordingEpr;
    if (!ValueRecorder.START_RECORDING_VALUE.equals(startRecording.getMethodAsString())) return -1;
    final Expression variableNumExpression = ((ArgumentListExpression) startRecording.getArguments()).getExpression(0);
    if (! (variableNumExpression instanceof ConstantExpression)) return -1;
    return (Integer)((ConstantExpression)variableNumExpression).getValue();
  }
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