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.ClassMapGenerator.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;// w ww.j  a va2s.com
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);

    composer.addImport(HashMap.class.getCanonicalName());

    composer.addImplementedInterface(classType.getQualifiedSourceName());
    JClassType target = typeOracle.getType(ClassMap.class.getCanonicalName());
    for (JClassType interfaze : classType.getImplementedInterfaces()) {
        if (interfaze.getErasedType().equals(target.getErasedType())) {
            JClassType[] genericTypes = interfaze.isParameterized().getTypeArgs();
            keyType = genericTypes[0];
            valueType = genericTypes[1];
        }
    }

    //      if (!"java.lang.String".equals(keyType.getQualifiedSourceName())){
    //         logger.log(TreeLogger.ERROR, "keyType must be a String for now");
    //         throw new UnableToCompleteException();
    //      }

    composer.addImport(keyType.getQualifiedSourceName());
    composer.addImport(valueType.getQualifiedSourceName());

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

    writeMethods(sourceWriter);
    writeData(sourceWriter);

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

    context.commit(logger, printWriter);
}

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

License:Open Source License

private void writeMethods(SourceWriter sw) {
    sw.print("private static HashMap<" + keyType.getName() + ", Class<? extends " + valueType.getName()
            + ">> map");
    sw.println("= new HashMap<" + keyType.getName() + ", Class<? extends " + valueType.getName() + ">>();");
    sw.print("private static HashMap<Class<? extends " + valueType.getName() + ">," + keyType.getName()
            + "> reversemap");
    sw.println("= new HashMap<Class<? extends " + valueType.getName() + ">," + keyType.getName() + ">();");
    sw.println();// ww w . jav  a  2  s.c o m
    sw.println("@Override");
    sw.println("public Class<? extends " + valueType.getName() + "> getClassFromKey(" + keyType.getName()
            + " name) {");
    sw.println("   return map.get(name);");
    sw.println("}");
    sw.println();
    sw.println("@Override");
    sw.println("public " + keyType.getName() + " getKeyFromClass(Class<? extends " + valueType.getName()
            + "> clazz) {");
    sw.println("   return reversemap.get(clazz);");
    sw.println("}");
}

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

License:Open Source License

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

    if (printWriter == null) {
        return;//from w  w w  .j  ava2 s .c o m
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImport(GWT.class.getCanonicalName());
    composer.addImport(RunAsyncCallback.class.getCanonicalName());
    composer.addImport(Ginjector.class.getCanonicalName());
    composer.addImport(GinModules.class.getCanonicalName());
    composer.addImport(AsyncCallback.class.getCanonicalName());
    composer.addImport(FlexInjector.class.getCanonicalName());
    composer.addImport(Map.class.getCanonicalName());
    composer.addImport(HashMap.class.getCanonicalName());

    composer.addImplementedInterface(classType.getQualifiedSourceName());

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);
    writeStatic(sourceWriter);
    writeGateways(sourceWriter);
    //      writeCreate(sourceWriter);
    writeConstructor(sourceWriter);
    sourceWriter.outdent();
    sourceWriter.println("}");

    context.commit(logger, printWriter);
}

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

License:Open Source License

private void writeFragment(SourceWriter sw, JClassType j) {
    sw.println("fragmentMap.put(" + j.getQualifiedSourceName() + ".class, new FlexInjector() {");
    sw.indent();/*from   www . ja v a2  s .com*/
    sw.println("@Override");
    sw.println("public <E> void create(Class<? extends E> type, AsyncCallback<E> callback) {");
    sw.indentln(
            "callback.onSuccess((E)injector.create$" + j.getQualifiedSourceName().replace('.', '$') + "());");
    sw.println("}");
    sw.outdent();
    sw.println("});");
}

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

License:Open Source License

private void writeGateways(SourceWriter sw) throws UnableToCompleteException {
    for (String key : getClasses().keySet()) {
        if (key == null)
            continue;
        sw.println("private final class fragment$" + key + " implements FlexInjector {");
        sw.indent();//from www . jav a  2  s  .  c  o  m
        sw.println();
        sw.println("@Override");
        sw.println("public <T> void create(final Class<? extends T> type, final AsyncCallback<T> callback) {");
        sw.indent();
        sw.println("GWT.runAsync(new RunAsyncCallback() {");
        sw.indent();
        sw.println("@Override");
        sw.println("public void onSuccess() {");
        for (JClassType j : getClasses().get(key)) {
            writeFragment(sw, j);
        }
        sw.indent();
        sw.println(className + ".this.create(type, callback);");
        sw.outdent();
        sw.println("}");
        sw.println("public void onFailure(Throwable reason) {");
        sw.indent();
        for (JClassType j : getClasses().get(key)) {
            sw.println("fragmentMap.remove(" + j.getQualifiedSourceName() + ".class);");
        }
        sw.println("callback.onFailure(reason);");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        sw.println("});");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        sw.println("}");
    }
}

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

