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.google.web.bindery.autobean.gwt.rebind.AutoBeanFactoryGenerator.java

License:Apache License

private void writeReturnWrapper(SourceWriter sw, AutoBeanType type, AutoBeanMethod method)
        throws UnableToCompleteException {
    if (!method.isValueType() && !method.isNoWrap()) {
        JMethod jmethod = method.getMethod();
        JClassType returnClass = jmethod.getReturnType().isClassOrInterface();
        AutoBeanType peer = model.getPeer(returnClass);

        sw.println("if (toReturn != null) {");
        sw.indent();/*from   www. jav  a  2  s  .  com*/
        sw.println("if (%s.this.isWrapped(toReturn)) {", type.getSimpleSourceName());
        sw.indentln("toReturn = %s.this.getFromWrapper(toReturn);", type.getSimpleSourceName());
        sw.println("} else {");
        sw.indent();
        if (peer != null) {
            // toReturn = new FooAutoBean(getFactory(), toReturn).as();
            sw.println("toReturn = new %s(getFactory(), toReturn).as();", peer.getQualifiedSourceName());
        }
        sw.outdent();
        sw.println("}");

        sw.outdent();
        sw.println("}");
    }
    // Allow return values to be intercepted
    JMethod interceptor = type.getInterceptor();
    if (interceptor != null) {
        // toReturn = FooCategory.__intercept(FooAutoBean.this, toReturn);
        sw.println("toReturn = %s.%s(%s.this, toReturn);",
                interceptor.getEnclosingType().getQualifiedSourceName(), interceptor.getName(),
                type.getSimpleSourceName());
    }
}

From source file:com.google.web.bindery.event.gwt.rebind.binder.EventBinderWriter.java

License:Apache License

private void writeBindMethodFooter(SourceWriter writer) {
    writer.println("return registrations;");
    writer.outdent();//from w ww  .jav a  2  s  . co m
    writer.println("}");
}

From source file:com.googlecode.gwtx.rebind.PropertyDescriptorsGenerator.java

License:Apache License

/**
 * @param logger//from w  ww  . j  a v  a2 s .  c  om
 * @param w
 * @param typeOracle
 */
private void write(TreeLogger logger, SourceWriter w, JClassType type) {
    Collection<Property> properties = lookupJavaBeanPropertyAccessors(logger, type);

    w.println("// automatically register BeanInfos for bean properties");
    w.println("static {");
    w.indent();
    w.println("GwtBeanInfo beanInfo = new GwtBeanInfo();");
    for (Property property : properties) {
        w.println("try {");
        w.indent();
        w.print("beanInfo.addPropertyDescriptor( ");
        writePropertyDescriptor(w, type, property.name, property.propertyType, property.getter,
                property.setter);
        w.println(" );");
        w.outdent();
        w.println("} catch (Exception e) {}");
    }
    w.println("GwtIntrospector.setBeanInfo( " + type.getName() + ".class, beanInfo );");
    w.outdent();
    w.println("}");
}

From source file:com.googlecode.gwtx.rebind.PropertyDescriptorsGenerator.java

License:Apache License

/**
 * @param sw// w w w  . j  ava2 s  .  com
 * @param type
 * @param propertyName
 * @param getter
 * @param setter
 */
private void writePropertyDescriptor(SourceWriter sw, JClassType type, String propertyName, String propertyType,
        JMethod getter, JMethod setter) {
    sw.print("new PropertyDescriptor( \"" + propertyName + "\", " + propertyType + ".class, ");
    if (getter != null) {
        sw.println("new Method() ");
        sw.println("{");
        sw.indent();
        sw.println("public Object invoke( Object bean, Object... args )");
        sw.println("{");
        sw.indent();
        sw.println("return ( (" + type.getName() + ") bean)." + getter.getName() + "();");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        sw.print("}, ");
    } else {
        sw.print("null, ");
    }
    if (setter != null) {
        sw.println("new Method() ");
        sw.println("{");
        sw.indent();
        sw.println("public Object invoke( Object bean, Object... args )");
        sw.println("{");
        sw.indent();
        JType argType = setter.getParameters()[0].getType().getErasedType();
        String argTypeName;
        if (argType.isPrimitive() != null) {
            argTypeName = argType.isPrimitive().getQualifiedBoxedSourceName();
        } else {
            argTypeName = argType.getQualifiedSourceName();
        }
        sw.println(
                "( (" + type.getName() + ") bean)." + setter.getName() + "( (" + argTypeName + ") args[0] );");
        sw.println("return null;");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        sw.print("} )");
    } else {
        sw.print("null )");
    }
}

From source file:com.googlecode.mgwt.css.rebind.StyleSheetUrlHolderGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    // get the property oracle
    PropertyOracle propertyOracle = context.getPropertyOracle();
    String enablePropertyValue = getSingleValue(propertyOracle, KEY_ENABLED, logger);

    if (!"true".equals(enablePropertyValue)) {
        return StyleSheetUrlHolderNoopImpl.class.getName();
    }// w  w w. j a v a  2s  . co  m

    List<String> urls = getValues(propertyOracle, KEY_URLS, logger);

    int interval = Integer.parseInt(getSingleValue(propertyOracle, KEY_INTERVAL, logger));

    JClassType classType = null;

    try {
        // get the type we are looking for
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        // if we can`t get it die
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }

    // get the package name
    String packageName = classType.getPackage().getName();
    // build name for implementation class
    String simpleName = classType.getSimpleSourceName() + "_generated";
    // combine package name and simple name to full qualified
    String fullName = packageName + "." + simpleName;

    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);

    if (printWriter == null) {
        return fullName;
    }

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.setSuperclass(StyleSheetUrlHolderDefaultImpl.class.getName());
    composer.addImport(StyleSheetUrlHolderDefaultImpl.class.getName());

    // start writing the implementation
    SourceWriter writer = composer.createSourceWriter(context, printWriter);

    writer.println("public " + simpleName + "() {");
    writer.print("super(");

    boolean first = true;
    for (String url : urls) {
        if (first) {
            first = false;
        } else {
            writer.print(",");
        }
        writer.print("\"" + url + "\"");
    }
    writer.print(");\n");

    writer.println("}");

    writer.println("public int interval() {");
    writer.println("return " + interval + ";");
    writer.println("}");
    writer.commit(logger);

    return fullName;
}

