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

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

Introduction

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

Prototype

void println(String s);

Source Link

Usage

From source file:com.kk_electronic.gwt.rebind.RemoteServiceGenerator.java

License:Open Source License

private void generateClass(TreeLogger logger, GeneratorContext context)
        throws UnableToCompleteException, NotFoundException {
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    if (printWriter == null) {
        return;//from ww w.  j a va2  s  .c om
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);

    dispatcher = findTargetDispatcher(classType);

    composer.addImport(dispatcher.getCanonicalName());
    composer.addImport(Dispatcher.class.getCanonicalName());
    composer.addImport(AsyncCallback.class.getCanonicalName());
    composer.addImport(DelayingDispatcher.class.getCanonicalName());
    composer.addImport(Injection.class.getCanonicalName());
    composer.addImport(GWT.class.getCanonicalName());

    composer.addImplementedInterface(classType.getQualifiedSourceName());

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    writeConstructor(sourceWriter);
    writeMethods(sourceWriter);

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

    context.commit(logger, printWriter);
}

From source file:com.kk_electronic.gwt.rebind.RemoteServiceGenerator.java

License:Open Source License

private void writeConstructor(SourceWriter sw) {
    sw.println("protected " + Dispatcher.class.getSimpleName() + " dispatcher;");
    sw.println();//from w ww . jav  a 2  s.  c  om
    sw.println("public " + className + "() {");
    sw.indent();
    sw.println("final DelayingDispatcher d = new DelayingDispatcher();");
    sw.println("this.dispatcher = d;");
    sw.println("Injection.create(" + dispatcher.getSimpleName() + ".class, new AsyncCallback<"
            + dispatcher.getSimpleName() + ">() {");
    sw.indent();
    sw.println("@Override");
    sw.println("public void onFailure(Throwable caught) {");
    sw.println(
            "   GWT.log(\"Failed to load dispatcher for " + escape(classType.getSimpleSourceName()) + "\");");
    sw.println("}");
    sw.println("");
    sw.println("@Override");
    sw.println("public void onSuccess(" + dispatcher.getSimpleName() + " result) {");
    sw.println("   d.setDispatcher(result);");
    sw.println("   dispatcher = result;");
    sw.println("}");
    sw.outdent();
    sw.println("});");
    sw.outdent();
    sw.println("}");
}

From source file:com.kk_electronic.gwt.rebind.VersionGenerator.java

License:Open Source License

private void generateClass(TreeLogger logger, GeneratorContext context) {
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    if (printWriter == null) {
        return;//from   w  w w .j av a 2  s .  co m
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);

    composer.addImplementedInterface(Version.class.getCanonicalName());

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    writeGetSHA1(sourceWriter);
    writeGetTag(sourceWriter);

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

    context.commit(logger, printWriter);
}

From source file:com.kk_electronic.gwt.rebind.VersionGenerator.java

License:Open Source License