License:Open Source License

private void writeStatic(SourceWriter sw) throws UnableToCompleteException {
    modules.toString();/*www .j a va  2  s .  c o  m*/
    sw.print("@GinModules(");
    for (Class<? extends GinModule> s : modules.value()) {
        sw.print(s.getCanonicalName());
        sw.print(".class");
    }
    sw.println(")");
    sw.println("static interface Injector extends Ginjector {");
    sw.indent();
    Set<JType> set = new HashSet<JType>();
    for (Vector<JClassType> group : getClasses().values()) {
        set.addAll(group);
    }
    for (JMethod method : classType.getMethods()) {
        set.add(method.getReturnType());
    }
    for (JType j : set) {
        sw.println(
                j.getQualifiedSourceName() + " create$" + j.getQualifiedSourceName().replace('.', '$') + "();");
    }
    //      for(Vector<JClassType> group : getClasses().values()){
    //         for(JClassType j : group){
    //            sw.println(j.getQualifiedSourceName() + " create$" + j.getQualifiedSourceName().replace('.', '$') + "();");
    //         }
    //      }
    sw.outdent();
    sw.println("}");
    sw.println();
    sw.println("private final Injector injector = GWT.create(Injector.class);");
    sw.println("private Map<Class<?>, FlexInjector> fragmentMap = new HashMap<Class<?>, FlexInjector>();");
    sw.println();
    sw.println("@Override");
    sw.println("public <T> void create(Class<? extends T> type, AsyncCallback<T> callback) {");
    sw.println("   FlexInjector x = fragmentMap.get(type);");
    sw.println("   if (x != null){");
    sw.println("      x.create(type, callback);");
    sw.println("   } else {");
    //      sw.println("      callback.onFailure(new ClassNotFoundException());");
    sw.println("      callback.onFailure(null);");
    sw.println("      GWT.log(\"Class Creation of \" + type + \" failed\");");
    sw.println("   }");
    sw.println("}");
}

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

License:Open Source License

/**
 * @param context/*  www  .  ja  v  a2s. c om*/
 */
private void generateHelperClass(GeneratorContext context) throws UnableToCompleteException, NotFoundException {
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    if (printWriter == null) {
        return;
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);

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

    composer.addImport(Singleton.class.getCanonicalName());
    composer.addImport(Map.class.getCanonicalName());
    composer.addImport(HashMap.class.getCanonicalName());
    composer.addImport(JsonEncoderHelper.class.getCanonicalName());
    composer.addImport(JsonValue.class.getCanonicalName());
    composer.addAnnotationDeclaration("@Singleton");

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

    writeHelperClass(sourceWriter);

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

    context.commit(logger, printWriter);
}

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

License:Open Source License

private void writeHelperClass(SourceWriter sw) {
    //Write variables
    sw.println("private HashMap<Class<?>, JsonValue<?>> map = new HashMap<Class<?>, JsonValue<?>>();");
    sw.println(); // Empty line for style

    //Write constructor
    sw.println("public " + className + "() {");
    sw.indent();/*from   w  ww  .  j a v  a 2 s.  c o m*/
    for (Entry<String, String> entry : map.entrySet()) {
        sw.println("map.put(" + entry.getKey() + ".class, new " + entry.getValue() + "());");
    }
    sw.outdent();
    sw.println("}");
    sw.println(); // Empty line for style

    //Write functions
    sw.println("@Override");
    sw.println("public Map<Class<?>, JsonValue<?>> getGeneratedMap() {");
    sw.indent();
    sw.println("return map;");
    sw.outdent();
    sw.println("}");
}

From source file:com.kk_electronic.gwt.rebind.ModuleTypeInfoHelperGenerator.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;//ww  w  . ja va  2  s  .c o  m
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);

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

    composer.addImport(ModuleTypeInfoHelper.class.getCanonicalName());

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

    writeClass(sourceWriter);

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

    context.commit(logger, printWriter);
}

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

License:Open Source License

private void writeClass(SourceWriter sw) {
    sw.println("@Override");
    sw.println("public void insertData(hasAddModuleTypeInfo provider) {");
    sw.indent();//from   w w w . j  av  a 2 s .c  o m
    for (JClassType j : getClasses()) {
        Integer id = getModuleID(j);
        String name = getModuleName(j);
        sw.println("provider.add(" + j.getQualifiedSourceName() + ".class," + id + "," + name + ");");
    }
    sw.outdent();
    sw.println("}");
}