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:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeCreateValidationGroupsMetadata(final SourceWriter sw) {
    // private static ValidationGroupsMetadata createValidationGroupsMetadata() {
    sw.println("private static ValidationGroupsMetadata createValidationGroupsMetadata() {");
    sw.indent();/*w  ww.  ja  v  a2  s.c  o  m*/

    // return ValidationGroupsMetadata.builder()
    sw.println("return ValidationGroupsMetadata.builder()");
    sw.indent();
    sw.indent();
    for (final Class<?> group : this.gwtValidation.groups()) {
        final GroupSequence sequenceAnnotation = group.getAnnotation(GroupSequence.class);
        Class<?>[] groups;
        if (sequenceAnnotation == null) {
            // .addGroup(<<group>>
            sw.print(".addGroup(");
            sw.print(group.getCanonicalName() + ".class");
            groups = group.getInterfaces();
        } else {
            // .addSequence(<<sequence>>
            sw.print(".addSequence(");
            sw.print(group.getCanonicalName() + ".class");
            groups = sequenceAnnotation.value();
        }
        for (final Class<?> clazz : groups) {
            // , <<group class>>
            sw.print(", ");
            sw.print(clazz.getCanonicalName() + ".class");
        }
        // )
        sw.println(")");
    }

    // .build();
    sw.println(".build();");
    sw.outdent();
    sw.outdent();

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeGetConstraintsForClass(final SourceWriter sw) {
    // public BeanDescriptor getConstraintsForClass(Class<?> clazz {
    sw.println("public BeanDescriptor getConstraintsForClass(Class<?> clazz) {");
    sw.indent();/*from   w w  w.ja va 2  s .  c om*/

    // checkNotNull(clazz, "clazz");
    sw.println("checkNotNull(clazz, \"clazz\");");

    for (final BeanHelper bean : this.beansToValidate) {
        this.writeGetConstraintsForClass(sw, bean);
    }

    this.writeThrowIllegalArgumnet(sw, "clazz.getName()");

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeGetConstraintsForClass(final SourceWriter sw, final BeanHelper bean) {
    // if (clazz.eqals(MyBean.class)) {
    sw.println("if (clazz.equals(" + bean.getTypeCanonicalName() + ".class)) {");
    sw.indent();/* w ww. j  a  v a 2s .c  om*/

    // return MyBeanValidator.INSTANCE.getConstraints(getValidationGroupsMetadata());
    sw.print("return ");
    sw.print(bean.getFullyQualifiedValidatorName());
    sw.println(".INSTANCE.getConstraints(getValidationGroupsMetadata());");

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeGwtValidate(final SourceWriter sw) {
    // public <T> Set<ConstraintViolation<T>> validate(GwtValidationContext<T>
    // context,// www. j  a  va 2s  .  com
    sw.print("public <T> Set<ConstraintViolation<T>> ");
    sw.println("validate(GwtValidationContext<T> context,");
    sw.indent();
    sw.indent();

    // Object object, Class<?>... groups) {
    sw.println("Object object, Class<?>... groups) {");
    sw.outdent();

    sw.println("checkNotNull(context, \"context\");");
    sw.println("checkNotNull(object, \"object\");");
    sw.println("checkNotNull(groups, \"groups\");");
    sw.println("checkGroups(groups);");

    for (final BeanHelper bean : this.cache.getAllBeans()) {
        this.writeGwtValidate(sw, bean);
    }

    // TODO(nchalko) log warning instead.
    this.writeThrowIllegalArgumnet(sw, "object.getClass().getName()");

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeGwtValidate(final SourceWriter sw, final BeanHelper bean) {
    this.writeIfInstanceofBeanType(sw, bean);
    sw.indent();/*w ww  .  j  ava  2 s. c om*/

    // return PersonValidator.INSTANCE

    sw.print("return ");
    sw.println(bean.getFullyQualifiedValidatorName() + ".INSTANCE");
    sw.indent();
    sw.indent();
    // .validate(context, (<<MyBean>>) object, groups);
    sw.print(".validate(context, ");
    sw.print("(" + bean.getTypeCanonicalName() + ") object, ");
    sw.println("groups);");
    sw.outdent();
    sw.outdent();

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeIfInstanceofBeanType(final SourceWriter sourceWriter, final BeanHelper bean) {
    // if (object instanceof MyBean) {
    sourceWriter.print("if (object instanceof ");
    sourceWriter.print(bean.getTypeCanonicalName());
    sourceWriter.println(") {");
}

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeThrowIllegalArgumnet(final SourceWriter sourceWriter, final String getClassName) {
    // throw new IllegalArgumentException("MyValidator can not validate ",
    sourceWriter.print("throw new IllegalArgumentException(\"");
    sourceWriter.print(this.validatorType.getName() + " can not  validate \"");
    sourceWriter.indent();/*from  www .j a v  a2 s .co  m*/
    sourceWriter.indent();

    // + object.getClass().getName() +". "
    sourceWriter.print("+ ");
    sourceWriter.print(getClassName);
    sourceWriter.println("+ \". \"");

    // + "Valid values are {Foo.clas, Bar.class}
    sourceWriter.print("+ \"Valid types are ");
    sourceWriter.print(this.beansToValidate.toString());
    sourceWriter.println("\");");
    sourceWriter.outdent();
    sourceWriter.outdent();
}

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeValidate(final SourceWriter sw) {
    // public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>...
    // groups) {//from   w w w . j a  v a 2  s.  c  o  m
    sw.println("public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {");
    sw.indent();

    sw.println("checkNotNull(object, \"object\");");
    sw.println("checkNotNull(groups, \"groups\");");
    sw.println("checkGroups(groups);");

    for (final BeanHelper bean : this.beansToValidate) {
        this.writeValidate(sw, bean);
    }

    this.writeThrowIllegalArgumnet(sw, "object.getClass().getName()");

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeValidate(final SourceWriter sw, final BeanHelper bean) {
    this.writeIfInstanceofBeanType(sw, bean);
    sw.indent();/*from w  w w. j  a va  2 s .co  m*/

    this.writeContext(sw, bean, "object");

    // return PersonValidator.INSTANCE
    sw.print("return ");
    sw.println(bean.getFullyQualifiedValidatorName() + ".INSTANCE");
    sw.indent();
    sw.indent();

    // .validate(context, (<<MyBean>>) object, groups);
    sw.print(".validate(context, ");
    sw.print("(" + bean.getTypeCanonicalName() + ") object, ");
    sw.println("groups);");
    sw.outdent();
    sw.outdent();

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

From source file:de.knightsoftnet.validators.rebind.ValidatorCreator.java

License:Apache License

private void writeValidateProperty(final SourceWriter sw) {
    sw.println("public <T> Set<ConstraintViolation<T>> validateProperty("
            + "T object,String propertyName, Class<?>... groups) {");
    sw.indent();/*from   w w  w. j  a  va2  s . com*/

    sw.println("checkNotNull(object, \"object\");");
    sw.println("checkNotNull(propertyName, \"propertyName\");");
    sw.println("checkNotNull(groups, \"groups\");");
    sw.println("checkGroups(groups);");

    for (final BeanHelper bean : this.beansToValidate) {
        this.writeValidateProperty(sw, bean);
    }

    this.writeThrowIllegalArgumnet(sw, "object.getClass().getName()");

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