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

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

Introduction

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

Prototype

void outdent();

Source Link

Usage

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

License:Open Source License

private void writeData(SourceWriter sw) throws UnableToCompleteException {
    sw.println();//  w w w .j a  v a  2s  .  c  o m
    sw.println("{");
    sw.indent();
    for (JClassType classType : valueType.getSubtypes()) {
        String key = getKeyFromClass(classType);
        sw.println("map.put(" + key + "," + classType.getQualifiedSourceName() + ".class);");
        sw.println("reversemap.put(" + classType.getQualifiedSourceName() + ".class, " + key + ");");
    }
    sw.outdent();
    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 av a 2  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  w  ww  . j ava2s .  c  o m
    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();/* www . ja v  a 2s. c om*/
        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 writeConstructor(SourceWriter sw) throws UnableToCompleteException {
    sw.println();//from w  w w .java  2s .  c  om
    sw.println("@SuppressWarnings(\"unchecked\")");
    sw.println("public " + className + "() {");
    sw.indent();
    sw.println("FlexInjector fragment;");
    for (String key : getClasses().keySet()) {
        if (key != null) {
            sw.println("fragment = new fragment$" + key + "();");
            for (JClassType j : getClasses().get(key)) {
                sw.println("fragmentMap.put(" + j.getQualifiedSourceName() + ".class, fragment);");
            }
        } else {
            for (JClassType j : getClasses().get(key)) {
                writeFragment(sw, j);
            }
        }
    }
    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();/*ww w . ja  v a  2  s .c  om*/
    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/*w  ww  .java  2 s  .  c o  m*/
 */
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();/* w  ww . j  ava 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;/*from  w  w  w . j  a  v  a2s . c  om*/
    }

    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();// w w  w.j  av a2s .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("}");
}