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.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 va  2 s . c o m*/
    }

    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  w w  .  java  2 s . c o  m
    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;// www .j a  v a  2s.c om
    }

    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();/* ww w  .java  2  s  .  c  o m*/
    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  . ja  v a  2  s .c  o 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.msco.mil.server.com.sencha.gxt.explorer.rebind.SampleGenerator.java

License:sencha.com license

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    // Get access to metadata about the type to be generated
    TypeOracle oracle = context.getTypeOracle();
    JClassType toGenerate = oracle.findType(typeName).isClass();

    // Get the name of the new type
    String packageName = toGenerate.getPackage().getName();
    String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl";
    PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName);
    if (pw == null) {
        return packageName + "." + simpleSourceName;
    }//from w ww .  jav a2  s . co  m

    // Generate an HTML file resource for every example and write the source
    JClassType[] types = oracle.getTypes();

    // Build a ResourceOracle capable of reading java files
    sourceOracle = new ResourceOracleImpl(logger.branch(Type.DEBUG, "Gathering sources"));

    // Clean up these prefixes to not have filters
    PathPrefixSet prefixes = ((ResourceOracleImpl) context.getResourcesOracle()).getPathPrefixes();
    sourceOracle.setPathPrefixes(new PathPrefixSet());
    for (PathPrefix p : prefixes.values()) {
        sourceOracle.getPathPrefixes().add(new PathPrefix(p.getPrefix(), null));
    }
    ResourceOracleImpl.refresh(logger, sourceOracle);

    // Load the header and footer HTML content
    try {
        String slashyPackageName = getClass().getPackage().getName().replace('.', '/');
        javaHeader = Utility.getFileFromClassPath(slashyPackageName + "/header.html");
        footer = Utility.getFileFromClassPath(slashyPackageName + "/footer.html");
    } catch (IOException e) {
        logger.log(Type.ERROR, "Header or Footer failed to be read", e);
        throw new UnableToCompleteException();
    }

    // Find all examples, annotated with @Detail
    Set<ExampleDetailModel> examples = new HashSet<ExampleDetailModel>();
    Map<String, List<ExampleDetailModel>> hierarchy = new HashMap<String, List<ExampleDetailModel>>();

    Set<SourceModel> exampleSources = new HashSet<SourceModel>();
    for (JClassType type : types) {
        Example.Detail detail = type.getAnnotation(Example.Detail.class);
        if (detail != null) {
            ExampleDetailModel example = new ExampleDetailModel(logger, context, type, detail);

            // Collect sources to be built into html
            exampleSources.addAll(example.getAllSources());

            List<ExampleDetailModel> exampleList = hierarchy.get(detail.category());
            if (exampleList == null) {
                exampleList = new ArrayList<ExampleDetailModel>();
                hierarchy.put(detail.category(), exampleList);
            }
            examples.add(example);
            exampleList.add(example);
        }
    }

    // Sort folders, sort within those folders
    List<String> folders = new ArrayList<String>(hierarchy.keySet());
    Collections.sort(folders);
    for (List<ExampleDetailModel> contents : hierarchy.values()) {
        Collections.sort(contents);
    }

    // Actually build source for each type
    for (SourceModel type : exampleSources) {
        TreeLogger l = logger.branch(Type.DEBUG, "Writing HTML file for " + type.getName());

        // attempt to create the output file
        if (type.getType() == FileType.JAVA) {
            writeTypeToHtml(l, context, type.getJClassType());
        } else {
            writeFileToHtml(l, context, type.getPath());
        }
    }

    // Start making the class, with basic imports
    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
    factory.setSuperclass(typeName);
    factory.addImport(Name.getSourceNameForClass(Category.class));
    factory.addImport(Name.getSourceNameForClass(ImageResource.class));
    factory.addImport(Name.getSourceNameForClass(GWT.class));
    factory.addImport(Name.getSourceNameForClass(Example.class));
    factory.addImport(Name.getSourceNameForClass(Source.class));
    factory.addImport(Name.getSourceNameForClass(Source.FileType.class));
    SourceWriter sw = factory.createSourceWriter(context, pw);

    // Write the ctor
    sw.println("public %1$s() {", simpleSourceName);
    sw.indent();
    // Declare variables that will be used
    sw.println("Category c;");
    sw.println("ImageResource icon;");
    sw.println("Example e;");
    sw.println("Source dir;");
    Set<String> names = new HashSet<String>();
    Map<JClassType, String> bundles = new HashMap<JClassType, String>();
    for (String folder : folders) {
        // TODO escape name
        sw.println("c = new Category(\"%1$s\");", folder);
        for (ExampleDetailModel example : hierarchy.get(folder)) {
            // make sure the bundle to be used exists
            if (!bundles.containsKey(example.getClientBundleType())) {
                String bundleName = getNextName("bundle", names);
                sw.println("%1$s %2$s = GWT.create(%1$s.class);",
                        example.getClientBundleType().getQualifiedSourceName(), bundleName);

                bundles.put(example.getClientBundleType(), bundleName);
            }

            // write out the example, adding it to the current category
            writeExample(sw, bundles.get(example.getClientBundleType()), example);
        }
        sw.println("categories.add(c);");
    }
    sw.outdent();
    sw.println("}");// end ctor

    sw.commit(logger);

    return factory.getCreatedClassName();
}

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);/*from  w ww.  ja v a  2 s  . c om*/
    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.  jav a  2  s  .c o  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  ww w .jav a 2  s .c om
    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   ww  w.  ja v a 2 s  .  c  o  m
    sw.println("return new %sMetaModelFactory(attrBuilder);", modelClassName);
    sw.outdent();
    sw.println("}");
}