Example usage for com.google.gwt.user.rebind SourceWriter print

List of usage examples for com.google.gwt.user.rebind SourceWriter print

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind SourceWriter print.

Prototype

void print(String s);

Source Link

Usage

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void saveMethodReturnsLocation(GeneratorInfo info, SourceWriter writer, JMethod method)
        throws UnableToCompleteException {

    String callbackParam = info.asyncCallbackParam.getName();
    String resourceParam = info.resourceParam.getName();
    String methodName = info.httpMethod.toString();

    // RequestBuilder request = new RequestBuilder(RequestBuilder.POST, getResourceURL());
    writer.println();/*w ww. j  a  v  a2s  . com*/
    writer.indent();
    writer.println("RequestBuilder request = new RequestBuilder(RequestBuilder." + methodName
            + ", getResourceURL());");

    // request.setHeader("Content-Type", "application/vnd.example.v1.person");

    String consumes = info.consumes(method);
    if (consumes != null) {
        writer.print("request.setHeader(\"Content-Type\", \"");
        writer.print(consumes);
        writer.println("\");");
    }

    String produces = info.produces(method);
    if (produces != null) {
        writer.print("request.setHeader(\"Accept\", \"");
        writer.print(produces);
        writer.println("\");");
    }

    // JSONObject json = new JSONObject(person);
    // String payload = json.toString();
    writer.println();
    writer.print("JSONObject json = new JSONObject(");
    writer.print(resourceParam);
    writer.println(");");
    writer.println("String payload = json.toString();");

    //    try {
    //     request.sendRequest(payload, new RequestCallback() {
    writer.println();
    writer.println("try {");
    writer.indent();
    writer.println("request.sendRequest(payload, new RequestCallback() {");
    writer.indent();

    //    @Override
    //    public void onResponseReceived(Request request, Response response) {
    //      
    //      if (
    //        response.getStatusCode() != Response.SC_CREATED &&
    //        response.getStatusCode() != Response.SC_OK
    //      ) {
    //        onError(request, new ResourceAccessException(response));
    //        return;
    //      }
    //      
    //      String location = response.getHeader("Location");
    //      callback.onSuccess(location);
    //      
    //    }
    writer.println();
    writer.println("@Override");
    writer.println("public void onResponseReceived(Request request, Response response) {");
    writer.indent();
    writer.println("if (");
    writer.println("  response.getStatusCode() != Response.SC_CREATED &&");
    writer.println("  response.getStatusCode() != Response.SC_OK");
    writer.println(") {");
    writer.println("  onError(request, new ResourceAccessException(response));");
    writer.println("  return;");
    writer.println("}");
    writer.println();
    writer.println("String location = response.getHeader(\"Location\");");
    writer.print(callbackParam);
    writer.println(".onSuccess(location);");
    writer.outdent();
    writer.println("}");

    //    @Override
    //    public void onError(Request request, Throwable e) {
    //      callback.onFailure(e);
    //    }
    //  });
    writer.println();
    writer.println("@Override");
    writer.println("public void onError(Request request, Throwable e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();
    writer.println("});");
    writer.outdent();

    //  } catch (RequestException e) {
    //    callback.onFailure(e);
    //  }
    writer.println();
    writer.println("} catch (RequestException e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();

}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void saveMethodReturnsEntity(GeneratorInfo info, SourceWriter writer, JMethod method)
        throws UnableToCompleteException {

    String callbackParam = info.asyncCallbackParam.getName();
    String resourceParam = info.resourceParam.getName();
    String callbackType = info.asyncType.getSimpleSourceName();
    String methodName = info.httpMethod.toString();

    // RequestBuilder request = new RequestBuilder(RequestBuilder.POST, getResourceURL());
    writer.println();/*from  w  w w  .  j a  va 2 s.c  om*/
    writer.indent();
    writer.println("RequestBuilder request = new RequestBuilder(RequestBuilder." + methodName
            + ", getResourceURL());");

    // request.setHeader("Content-Type", "application/vnd.example.v1.person");
    String consumes = info.consumes(method);
    if (consumes != null) {
        writer.print("request.setHeader(\"Content-Type\", \"");
        writer.print(consumes);
        writer.println("\");");
    }

    String produces = info.produces(method);
    if (produces != null) {
        writer.print("request.setHeader(\"Accept\", \"");
        writer.print(produces);
        writer.println("\");");
    }

    // JSONObject json = new JSONObject(person);
    // String payload = json.toString();
    writer.println();
    writer.print("JSONObject json = new JSONObject(");
    writer.print(resourceParam);
    writer.println(");");
    writer.println("String payload = json.toString();");

    //    try {
    //     request.sendRequest(payload, new RequestCallback() {
    writer.println();
    writer.println("try {");
    writer.indent();
    writer.println("request.sendRequest(payload, new RequestCallback() {");
    writer.indent();

    //    @Override
    //    public void onResponseReceived(Request request, Response response) {
    //      
    //      if (
    //        response.getStatusCode() != Response.SC_CREATED &&
    //        response.getStatusCode() != Response.SC_OK
    //      ) {
    //        onError(request, new ResourceAccessException(response));
    //        return;
    //      }
    //      JSONValue value = JSONParser.parseStrict(response.getText());
    //      PersonRef entity = value.isObject().getJavaScriptObject().cast();
    //      callback.onSuccess(entity);
    //    }
    writer.println();
    writer.println("@Override");
    writer.println("public void onResponseReceived(Request request, Response response) {");
    writer.indent();
    writer.println("if (");
    writer.println("  response.getStatusCode() != Response.SC_CREATED &&");
    writer.println("  response.getStatusCode() != Response.SC_OK");
    writer.println(") {");
    writer.println("  onError(request, new ResourceAccessException(response));");
    writer.println("  return;");
    writer.println("}");
    writer.println();
    writer.println("JSONValue value = JSONParser.parseStrict(response.getText());");
    writer.print(callbackType);
    writer.println(" entity = value.isObject().getJavaScriptObject().cast();");
    writer.print(callbackParam);
    writer.println(".onSuccess(entity);");
    writer.outdent();
    writer.println("}");

    //    @Override
    //    public void onError(Request request, Throwable e) {
    //      callback.onFailure(e);
    //    }
    //  });
    writer.println();
    writer.println("@Override");
    writer.println("public void onError(Request request, Throwable e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();
    writer.println("});");
    writer.outdent();

    //  } catch (RequestException e) {
    //    callback.onFailure(e);
    //  }
    writer.println();
    writer.println("} catch (RequestException e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();

}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void saveMethodReturnsVoid(GeneratorInfo info, SourceWriter writer, JMethod method)
        throws UnableToCompleteException {

    String callbackParam = info.asyncCallbackParam.getName();
    String resourceParam = info.resourceParam.getName();
    String methodName = info.httpMethod.toString();

    // RequestBuilder request = new RequestBuilder(RequestBuilder.POST, getResourceURL());
    writer.println();// www . j a va  2  s  .c  o m
    writer.indent();
    writer.println("RequestBuilder request = new RequestBuilder(RequestBuilder." + methodName
            + ", getResourceURL());");
    writer.indent();
    // request.setHeader("Content-Type", "application/vnd.example.v1.person");
    String consumes = info.consumes(method);
    if (consumes != null) {
        writer.print("request.setHeader(\"Content-Type\", \"");
        writer.print(consumes);
        writer.println("\");");
    }

    String produces = info.produces(method);
    if (produces != null) {
        writer.print("request.setHeader(\"Accept\", \"");
        writer.print(produces);
        writer.println("\");");
    }

    // JSONObject json = new JSONObject(person);
    // String payload = json.toString();
    writer.println();
    writer.print("JSONObject json = new JSONObject(");
    writer.print(resourceParam);
    writer.println(");");
    writer.println("String payload = json.toString();");

    //    try {
    //     request.sendRequest(payload, new RequestCallback() {
    writer.println();
    writer.println("try {");
    writer.indent();
    writer.println("request.sendRequest(payload, new RequestCallback() {");

    //    @Override
    //    public void onResponseReceived(Request request, Response response) {
    //      
    //      if (
    //        response.getStatusCode() != Response.SC_CREATED &&
    //        response.getStatusCode() != Response.SC_OK
    //      ) {
    //        onError(request, new ResourceAccessException(response));
    //        return;
    //      }
    //      callback.onSuccess(null);
    //    }
    writer.println();
    writer.println("@Override");
    writer.println("public void onResponseReceived(Request request, Response response) {");
    writer.indent();
    writer.println("if (");
    writer.println("  response.getStatusCode() != Response.SC_CREATED &&");
    writer.println("  response.getStatusCode() != Response.SC_OK");
    writer.println(") {");
    writer.println("  onError(request, new ResourceAccessException(response));");
    writer.println("  return;");
    writer.println("}");
    writer.println();
    writer.print(callbackParam);
    writer.println(".onSuccess(null);");
    writer.outdent();
    writer.println("}");

    //    @Override
    //    public void onError(Request request, Throwable e) {
    //      callback.onFailure(e);
    //    }
    //  });
    writer.println();
    writer.println("@Override");
    writer.println("public void onError(Request request, Throwable e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();
    writer.println("});");
    writer.outdent();

    //  } catch (RequestException e) {
    //    callback.onFailure(e);
    //  }
    writer.println();
    writer.println("} catch (RequestException e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();

}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void buildGetMethod(GeneratorInfo info, SourceWriter writer, JMethod method) {

    if (info.asyncType == null) {
        info.logger.log(TreeLogger.ERROR,
                "GET method must have a single parameter of type AsyncCallback<T> where T is the resource type.");
        return;//ww  w  . ja  v a2 s.  c  o m
    }

    String callbackParam = info.asyncCallbackParam.getName();

    String resourceSimpleName = info.asyncType.getSimpleSourceName();
    String contentType = info.produces(method);

    writer.indent();
    // RequestBuilder request = new RequestBuilder(RequestBuilder.GET, getResourceURL());
    writer.println("RequestBuilder request = new RequestBuilder(RequestBuilder.GET, getResourceURL());");

    // request.setHeader("Content-Type", "...");
    if (contentType != null) {
        writer.print("request.setHeader(\"Accept\", \"");
        writer.print(contentType);
        writer.println("\");");
    }

    /*
    request.setCallback(new RequestCallback() {
              
      @Override
      public void onResponseReceived(Request request, Response response) {
        if (response.getStatusCode() != Response.SC_OK) {
          onError(request, new ResourceAccessException(response));
          return;
        }
        JSONValue value = JSONParser.parseStrict(response.getText());
        Person entity = toPerson(value.isObject().getJavaScriptObject());
        callback.onSuccess(entity);
      }      
    */

    writer.println("request.setCallback(new RequestCallback() {");
    writer.indent();
    writer.println();
    writer.println("@Override");
    writer.println("public void onResponseReceived(Request request, Response response) {");
    writer.indent();
    writer.println("if (response.getStatusCode() != Response.SC_OK) {");
    writer.indent();
    writer.println("onError(request, new ResourceAccessException(response));");
    writer.println("return;");
    writer.outdent();
    writer.println("}");
    writer.println("JSONValue value = JSONParser.parseStrict(response.getText());");
    writer.print(resourceSimpleName);
    writer.print(" entity = ");
    writer.println("value.isObject().getJavaScriptObject().cast();");
    writer.print(callbackParam);
    writer.println(".onSuccess(entity);");

    writer.outdent();
    writer.println("}");

    /*/
      @Override
      public void onError(Request request, Throwable exception) {
        callback.onFailure(exception);
      }
    });
     */
    writer.println();
    writer.println("@Override");
    writer.println("public void onError(Request request, Throwable exception) {");
    writer.indent();
    writer.print(callbackParam);
    writer.println(".onFailure(exception);");
    writer.outdent();
    writer.println("}");
    writer.outdent();
    writer.println("});");

    /*
    try {
      request.send();
    } catch (RequestException e) {
      callback.onFailure(e);
    }
     */
    writer.println("try {");
    writer.println("  request.send();");
    writer.println("} catch (RequestException e) {");
    writer.print("  ");
    writer.print(callbackParam);
    writer.println(".onFailure(e);");
    writer.println("}");
    writer.outdent();

}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void addParameters(GeneratorInfo info, SourceWriter writer, JParameter[] parameters)
        throws UnableToCompleteException {
    info.asyncCallbackParam = null;/*from  w ww. jav  a  2s .  co  m*/
    info.asyncType = null;
    info.resourceParam = null;
    info.resourceType = null;

    for (int i = 0; i < parameters.length; i++) {
        if (i > 0) {
            writer.print(", ");
        }
        JParameter param = parameters[i];
        String paramType = param.getType().getSimpleSourceName();
        String paramName = param.getName();

        JParameterizedType generic = param.getType().isParameterized();

        if (AsyncCallback.class.getName().equals(param.getType().getQualifiedSourceName())) {
            info.asyncCallbackParam = param;
            info.asyncType = generic.getTypeArgs()[0];
            writer.print("final ");
        } else {
            info.resourceParam = param;
            info.resourceType = param.getType().isClassOrInterface();
        }
        writer.print(paramType);
        if (generic != null) {
            addParameterizedType(info, writer, generic);
        }
        writer.print(" ");
        writer.print(paramName);
    }

}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void addParameterizedType(GeneratorInfo info, SourceWriter writer, JParameterizedType generic) {

    JClassType param[] = generic.getTypeArgs();
    writer.print("<");
    for (int i = 0; i < param.length; i++) {
        if (i > 0) {
            writer.print(", ");
        }/*from   w ww  .  j  a  v a2  s.c o m*/
        writer.print(param[i].getSimpleSourceName());
    }

    writer.print(">");

}

From source file:org.vectomatic.dev.svg.impl.gen.ExternalSVGResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    String name = method.getName();

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + ExternalSVGResourcePrototype.class.getName() + "(");
    sw.indent();// ww w  .  j  ava 2  s  .  c  o  m
    sw.println('"' + name + "\",");
    // These are field names
    sw.println(externalSVGUrlIdent + ", " + externalSVGCacheIdent + ", ");
    sw.println(offsets.get(method.getName()).toString());
    sw.outdent();
    sw.print(")");

    return sw.toString();
}

From source file:org.webinit.gwt.rebind.InterfaceProxyGenerator.java

License:Apache License

private void writeMethod(TreeLogger log, JMethod method, String proxyObjectName, SourceWriter writer) {
    StringBuffer buf = new StringBuffer();
    buf.append("public ");
    // return type
    JType returnType = method.getReturnType();
    buf.append(returnType.getQualifiedSourceName() + " ");
    // name//from   ww  w  . jav  a  2 s . c o  m
    buf.append(method.getName() + "(");

    // arguments
    JParameter[] args = method.getParameters();
    // set the first argument
    if (args.length > 0) {
        buf.append(args[0].getType().getQualifiedSourceName() + " arg0");
    }
    // following arguments if available
    for (int index = 1; index < args.length; index++) {
        JParameter arg = args[index];
        buf.append(", " + arg.getType().getQualifiedSourceName() + " arg" + index);
    }
    // parameter end
    buf.append(") ");

    JType[] thrs = method.getThrows();
    // set the first throw
    if (thrs.length > 0) {
        buf.append("throws " + thrs[0].getQualifiedSourceName());
    }
    // following throws
    for (int index = 1; index < thrs.length; index++) {
        JType thr = thrs[index];
        buf.append(", " + thr.getQualifiedSourceName());
    }
    // throws end
    buf.append(" {\n");

    // main statement
    if (returnType.isPrimitive() != JPrimitiveType.VOID)
        buf.append("return ");
    buf.append(proxyObjectName + "." + method.getName() + "(");
    if (args.length > 0)
        buf.append("arg0");
    for (int index = 1; index < args.length; index++)
        buf.append(", arg" + index);
    buf.append(");\n");
    buf.append("}\n");

    // write to writer
    writer.print(buf.toString());
}

From source file:sheath.rebind.SheathGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    JClassType toGenerate = oracle.findType(typeName).isInterface();
    if (toGenerate == null) {
        logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
        throw new UnableToCompleteException();
    }//from  w  w w  .  j a v  a  2s  .c  o  m

    JClassType sheathType = oracle.findType(Sheath.class.getCanonicalName());
    if (!toGenerate.isAssignableTo(sheathType)) {
        logger.log(TreeLogger.ERROR, typeName + " is not assignable to " + Sheath.class.getCanonicalName());
        throw new UnableToCompleteException();
    }
    if (toGenerate.equals(sheathType)) {
        logger.log(TreeLogger.ERROR,
                "You must declare an interface that extends " + Sheath.class.getCanonicalName());
        throw new UnableToCompleteException();
    }

    // TODO: really generate incrementally!

    Class<?>[] moduleClasses = collectAllModules(logger, toGenerate);

    Map<String, String> injectableTypes = new LinkedHashMap<String, String>();
    Set<Class<?>> staticInjections = new LinkedHashSet<Class<?>>();
    for (Class<?> module : moduleClasses) {
        Module annotation = module.getAnnotation(Module.class);
        String moduleName = module.getCanonicalName();
        for (Class<?> key : annotation.injects()) {
            injectableTypes.put(key.getName(), moduleName);
        }
        for (Class<?> c : annotation.staticInjections()) {
            staticInjections.add(c);
        }
    }

    String packageName = toGenerate.getPackage().getName();
    String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl";
    PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName);
    if (pw == null) {
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + simpleSourceName);
    }

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
    factory.setSuperclass(AbstractSheath.class.getCanonicalName());
    factory.addImplementedInterface(typeName);
    SourceWriter sw = factory.createSourceWriter(context, pw);

    // Linker
    sw.println("private static class Plugin extends AbstractSheathPlugin {");
    sw.indent();
    sw.println("@java.lang.Override");
    sw.println(
            "public native %1$s<?> getAtInjectBinding(%2$s key, %2$s className, boolean mustBeInjectable) /*-{",
            Binding.class.getCanonicalName(), String.class.getCanonicalName());
    sw.indent();
    sw.println("switch (className) {");
    LinkedHashMap<String, String> factoryMethodsToGenerate = new LinkedHashMap<String, String>();
    for (JClassType type : oracle.getTypes()) {
        // XXX: workaround for http://code.google.com/p/google-web-toolkit/issues/detail?id=6799
        // We really should use type.getName().endsWith("$$InjectAdapter") but GWT makes a JClassType
        // with name "InjectAdapter", thinking it's a nested class, and we lose the part before the
        // dollar. So in the mean time, look for the InjectAdapter in the classpath FOR EACH CLASS,
        // and we additionally generate a non-JSNI class to instantiate it, so that processing of the
        // class name is done by JDT rather than GWT's TypeOracle.
        String adapterName = type.getQualifiedSourceName() + "$$InjectAdapter";
        boolean found;
        try {
            Class.forName(adapterName, false, Thread.currentThread().getContextClassLoader());
            found = true;
        } catch (Throwable t) {
            found = false;
        }
        if (found /*&& type.isAssignableTo(oracle.findType(Binding.class.getCanonicalName()))*/) {
            String name = type.getQualifiedSourceName();
            String factoryName = "create_" + name.replace('.', '_') + "_InjectAdapter";
            factoryMethodsToGenerate.put(adapterName, factoryName);
            sw.println("case '%s': return this.@%s.Plugin::%s()();", name, factory.getCreatedClassName(),
                    factoryName);
        }
    }
    sw.println("default: return null;");
    sw.println("}");
    sw.outdent();
    sw.println("}-*/;");
    for (Map.Entry<String, String> factoryMethodToGenerate : factoryMethodsToGenerate.entrySet()) {
        sw.println();
        sw.println("private %s %s() {", factoryMethodToGenerate.getKey(), factoryMethodToGenerate.getValue());
        sw.indentln("return new %s();", factoryMethodToGenerate.getKey());
        sw.println("}");
    }
    sw.println();
    sw.println("@java.lang.Override");
    sw.println("public %s[] createStaticInjections() {", StaticInjection.class.getCanonicalName());
    sw.indent();
    sw.println("return new %s[] {", StaticInjection.class.getCanonicalName());
    sw.indent();
    for (Class<?> staticInjection : staticInjections) {
        sw.println("new %s$$StaticInjection(),", staticInjection.getName());
    }
    sw.outdent();
    sw.println("};");
    sw.outdent();
    sw.println("}");
    sw.outdent();
    sw.print("}");

    // Constructor
    sw.println();
    sw.println("public %s() {", simpleSourceName);
    sw.indent();
    sw.println("super(new Plugin(), ");
    sw.println("new %s<?>[] {", ModuleAdapter.class.getCanonicalName());
    sw.indent();
    for (Class<?> module : moduleClasses) {
        sw.println("new %s$$ModuleAdapter(),", module.getName());
    }
    sw.outdent();
    sw.println("});");
    sw.outdent();
    sw.outdent();
    sw.println("}");

    for (JMethod method : toGenerate.getOverridableMethods()) {
        // TODO: check arguments (number, injectable types)
        if (method.getParameterTypes().length != 1) {
            // could be injectStatics()
            continue;
        }
        JType toInject = method.getParameterTypes()[0];
        sw.println("@java.lang.Override");
        sw.println("public %s %s(%s instance) {", method.getReturnType().getParameterizedQualifiedSourceName(),
                method.getName(), toInject.getParameterizedQualifiedSourceName());
        sw.indent();
        sw.println("doInject(instance, \"members/%s\", %s.class);",
                toInject.getParameterizedQualifiedSourceName(),
                injectableTypes.get(toInject.getQualifiedBinaryName()));
        if (!JPrimitiveType.VOID.equals(method.getReturnType())) {
            sw.println("return arg;");
        }
        sw.outdent();
        sw.println("}");
    }

    sw.commit(logger);

    return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + simpleSourceName);
}

