public void setCompilePhase(CompilePhase phase) {
    if (phase.getPhaseNumber() < CompilePhase.CONVERSION.getPhaseNumber())
      throw new IllegalArgumentException("AST is only available from phase CONVERSION onwards");
    compilePhase = phase;
  }
Sets the compile phase up to which compilation should proceed. Defaults to
CompilePhase.CONVERSION (the phase in which the AST is first constructed).

@param phase the compile phase up to which compilation should proceed
@throws IllegalArgumentException if a compile phase before
CompilePhase.CONVERSION is specified
spock-core/src/main/java/org/spockframework/util/inspector/AstInspector.java