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:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

private void writeGetFontName(JMethod method, SourceWriter sw) {
    sw.println("public String getFontName() {");
    sw.indent();/*  w  w w.  j a v a  2  s  . c  om*/

    sw.print("return \"");
    sw.print(getFontName(method));
    sw.println("\";");
    sw.outdent();
    sw.println("}");
}

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

protected void writeEnsureInjected(SourceWriter sw) {
    sw.println("private boolean injected;");
    sw.println("public boolean ensureInjected() {");
    sw.indent();//from www.  ja v a2s .  c  om
    sw.println("if (!injected) {");
    sw.indentln("injected = true;");
    sw.indentln(StyleInjector.class.getName() + ".inject(getText());");
    sw.indentln("return true;");
    sw.println("}");
    sw.println("return false;");
    sw.outdent();
    sw.println("}");
}

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

private void writeGetName(JMethod method, SourceWriter sw) {
    sw.println("public String getName() {");
    sw.indent();//from ww  w  .  j  a  v a2 s  .c  o  m
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");
}

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

private void writeGetText(TreeLogger logger, ResourceContext context, JMethod method, SourceWriter sw)
        throws UnableToCompleteException {
    sw.println("public String getText() {");
    sw.indent();/* w ww.j a v  a  2 s .  c  o  m*/

    URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method);

    sw.print("return \"");
    sw.print("@font-face{");

    sw.print("font-family:'");
    sw.print(getFontName(method));
    sw.print("';");

    sw.print("font-style:normal;");
    sw.print("font-weight:400;");

    try {
        String agent = context.getGeneratorContext().getPropertyOracle()
                .getSelectionProperty(logger, "user.agent").getCurrentValue();
        if (agent.equals("ie6") || agent.equals("ie8"))
            writeSrcIE(logger, context, method, sw, urls);
        else
            writeSrc(logger, context, method, sw, urls);
    } catch (BadPropertyValueException e) {
        throw new UnableToCompleteException();
    }
    sw.print("}");

    sw.println("\";");

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

}

From source file:org.cruxframework.crux.plugin.gadget.rebind.gwt.DefaultPreferenceGenerator.java

License:Apache License

/**
 * Write an instantiation expression for a given Preference subtype.
 *///from  w w w  . jav  a  2 s. c o  m
public void writeInstantiation(TreeLogger logger, SourceWriter sw, JClassType extendsPreferenceType,
        JMethod prefMethod) {
    sw.println("new " + extendsPreferenceType.getParameterizedQualifiedSourceName() + "() {");
    sw.indent();

    sw.println("public String getName() {return \"" + prefMethod.getName() + "\";}");
    sw.outdent();
    sw.println("}");
}

From source file:org.cruxframework.crux.plugin.gadget.rebind.gwt.UserPreferencesGenerator.java

License:Apache License

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

    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();

    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
        logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
        throw new UnableToCompleteException();
    }/*from   ww  w . j a  v  a2s.c  om*/

    // Make sure the UserPreferences type is correctly defined
    validateType(logger, sourceType);

    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "UserPreferencesImpl";

    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(),
            generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.addImport(PreferencesUtil.class.getName());
    f.addImplementedInterface(typeName);

    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);

    // If an implementation already exists, we don't need to do any work
    if (out != null) {
        JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace('$', '.'));
        assert preferenceType != null;

        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);

        for (JMethod m : sourceType.getOverridableMethods()) {
            JClassType extendsPreferenceType = m.getReturnType().isClassOrInterface();
            if (extendsPreferenceType == null) {
                logger.log(TreeLogger.ERROR,
                        "Return type of " + m.getName() + " is not a class or interface (must be assignable to "
                                + preferenceType.getName() + ").",
                        null);
                throw new UnableToCompleteException();
            }

            if (!preferenceType.isAssignableFrom(extendsPreferenceType)) {
                logger.log(TreeLogger.ERROR, "Cannot assign " + extendsPreferenceType.getQualifiedSourceName()
                        + " to " + preferenceType.getQualifiedSourceName(), null);
                throw new UnableToCompleteException();
            }

            // private final FooProperty __propName = new FooProperty()
            // {...}
            sw.print("private final " + extendsPreferenceType.getParameterizedQualifiedSourceName() + " __"
                    + m.getName() + " = ");
            writeInstantiation(logger, sw, extendsPreferenceType, m);
            sw.println(";");

            // public FooProperty property() { return __property; }
            sw.print("public ");
            sw.print(m.getReadableDeclaration(true, true, true, true, true));
            sw.println("{");
            sw.indent();
            sw.println("return __" + m.getName() + ";");
            sw.outdent();
            sw.println("}");
        }

        sw.commit(logger);
    }

    return f.getCreatedClassName();
}

From source file:org.cruxframework.crux.plugin.gadget.rebind.rpc.CruxGadgetProxyCreator.java

License:Apache License

/**
 * @param srcWriter/*w  w  w.j a va  2  s . co  m*/
 */
private void generateGadgetProxyContructor(SourceWriter srcWriter) {
    srcWriter.println("public " + getGadgetProxySimpleName() + "() {");
    srcWriter.indent();

    srcWriter.println("super();");

    if (HangoutUtils.isHangoutGadget()) {
        srcWriter.println("GadgetsGwtRpc.redirectThroughProxy((ServiceDefTarget) this, "
                + EscapeUtils.quote(HangoutUtils.getDeployURL()) + ");");
    } else {
        srcWriter.println("GadgetsGwtRpc.redirectThroughProxy((ServiceDefTarget) this);");
    }

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

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateAttributes(SourceWriter sourceWriter) {
    sourceWriter.indent();/*  w w w .j  a  va 2 s  .  com*/
    sourceWriter.println("private static Images images = GWT.create(Images.class);");
    sourceWriter.println("private static Constants constants = GWT.create(Constants.class);");
}

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetRegisteredAssetEditorFormatsMethod(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println("public String[] getRegisteredAssetEditorFormats() {");
    sourceWriter.indent();/*from  w  ww .j  ava 2  s. c o m*/
    sourceWriter.println("String[] formats = new String[] {");
    int i = 0;
    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        sourceWriter.print("\"" + format + "\"");
        if (i < registeredEditors.size() - 1) {
            sourceWriter.print(", ");
        }
        i++;
    }

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

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetAssetEditorMethod(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println(
            "public Widget getAssetEditor(Asset asset, RuleViewer viewer, ClientFactory clientFactory, EventBus eventBus) {");
    sourceWriter.indent();/*from w ww  . j a  v  a2s . c  o  m*/

    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        String assetEditorClassName = a.getEditorClass();
        sourceWriter.println("if(asset.getFormat().equals(\"" + format + "\")) {");
        sourceWriter.indent();
        sourceWriter
                .println("return new " + assetEditorClassName + "(asset, viewer, clientFactory, eventBus);");
        sourceWriter.outdent();
        sourceWriter.println("}");
    }
    sourceWriter.println("return new DefaultContentUploadEditor(asset, viewer, clientFactory, eventBus);");
    sourceWriter.outdent();
    sourceWriter.println("}");
}