package uk.co.bristlecone.voltdb.wrapgen.builder;

import java.util.function.Function;

import javax.lang.model.element.Modifier;

import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;

import uk.co.bristlecone.voltdb.wrapgen.builder.impl.RunnerBuilderServices;
import uk.co.bristlecone.voltdb.wrapgen.runner.VoltRunner;

/**
 * Allows Java class definitions for VoltRunner's to be easily built from ProcData and supporting metadata
 * 
 * @author christo
 */
public class RunnerBuilder {
  private RunnerBuilderServices rbs;

  public RunnerBuilder(ProcData procData, Function<String, String> packageNamer, Function<String, String> runnerNamer) {
    rbs = new RunnerBuilderServices(procData, packageNamer, runnerNamer);
  }

  public VoltRunnerJavaSource build() {
    TypeSpec runnerClassBuilder = TypeSpec.classBuilder(rbs.runnerName())
        .addModifiers(Modifier.PUBLIC)
        .addAnnotation(VoltRunner.class)
        .addJavadoc(rbs.runnerJavaDoc())
        .build();
    JavaFile fileBuilder = JavaFile.builder(rbs.runnerPackageName(), runnerClassBuilder)
        .build();
    return new VoltRunnerJavaSource(fileBuilder.toString());
  }
}

@@ -60,112 +60,454 @@
 ava.
-util.function.Function;%0A%0Aimport javax.lang.model.element.Modifier;%0A%0Aimport com.squareup.javapoet.JavaFil
+io.IOException;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.function.Function;%0A%0Aimport javax.lang.model.element.Modifier;%0A%0Aimport org.voltdb.client.ClientResponse;%0Aimport org.voltdb.client.NoConnectionsException;%0Aimport org.voltdb.client.ProcedureCallback;%0A%0Aimport com.squareup.javapoet.JavaFile;%0Aimport com.squareup.javapoet.MethodSpec;%0Aimport com.squareup.javapoet.ParameterizedTypeName;%0Aimport com.squareup.javapoet.TypeNam
 e;%0Ai
@@ -679,16 +679,76 @@
 tRunner;
+%0Aimport uk.co.bristlecone.voltdb.wrapgen.runner.WrapgenUtil;
 %0A%0A/**%0A *
@@ -854,17 +854,16 @@
 adata%0A *
- 
 %0A * @aut
@@ -917,16 +917,22 @@
 private 
+final 
 RunnerBu
@@ -974,16 +974,22 @@
 Builder(
+final 
 ProcData
@@ -998,16 +998,22 @@
 rocData,
+ final
  Functio
@@ -1043,16 +1043,28 @@
 geNamer,
+%0A      final
  Functio
@@ -1219,16 +1219,881 @@
 ) %7B%0A    
+final TypeName runnerRunReturnType = ParameterizedTypeName.get(CompletableFuture.class, ClientResponse.class);%0A    final String callProcedureParamsAsVariableList = String.format(%22handler, %5C%22%25s%5C%22, %25s%22, rbs.procName(),%0A        rbs.runMethodParamsAsVariableList());%0A    final MethodSpec runMethod = MethodSpec.methodBuilder(%22run%22)%0A        .addParameters(rbs.runMethodParamsAsParameterSpecs())%0A        .addException(NoConnectionsException.class)%0A        .addException(IOException.class)%0A        .returns(runnerRunReturnType)%0A        .addStatement(%22$T result = new $T()%22, runnerRunReturnType, runnerRunReturnType)%0A        .addStatement(%22$T handler = $T.getHandler(result)%22, ProcedureCallback.class, WrapgenUtil.class)%0A        .addStatement(%22client.callProcedure($L)%22, callProcedureParamsAsVariableList)%0A        .addStatement(%22return result%22)%0A        .build();%0A    final 
 TypeSpec
@@ -2271,24 +2271,98 @@
 rJavaDoc())%0A
+        .addMethod(runMethod)%0A        // .addMethod(runWithTimeoutMethod)%0A
         .bui
@@ -2371,16 +2371,22 @@
 ();%0A    
+final 
 JavaFile

Implement RunnerBuilder-generation of runner with run() method