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

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

Introduction

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

Prototype

void indent();

Source Link

Usage

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

private void generateStaticInitializer(TreeLogger logger, SourceWriter srcWriter) {

    srcWriter/* w w  w  .j a v  a2s  .c  o m*/
            .println("protected static final Map<String, PropertyDescription> PROPERTIES = Maps.newHashMap();");
    srcWriter.println("static{");
    srcWriter.indent();

    for (String propertyName : this.propertyTypes.keySet()) {
        JType propertyType = this.propertyTypes.get(propertyName);
        String simplePropertyTypeName = propertyType.getSimpleSourceName();
        String modelName = this.subModels.get(propertyType);
        if (modelName != null) {
            modelName += ".INSTANCE";
        }

        try {
            if (propertyType.isPrimitive() == null) {
                Class<?> propertyClass = Class.forName(propertyType.getQualifiedSourceName());

                if (Collection.class.isAssignableFrom(propertyClass)) {
                    JParameterizedType parametrizedType = propertyType.isParameterized();
                    JType subType = propertyType;
                    if (parametrizedType != null) {
                        subType = parametrizedType.getTypeArgs()[0];
                        String submodelName = this.subModels.get(subType);
                        if (submodelName != null) {
                            submodelName += ".INSTANCE";
                        } else {
                            submodelName = subType.getSimpleSourceName() + ".class";
                        }
                        modelName = String.format("new ModelCollection<%s>(%s.class, %s)",
                                subType.getSimpleSourceName(), propertyType.getSimpleSourceName(),
                                submodelName);
                    } else {
                        logger.branch(Type.WARN, String.format(
                                "Property [%s] on bean %s is a raw collection type. You cannot use it on editors.",
                                propertyName, this.beanType.getQualifiedSourceName()));
                        modelName = "new ModelCollection((Model) null)";
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            logger.branch(Type.WARN,
                    String.format("%s class not found.", propertyType.getQualifiedSourceName()));
        }
        Boolean getter = this.getters.containsKey(propertyName);
        Boolean setter = this.setters.containsKey(propertyName);

        srcWriter.print("PROPERTIES.put(\"%s\", newPropertyDescription(\"%s\", %s.class, %s, %s, %s",
                propertyName, propertyName, simplePropertyTypeName, modelName, getter, setter);
        this.generateValidators(srcWriter, propertyName);
        srcWriter.println("));");
    }
    srcWriter.outdent();
    srcWriter.println("}");

    srcWriter.println("protected Map<String, PropertyDescription> getProperties(){");
    srcWriter.println("   return PROPERTIES;");
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

private void generateConstructor(TreeLogger logger, SourceWriter srcWriter) {
    int lastIndex = this.proxyModelQualifiedName.lastIndexOf('.');
    String className = lastIndex == -1 ? this.proxyModelQualifiedName
            : this.proxyModelQualifiedName.substring(lastIndex + 1, this.proxyModelQualifiedName.length());
    srcWriter.println("public %s(){", className);
    srcWriter.indent();

    if (this.subModels.get(this.parentType) != null) {
        srcWriter.println("super(%s.INSTANCE, %s.class);", this.subModels.get(this.parentType),
                this.beanType.getSimpleSourceName());
        srcWriter.println();//from   ww w  .  j av a 2 s  . co m
    } else {
        srcWriter.println("super(%s.class);", this.beanType.getSimpleSourceName());
        srcWriter.println();
    }

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

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

private void generateCreate(TreeLogger logger, SourceWriter srcWriter) {
    srcWriter.println("public %s newInstance() {", this.beanType.getSimpleSourceName());
    srcWriter.indent();
    if (!this.beanType.isAbstract()) {
        srcWriter.println("return new %s();", this.beanType.getSimpleSourceName());
    } else {//from   w w  w . ja v  a2  s .  c o m
        srcWriter.println("throw new RuntimeException(\"Can not instantiate the abstract class %s\");",
                this.beanType.getSimpleSourceName());
    }
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

private void generateInternalGet(TreeLogger logger, SourceWriter srcWriter) {
    srcWriter.println("protected <P> P internalGet(%s bean, String fieldName){",
            this.beanType.getSimpleSourceName());
    srcWriter.indent();
    for (String propertyName : this.propertyTypes.keySet()) {
        JType propertyType = this.propertyTypes.get(propertyName);
        JPrimitiveType primitiveType = propertyType.isPrimitive();
        JMethod getter = this.getters.get(propertyName);
        if (getter != null) {
            if (primitiveType != null) {
                String boxedName = primitiveType.getQualifiedBoxedSourceName();
                boxedName = boxedName.substring(boxedName.lastIndexOf(".") + 1, boxedName.length());
                srcWriter.println(//from  w  ww  .  j a  v  a 2  s .c o  m
                        "if(\"%s\".equals(fieldName)){  return (P) PrimitiveUtils.castTo%s(bean.%s()); }",
                        propertyName, boxedName, getter.getName());
            } else {
                srcWriter.println("if(\"%s\".equals(fieldName)){  return (P) bean.%s(); }", propertyName,
                        getter.getName());
            }
        } else if (this.publicFields.containsKey(propertyName)) {
            if (primitiveType != null) {
                String boxedName = primitiveType.getQualifiedBoxedSourceName();
                boxedName = boxedName.substring(boxedName.lastIndexOf(".") + 1, boxedName.length());
                srcWriter.println(
                        "if(\"%s\".equals(fieldName)){  return (P) PrimitiveUtils.castTo%s(bean.%s); }",
                        propertyName, boxedName, propertyName);
            } else {
                srcWriter.println("if(\"%s\".equals(fieldName)){  return (P) bean.%s; }", propertyName,
                        propertyName);
            }
        }
    }
    srcWriter.println();
    srcWriter.println("return null;");
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java

License:Open Source License

private void generateInternalSet(TreeLogger logger, SourceWriter srcWriter) {
    srcWriter.println("protected <P> void internalSet(%s bean, String fieldName, P value){",
            this.beanType.getSimpleSourceName());
    srcWriter.indent();
    for (String propertyName : this.propertyTypes.keySet()) {
        JType propertyType = this.propertyTypes.get(propertyName);
        JPrimitiveType primitiveType = propertyType.isPrimitive();
        JMethod setter = this.setters.get(propertyName);
        if (setter != null) {
            if (primitiveType != null) {
                srcWriter.println(/*w ww  .j  av a2  s  . c  o  m*/
                        "if(\"%s\".equals(fieldName)){  bean.%s((%s) PrimitiveUtils.asPrimitive((%s)value)); }",
                        propertyName, setter.getName(), propertyType.getSimpleSourceName(),
                        primitiveType.getQualifiedBoxedSourceName());
            } else {
                srcWriter.println("if(\"%s\".equals(fieldName)){  bean.%s((%s) value); }", propertyName,
                        setter.getName(), propertyType.getSimpleSourceName());
            }
        } else if (this.publicFields.containsKey(propertyName)) {
            if (primitiveType != null) {
                srcWriter.println(
                        "if(\"%s\".equals(fieldName)){ bean.%s = PrimitiveUtils.asPrimitive((%s) value); }",
                        propertyName, propertyName, primitiveType.getQualifiedBoxedSourceName());
            } else {
                srcWriter.println("if(\"%s\".equals(fieldName)){  bean.%s = (%s) value; }", propertyName,
                        propertyName, propertyType.getSimpleSourceName());
            }
        }
    }
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

public String create(TreeLogger logger, GeneratorContext context) {
    PrintWriter printWriter = context.tryCreate(logger, this.packageName, this.viewProxySimpleName);
    if (printWriter == null) {
        return this.viewProxyQualifiedName;
    }//from w  w  w .j a  v  a 2s  .c om

    SourceWriter srcWriter = this.getSourceWriter(printWriter, context);

    srcWriter.indent();
    this.generateProxy(logger, srcWriter);
    srcWriter.println();
    this.generateTokenPrefixes(logger, srcWriter);
    srcWriter.println();
    if (this.placeTokenizerClass == null) {
        this.generateInternalTokenizer(logger, srcWriter);
    } else {
        this.generateDelegateTokenizer(logger, srcWriter);
    }
    this.generateActivityFactory(logger, srcWriter);
    srcWriter.outdent();

    srcWriter.commit(logger);
    return this.viewProxyQualifiedName;
}

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

private void generateActivityFactory(TreeLogger logger, SourceWriter srcWriter) {
    srcWriter.println("@Override");
    srcWriter.println("public Activity createActivity(Place place) {");
    srcWriter.indent();
    srcWriter.println("return new ViewActivity(this, place);");
    srcWriter.outdent();//  w  w  w  . j a  v a2  s.co  m
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

private void generateInternalTokenizer(TreeLogger logger, SourceWriter srcWriter) {
    boolean hasTokeConstructor = false;
    for (JConstructor constructor : this.placeType.getConstructors()) {
        if (constructor.getParameters().length == 1 && constructor.getParameters()[0].getType()
                .getSimpleSourceName().equals(String.class.getSimpleName())) {
            hasTokeConstructor = true;//from www  .  ja  v a 2  s. co  m
        }
    }
    srcWriter.println("@Override");
    srcWriter.println("public %s getPlace(String token) {", this.placeType.getSimpleSourceName());
    srcWriter.indent();
    if (hasTokeConstructor) {
        srcWriter.println("return new %s(token);", this.placeType.getSimpleSourceName());
    } else {
        srcWriter.println("%s place = new %s();", this.placeType.getSimpleSourceName(),
                this.placeType.getSimpleSourceName());
        srcWriter.println("place.setToken(token);");
        srcWriter.println("return place;");
    }
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println("@Override");
    srcWriter.println("public String getToken(%s place) {", this.placeType.getSimpleSourceName());
    srcWriter.indent();
    srcWriter.println("if(place instanceof ViewPlace){");
    srcWriter.indent();
    srcWriter.println("return ((ViewPlace)place).getToken();");
    srcWriter.outdent();
    srcWriter.println("}");
    srcWriter.println("return null;");
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

private void generateDelegateTokenizer(TreeLogger logger, SourceWriter srcWriter) {
    srcWriter.println("@Override");
    srcWriter.println("public %s getPlace(String token) {", this.placeType.getSimpleSourceName());
    srcWriter.indent();
    srcWriter.println("return new %s().getPlace(token);", this.placeTokenizerClass.getSimpleName());
    srcWriter.outdent();//  w w  w  . ja  v  a2 s . c  o  m
    srcWriter.println("}");
    srcWriter.println("@Override");
    srcWriter.println("public String getToken(%s place) {", this.placeType.getSimpleSourceName());
    srcWriter.indent();
    srcWriter.println("return new %s().getToken(place);", this.placeTokenizerClass.getSimpleName());
    srcWriter.outdent();
    srcWriter.println("}");
}

From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java

License:Open Source License

private void generateTokenPrefixes(TreeLogger logger, SourceWriter srcWriter) {
    List<String> tokens = Lists.newArrayList();
    tokens.add("\"" + this.placeType.getSimpleSourceName().replaceAll("Place$", "") + "\"");
    for (String alias : this.activityDescrition.aliases()) {
        tokens.add("\"" + alias + "\"");
    }//  w w  w . jav  a2  s  .  c  om

    srcWriter.println("@Override");
    srcWriter.println("public String[] getPlacePrefixes(){");
    srcWriter.indent();
    srcWriter.println("return new String[]{ %s };", Joiner.on(", ").join(tokens));
    srcWriter.outdent();
    srcWriter.println("}");
}