From source file:xapi.dev.generators.AbstractInjectionGenerator.java

License:Open Source License

public static InjectionCallbackArtifact ensureAsyncInjected(TreeLogger logger, String packageName,
        String className, String outputClass, GeneratorContext ctx) throws UnableToCompleteException {

    GwtInjectionMap gwtInjectionMap = getInjectionMap(logger, ctx);
    InjectionCallbackArtifact artifact = gwtInjectionMap.getOrCreateArtifact(ctx, packageName, className);
    if (artifact.isTargetUnbound()) {
        artifact.bindTo(outputClass);/*from   w  w w  .ja  v a2s .com*/
        ensureProviderClass(logger, packageName, artifact.getSimpleName(), artifact.getCanonicalName(),
                artifact.getBoundTarget(), ctx);
        logger = logger.branch(Type.TRACE,
                "Creating asynchronous callback for " + artifact.getCanonicalName() + " -> " + outputClass);
        String generatedName = InjectionUtils.generatedAsyncProviderName(artifact.getGeneratedName());
        String implPackage = artifact.getImplementationPackage();
        PrintWriter printWriter = ctx.tryCreate(logger, implPackage, generatedName);
        if (printWriter == null) {
            logger.log(Type.WARN,
                    "Could not create the source writer for " + implPackage + "." + generatedName);
            return artifact;
        }
        artifact.addCallback(implPackage + "." + generatedName + ".Deproxy");
        ctx.commitArtifact(logger, artifact);

        ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(implPackage,
                generatedName);
        composer.setPrivacy("public final");

        composer.addImport(com.google.gwt.core.client.GWT.class.getName());
        composer.addImport(RunAsyncCallback.class.getName());
        composer.addImport(Fifo.class.getName());
        composer.addImport(JsFifo.class.getName());
        composer.addImport(AsyncProxy.class.getName());
        composer.addImport(ApplyMethod.class.getName());
        composer.addImport(ReceivesValue.class.getName());
        composer.addImport(ReceiverAdapter.class.getCanonicalName());
        composer.addImport(artifact.getCanonicalName());

        String simpleName = artifact.getSimpleName();
        SourceWriter sw = composer.createSourceWriter(ctx, printWriter);

        sw.println();
        sw.println("static final class Callbacks implements ApplyMethod{");
        sw.indent();
        sw.println("public void apply(Object ... args){");
        sw.println("}");
        sw.outdent();
        sw.println("}");
        sw.println();

        sw.println("static final class Deproxy implements ReceivesValue<" + simpleName + ">{");
        sw.indent();
        sw.println("public final void set(final " + simpleName + " value){");
        sw.indentln("getter = new ReceiverAdapter<" + simpleName + ">(value);");
        sw.println("}");
        sw.outdent();
        sw.println("}");
        sw.println();

        sw.println("private static final class Proxy implements ReceivesValue<ReceivesValue<" + simpleName
                + ">>{");
        sw.indent();
        sw.println("public final void set(final ReceivesValue<" + simpleName + "> receiver){");
        sw.indent();

        sw.print("GWT.runAsync(");
        sw.println(artifact.getCanonicalName() + ".class,new Request(receiver));");

        sw.outdent();
        sw.println("}");
        sw.outdent();
        sw.println("}");
        sw.println();

        sw.println("private static final class Request");
        sw.indent();
        sw.println("extends AsyncProxy<" + simpleName + "> ");
        sw.println("implements RunAsyncCallback{");

        DefermentWriter defer = new DefermentWriter(sw);
        defer.setStrategy(DefermentStrategy.NONE);

        sw.println("private static final Fifo<ReceivesValue<" + simpleName + ">> pending =");
        sw.indentln("JsFifo.newFifo();");
        sw.println();

        sw.println("protected Request(ReceivesValue<" + simpleName + "> receiver){");
        sw.indentln("accept(receiver);");
        sw.println("}");
        sw.println();

        sw.println("@Override");
        sw.println("protected final Fifo<ReceivesValue<" + simpleName + ">> pending(){");
        sw.indentln("return pending;");
        sw.println("}");
        sw.println();

        sw.println("protected final void dispatch(){");
        sw.indentln("go();");
        sw.println("}");
        sw.println();

        sw.println("public final void onSuccess(){");
        sw.indent();
        defer.printStart();

        sw.println("final " + simpleName + " value = ");
        sw.print(packageName + "." + InjectionUtils.generatedProviderName(simpleName));
        sw.println(".theProvider.get();");
        sw.println();

        sw.print("final ApplyMethod callbacks = GWT.create(");
        sw.print(packageName + ".impl." + generatedName + ".Callbacks.class");
        sw.println(");");
        sw.println("callbacks.apply(value);");
        sw.println();

        sw.println("apply(value);");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        defer.printFinish();
        sw.println("}");
        sw.println();

        sw.println("private static ReceivesValue<ReceivesValue<" + simpleName + ">> getter = new Proxy();");
        sw.println();

        sw.println("static void request(final ReceivesValue<" + simpleName + "> request){");
        sw.indentln("getter.set(request);");
        sw.println("}");
        sw.println();

        sw.println("static void go(){");
        sw.indentln("request(null);");
        sw.println("}");
        sw.println();

        sw.println("private " + generatedName + "(){}");

        sw.commit(logger);

    } else {
        assert artifact.getBoundTarget().equals(outputClass) : "The injection target "
                + artifact.getCanonicalName() + " was bound " + "to " + artifact.getBoundTarget()
                + ", but you tried to bind it again, " + "to a different class: " + outputClass;
    }
    return artifact;
}