private void writeGetSHA1(SourceWriter sourceWriter) {
    sourceWriter.println("public String getSHA1(){");
    sourceWriter.indent();//from w  ww  .j a v  a  2s  .  c  om
    sourceWriter.print("return \"");
    String result = executeCommand("git rev-parse HEAD");
    if (result != null) {
        sourceWriter.print(escape(result));
    }
    sourceWriter.println("\";");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:com.kk_electronic.gwt.rebind.VersionGenerator.java

License:Open Source License

private void writeGetTag(SourceWriter sourceWriter) {
    sourceWriter.println("public String getTag(){");
    sourceWriter.indent();//from  w w  w  .j  av  a2  s  . co  m
    sourceWriter.print("return \"");
    String result = executeCommand("git describe --tags --always HEAD");
    if (result != null) {
        sourceWriter.print(escape(result));
    }
    sourceWriter.println("\";");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:com.mvp4g.rebind.Mvp4gRunAsyncGenerator.java

License:Apache License

void writeClass(SourceWriter sourceWriter, String callBackType) {
    sourceWriter.print("public void load(");
    sourceWriter.print(callBackType);//  w ww  . j a  v a2 s  . co m
    sourceWriter.println(" callback) {");
    sourceWriter.indent();
    sourceWriter.println("GWT.runAsync(callback);");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:com.ponysdk.ui.server.AddonListGenerator.java

License:Apache License

@Override
public String generate(final TreeLogger logger, final GeneratorContext context, final String typeName)
        throws UnableToCompleteException {

    final List<JClassType> ponyAddons = new ArrayList<JClassType>();

    final TypeOracle typeOracle = context.getTypeOracle();
    assert (typeOracle != null);

    JClassType classType = null;/*  ww  w . j  ava2 s  .co m*/
    try {
        classType = typeOracle.getType(typeName);
    } catch (final NotFoundException e) {
        e.printStackTrace();
        return null;
    }

    final SourceWriter src = getSourceWriter(classType, context, logger);
    if (src == null) {
        return typeName + "Generated";
    }

    final JClassType[] types = typeOracle.getTypes();

    System.out.println("Generating AddonListGenerator " + typeName);
    System.out.println("\tAnalysing " + types.length + " types ...");

    for (final JClassType jClassType : types) {
        if (jClassType.isAnnotationPresent(PonyAddOn.class)) {
            System.out.println("\tAdding Pony Addon " + jClassType.getParameterizedQualifiedSourceName());
            ponyAddons.add(jClassType);
        }
    }

    // Here you would retrieve the metadata based on typeName for this Screen
    src.println("public List<AddonFactory> getAddonFactoryList() {");
    src.indent();
    src.println("List<AddonFactory> addonList = new ArrayList();");
    for (final JClassType addon : ponyAddons) {
        src.println("addonList.add(new AddonFactory(){");
        src.indent();
        src.println("public PTAddon newAddon(){");
        src.indent();
        src.println("PTAddon addon =  new " + addon.getParameterizedQualifiedSourceName() + "();");
        src.println("return addon;");
        src.outdent();
        src.println("}");
        src.println();

        src.println("public String getSignature(){");
        src.indent();
        src.println("return \"" + addon.getParameterizedQualifiedSourceName() + "\";");
        src.outdent();
        src.println("}");
        src.println();
        src.outdent();
        src.println("});");
    }
    src.println("return addonList;");
    src.outdent();
    src.println("}");

    src.commit(logger);
    System.out.println("Generating for: " + typeName);
    return typeName + "Generated";
}

From source file:com.rhizospherejs.gwt.rebind.MappingWriter.java

License:Open Source License

private void writeModelBridgeFactoryMethod(SourceWriter sw) {
    sw.println("@Override");
    sw.println("public ModelBridge<%s> newModelBridge(%s jsoBuilder) {", modelClassName,
            BridgeCapabilities.JSO_BUILDER_CLASS);
    sw.indent();/*from w ww .jav a2  s .  co  m*/
    sw.println("return new %sModelBridge(jsoBuilder);", modelClassName);
    sw.outdent();
    sw.println("}");
}

From source file:com.rhizospherejs.gwt.rebind.MappingWriter.java

License:Open Source License

private void writeMetaModelFactoryInterfaceImpl(SourceWriter sw) {
    sw.println("@Override");
    sw.println("public MetaModelFactory newMetaModelFactory(%s attrBuilder) {",
            BridgeCapabilities.METAMODEL_ATTRIBUTE_BUILDER_CLASS);
    sw.indent();/*from  w  ww.  ja v a 2 s  .com*/
    sw.println("return new %sMetaModelFactory(attrBuilder);", modelClassName);
    sw.outdent();
    sw.println("}");
}

From source file:com.seanchenxi.resteasy.autobean.generator.RESTServiceGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {

    TypeOracle oracle = context.getTypeOracle();

    String asyncTypeName = typeName + "Async";
    JClassType asyncType = null;//from  ww  w  .j  a  v a 2  s. c  o  m
    String packageName = null;
    String simpleName = null;
    try {
        asyncType = oracle.findType(asyncTypeName);
        asyncType = asyncType.isInterface();
        packageName = asyncType.getPackage().getName();
        simpleName = asyncType.getSimpleSourceName() + "Impl";
    } catch (Exception e) {
        logger.log(TreeLogger.ERROR, asyncTypeName + " is not found or is not an interface", e);
        throw new UnableToCompleteException();
    }

    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return packageName + "." + simpleName;
    }

    // This method will complete httpMethods map and restPaths map;
    parseSyncType(typeName, oracle, logger);

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleName);
    factory.addImplementedInterface(asyncTypeName);
    factory.setSuperclass(RESTServiceProxy.class.getName());
    factory.addImport(RequestBuilder.class.getName());
    factory.addImport(RESTRequest.class.getName());

    SourceWriter writer = factory.createSourceWriter(context, printWriter);
    writer.indent();
    writer.println("");
    for (JMethod asyncMethod : asyncType.getMethods()) {
        writeAsyncMethod(asyncTypeName, asyncMethod, writer, logger);
    }
    writer.outdent();
    writer.commit(logger);
    return factory.getCreatedClassName();
}