From source file:com.googlecode.mgwt.ui.generator.DeviceDensityGenerator.java

License:Apache License

protected void writeImplementation(TreeLogger logger, SelectionProperty property, SourceWriter writer) {
    writer.println("public boolean isMidDPI() {");
    writer.println("return " + property.getCurrentValue().equals("mid") + ";");
    writer.println("}");

    writer.println("public boolean isHighDPI() {");
    writer.println("return " + property.getCurrentValue().equals("high") + ";");
    writer.println("}");

    writer.println("public boolean isXHighDPI() {");
    writer.println("return " + property.getCurrentValue().equals("xhigh") + ";");
    writer.println("}");

    writer.commit(logger);/*w  ww  .  j  av a2  s. co  m*/
}

From source file:com.googlecode.mgwt.ui.generator.FormFactorGenerator.java

License:Apache License

@Override
protected void writeImplementation(TreeLogger logger, SelectionProperty property, SourceWriter writer) {
    writer.println("public boolean isPhone() {");
    writer.println("return " + property.getCurrentValue().equals("phone") + ";");
    writer.println("}");

    writer.println("public boolean isTablet() {");
    writer.println("return " + property.getCurrentValue().equals("tablet") + ";");
    writer.println("}");

    writer.println("public boolean isDesktop() {");
    writer.println("return " + property.getCurrentValue().equals("desktop") + ";");
    writer.println("}");

    writer.commit(logger);/*from   ww  w  . j  a v a 2 s.  c o  m*/
}

From source file:com.googlecode.mgwt.ui.generator.OsDetectionGenerator.java

License:Apache License

@Override
protected void writeImplementation(TreeLogger logger, SelectionProperty property, SourceWriter writer) {
    writer.println("public boolean isAndroid() {");
    writer.println("return isAndroidTablet() || isAndroidPhone();");
    writer.println("}");

    writer.println("public boolean isIPhone() {");
    writer.println("return " + property.getCurrentValue().equals("iphone") + " || "
            + property.getCurrentValue().equals("retina") + ";");
    writer.println("}");

    writer.println("public boolean isIPad() {");
    writer.println("return " + property.getCurrentValue().equals("ipad") + " || "
            + property.getCurrentValue().equals("ipad_retina") + ";");
    writer.println("}");

    writer.println("public boolean isIOs() {");
    writer.println("return isIPhone() || isIPad();");
    writer.println("}");

    writer.println("public boolean isDesktop() {");
    writer.println("return " + property.getCurrentValue().equals("desktop") + ";");
    writer.println("}");

    writer.println("public boolean isBlackBerry() {");
    writer.println("return false;");
    writer.println("}");

    writer.println("public boolean isTablet() {");
    writer.println("return isDesktop() || isIPad() || isAndroidTablet();");
    writer.println("}");

    writer.println("public boolean isPhone() {");
    writer.println("return isIPhone() || isAndroidPhone() || isBlackBerry();");
    writer.println("}");

    writer.println("public boolean isAndroidTablet() {");
    writer.println("return " + property.getCurrentValue().equals("android_tablet") + ";");
    writer.println("}");

    writer.println("public boolean isAndroidPhone() {");
    writer.println("return " + property.getCurrentValue().equals("android") + ";");
    writer.println("}");

    writer.println("public boolean isRetina() {");
    writer.println("return " + property.getCurrentValue().equals("retina") + ";");
    writer.println("}");

    writer.println("public boolean isIPadRetina() {");
    writer.println("return " + property.getCurrentValue().equals("ipad_retina") + ";");
    writer.println("}");

    writer.commit(logger);//from w  ww  .j  a  v a  2 s.c  o  m
}

From source file:com.googlecode.mgwt.ui.generator.SuperDevModeGenerator.java

License:Apache License

private String buildOnImplementation(TreeLogger logger, GeneratorContext context, JClassType classType,
        String typeName, ConfigurationProperty superDevModeServer) {

    if (superDevModeServer.getValues().get(0) == null) {
        //use default impl!
        return "com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnDefaultImpl";
    }//w w w. j a v a2s  .  c o  m

    // get the package name
    String packageName = classType.getPackage().getName();
    // build name for implementation class
    String simpleName = classType.getSimpleSourceName() + "_generated";
    // combine package name and simple name to full qualified
    String fullName = packageName + "." + simpleName;

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.setSuperclass("com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnImpl");
    composer.addImport("com.googlecode.mgwt.ui.client.util.impl.SuperDevModeHelperOnImpl");

    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);

    if (printWriter == null) {
        return fullName;
    }

    // start writing the implementation
    SourceWriter writer = composer.createSourceWriter(context, printWriter);

    writer.println("protected String getServerUrl() {");
    writer.println("return \"" + superDevModeServer.getValues().get(0) + "\";");
    writer.println("}");
    writer.commit(logger);

    return fullName;
}

From source file:com.googlecode.mgwt.ui.server.util.MGWTCssResourceGenerator.java

License:Apache License

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