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.GwtSpecificValidatorCreator.java

License:Apache License

private void writeClassLevelConstraintsValidation(final SourceWriter sw, final String groupsVarName)
        throws UnableToCompleteException {
    // all class level constraints
    int count = 0;
    final Class<?> clazz = this.beanHelper.getClazz();
    for (final ConstraintDescriptor<?> constraint : this.beanHelper.getBeanDescriptor()
            .getConstraintDescriptors()) {
        if (this.areConstraintDescriptorGroupsValid(constraint)) {
            if (this.hasMatchingAnnotation(constraint)) {

                if (!constraint.getConstraintValidatorClasses().isEmpty()) { // NOPMD
                    final Class<? extends ConstraintValidator<? extends Annotation, ?>> validatorClass = getValidatorForType(
                            constraint, clazz);

                    // validate(context, violations, null, object,
                    sw.print("validate(context, violations, null, object, ");

                    // new MyValidtor(),
                    sw.print("new ");
                    sw.print(validatorClass.getCanonicalName());
                    sw.print("(), "); // TODO(nchalko) use ConstraintValidatorFactory

                    // this.aConstraintDescriptor, groups);
                    sw.print(this.constraintDescriptorVar("this", count));
                    sw.print(", ");
                    sw.print(groupsVarName);
                    sw.println(");");
                } else if (constraint.getComposingConstraints().isEmpty()) {
                    // TODO(nchalko) What does the spec say to do here.
                    this.logger.log(TreeLogger.WARN,
                            "No ConstraintValidator of " + constraint + " for type " + clazz);
                }/* w ww .  j  a  v  a  2  s.co  m*/
                // TODO(nchalko) handle constraint.isReportAsSingleViolation() and
                // hasComposingConstraints
            }
            count++;
        }
    }
}

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

License:Apache License

private void writeConstraintDescriptor(final SourceWriter sw,
        final ConstraintDescriptor<? extends Annotation> constraint, final ElementType elementType,
        final ConstraintOrigin origin, final String constraintDescripotorVar) throws UnableToCompleteException {
    final Class<? extends Annotation> annotationType = constraint.getAnnotation().annotationType();

    // First list all composing constraints
    int count = 0;
    for (final ConstraintDescriptor<?> composingConstraint : constraint.getComposingConstraints()) {
        this.writeConstraintDescriptor(sw, composingConstraint, elementType, origin,
                constraintDescripotorVar + "_" + count++);
    }/*w  w w .ja va 2  s  .  com*/

    // private final ConstraintDescriptorImpl<MyAnnotation> constraintDescriptor = ;
    sw.print("private final ");
    sw.print(ConstraintDescriptorImpl.class.getCanonicalName());
    sw.print("<");

    sw.print(annotationType.getCanonicalName());
    sw.print(">");

    sw.println(" " + constraintDescripotorVar + "  = ");
    sw.indent();
    sw.indent();

    // ConstraintDescriptorImpl.<MyConstraint> builder()
    sw.print(ConstraintDescriptorImpl.class.getCanonicalName());
    sw.print(".<");

    sw.print(annotationType.getCanonicalName());
    sw.println("> builder()");
    sw.indent();
    sw.indent();

    // .setAnnotation(new MyAnnotation )
    sw.println(".setAnnotation( ");
    sw.indent();
    sw.indent();
    this.writeNewAnnotation(sw, constraint);
    sw.println(")");
    sw.outdent();
    sw.outdent();

    // .setAttributes(builder()
    sw.println(".setAttributes(attributeBuilder()");
    sw.indent();

    for (final Map.Entry<String, Object> entry : constraint.getAttributes().entrySet()) {
        // .put(key, value)
        sw.print(".put(");
        final String key = entry.getKey();
        sw.print(asLiteral(key));
        sw.print(", ");
        Object value = entry.getValue();
        // Add the Default group if it is not already present
        if ("groups".equals(key) && value instanceof Class[] && ((Class[]) value).length == 0) {
            value = new Class[] { Default.class };
        }
        sw.print(asLiteral(value));
        sw.println(")");
    }

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

    // .setConstraintValidatorClasses(classes )
    sw.print(".setConstraintValidatorClasses(");
    sw.print(asLiteral(this.asArray(constraint.getConstraintValidatorClasses(), new Class[0])));
    sw.println(")");

    final int ccCount = constraint.getComposingConstraints().size();
    for (int i = 0; i < ccCount; i++) {
        // .addComposingConstraint(cX_X)
        sw.print(".addComposingConstraint(");
        sw.print(constraintDescripotorVar + "_" + i);
        sw.println(")");
    }

    // .getGroups(groups)
    sw.print(".setGroups(");
    final Set<Class<?>> groups = constraint.getGroups();
    sw.print(asLiteral(this.asArray(groups, new Class<?>[0])));
    sw.println(")");

    // .setPayload(payload)
    sw.print(".setPayload(");
    final Set<Class<? extends Payload>> payload = constraint.getPayload();
    sw.print(asLiteral(this.asArray(payload, new Class[0])));
    sw.println(")");

    // .setReportAsSingleViolation(boolean )
    sw.print(".setReportAsSingleViolation(");
    sw.print(Boolean.toString(constraint.isReportAsSingleViolation()));
    sw.println(")");

    // .setElementType(elementType)
    sw.print(".setElementType(");
    sw.print(asLiteral(elementType));
    sw.println(")");

    // .setDefinedOn(origin)
    sw.print(".setDefinedOn(");
    sw.print(asLiteral(origin));
    sw.println(")");

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

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

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

License:Apache License

private void writeExpandDefaultAndValidate(final SourceWriter sw, final Stage stage)
        throws UnableToCompleteException {
    final Class<?> clazz = this.beanHelper.getClazz();

    // ArrayList<Class<?>> justGroups = new ArrayList<Class<?>>();
    sw.println("ArrayList<Class<?>> justGroups = new ArrayList<Class<?>>();");

    // for (Group g : groups) {
    sw.println("for (Group g : groups) {");
    sw.indent();/*  w ww. j ava 2 s .  c o m*/
    // if (!g.isDefaultGroup() || !getBeanMetadata().defaultGroupSequenceIsRedefined()) {
    sw.println("if (!g.isDefaultGroup() || !getBeanMetadata().defaultGroupSequenceIsRedefined()) {");
    sw.indent();
    // justGroups.add(g.getGroup());
    sw.println("justGroups.add(g.getGroup());");
    sw.outdent();
    // }
    sw.println("}");
    sw.outdent();
    // }
    sw.println("}");

    // Class<?>[] justGroupsArray = justGroups.toArray(new Class<?>[justGroups.size()]);
    sw.println("Class<?>[] justGroupsArray = justGroups.toArray(new Class<?>[justGroups.size()]);");

    switch (stage) {
    case OBJECT:
        // validateAllNonInheritedProperties(context, object, violations, justGroupsArray);
        sw.println("validateAllNonInheritedProperties(context, object, violations, " + "justGroupsArray);");
        this.writeClassLevelConstraintsValidation(sw, "justGroupsArray");
        break;
    case PROPERTY:
        // validatePropertyGroups(context, object, propertyName, violations, justGroupsArray);
        sw.println("validatePropertyGroups(context, object, propertyName, violations, " + "justGroupsArray);");
        break;
    case VALUE:
        // validateValueGroups(context, beanType, propertyName, value, violations,
        // justGroupsArray);
        sw.println("validateValueGroups(context, beanType, propertyName, value, violations, "
                + "justGroupsArray);");
        break;
    default:
        throw new IllegalStateException();
    }

    // if (getBeanMetadata().defaultGroupSequenceIsRedefined()) {
    sw.println("if (getBeanMetadata().defaultGroupSequenceIsRedefined()) {");
    sw.indent();
    // for (Class<?> g : beanMetadata.getDefaultGroupSequence()) {
    sw.println("for (Class<?> g : beanMetadata.getDefaultGroupSequence()) {");
    sw.indent();
    // int numberOfViolations = violations.size();
    sw.println("int numberOfViolations = violations.size();");

    switch (stage) {
    case OBJECT:
        // validateAllNonInheritedProperties(context, object, violations, g);
        sw.println("validateAllNonInheritedProperties(context, object, violations, g);");
        this.writeClassLevelConstraintsValidation(sw, "g");
        // validate super classes and super interfaces
        this.writeValidateInheritance(sw, clazz, Stage.OBJECT, null, false, "g");
        break;
    case PROPERTY:
        // validatePropertyGroups(context, object, propertyName, violations, g);
        sw.println("validatePropertyGroups(context, object, propertyName, violations, g);");
        break;
    case VALUE:
        // validateValueGroups(context, beanType, propertyName, value, violations, g);
        sw.println("validateValueGroups(context, beanType, propertyName, value, violations, g);");
        break;
    default:
        throw new IllegalStateException();
    }

    // if (violations.size() > numberOfViolations) {
    sw.println("if (violations.size() > numberOfViolations) {");
    sw.indent();
    // break;
    sw.println("break;");
    sw.outdent();
    // }
    sw.println("}");
    sw.outdent();
    // }
    sw.println("}");
    sw.outdent();
    // }
    sw.println("}");
    if (stage == Stage.OBJECT) {
        // else {
        sw.println("else {");
        sw.indent();

        // validate super classes and super interfaces
        this.writeValidateInheritance(sw, clazz, Stage.OBJECT, null, true, "groups");

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

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

License:Apache License

private void writeExpandDefaultAndValidateClassGroups(final SourceWriter sw) throws UnableToCompleteException {
    // public <T> void expandDefaultAndValidateClassGroups(
    sw.println("public <T> void expandDefaultAndValidateClassGroups(");

    // GwtValidationContext<T> context, BeanType object,
    // Set<ConstraintViolation<T>> violations, Group... groups) {
    sw.indent();//from   w ww  .  j  a v  a  2s.  c  om
    sw.indent();
    sw.println("GwtValidationContext<T> context,");
    sw.println(this.beanHelper.getTypeCanonicalName() + " object,");
    sw.println("Set<ConstraintViolation<T>> violations,");
    sw.println("Group... groups) {");
    sw.outdent();

    this.writeExpandDefaultAndValidate(sw, Stage.OBJECT);

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

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

License:Apache License

private void writeExpandDefaultAndValidatePropertyGroups(final SourceWriter sw)
        throws UnableToCompleteException {
    // public <T> void expandDefaultAndValidatePropertyGroups(
    sw.println("public <T> void expandDefaultAndValidatePropertyGroups(");

    // GwtValidationContext<T> context, BeanType object, String propertyName,
    // Set<ConstraintViolation<T>> violations, Group... groups) {
    sw.indent();//w  w w .  j  a va  2  s.  co  m
    sw.indent();
    sw.println("GwtValidationContext<T> context,");
    sw.println(this.beanHelper.getTypeCanonicalName() + " object,");
    sw.println("String propertyName,");
    sw.println("Set<ConstraintViolation<T>> violations,");
    sw.println("Group... groups) {");
    sw.outdent();

    this.writeExpandDefaultAndValidate(sw, Stage.PROPERTY);

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

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

License:Apache License

private void writeExpandDefaultAndValidateValueGroups(final SourceWriter sw) throws UnableToCompleteException {
    // public <T> void expandDefaultAndValidateValueGroups(
    sw.println("public <T> void expandDefaultAndValidateValueGroups(");

    // GwtValidationContext<T> context, Class<Author> beanType, String propertyName,
    // Object value, Set<ConstraintViolation<T>> violations, Group... groups) {
    sw.indent();/*from ww w. j  a v a  2s  .c om*/
    sw.indent();
    sw.println("GwtValidationContext<T> context,");
    sw.println("Class<" + this.beanHelper.getTypeCanonicalName() + "> beanType,");
    sw.println("String propertyName,");
    sw.println("Object value,");
    sw.println("Set<ConstraintViolation<T>> violations,");
    sw.println("Group... groups) {");
    sw.outdent();

    this.writeExpandDefaultAndValidate(sw, Stage.VALUE);

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

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

License:Apache License

private void writeFields(final SourceWriter sw) throws UnableToCompleteException {

    // Create a static array of all valid property names.
    BeanInfo beanInfo;//from w  w w.ja  v  a 2 s  .c  o m
    try {
        beanInfo = Introspector.getBeanInfo(this.beanHelper.getClazz());
    } catch (final IntrospectionException e) {
        throw error(this.logger, e);
    }

    // private static final java.util.List<String> ALL_PROPERTY_NAMES =
    sw.println("private static final java.util.List<String> ALL_PROPERTY_NAMES = ");
    sw.indent();
    sw.indent();

    // Collections.<String>unmodifiableList(
    sw.println("java.util.Collections.<String>unmodifiableList(");
    sw.indent();
    sw.indent();

    // java.util.Arrays.<String>asList(
    sw.print("java.util.Arrays.<String>asList(");

    // "foo","bar" );
    sw.print(Joiner.on(",").join(Iterables.transform(ImmutableList.copyOf(beanInfo.getPropertyDescriptors()),
            Functions.compose(TO_LITERAL, PROPERTY_DESCRIPTOR_TO_NAME))));
    sw.println("));");
    sw.outdent();
    sw.outdent();
    sw.outdent();
    sw.outdent();

    // Write the metadata for the bean
    this.writeBeanMetadata(sw);
    sw.println();

    // Create a variable for each constraint of each property
    for (final PropertyDescriptor p : this.beanHelper.getBeanDescriptor().getConstrainedProperties()) {
        int count = 0;
        for (final ConstraintDescriptor<?> constraint : p.getConstraintDescriptors()) {
            final org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?> constraintHibernate = (org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?>) constraint;
            if (this.areConstraintDescriptorGroupsValid(constraint)) {
                this.writeConstraintDescriptor(sw, constraint, constraintHibernate.getElementType(),
                        convertConstraintOriginEnum(constraintHibernate.getDefinedOn()),
                        this.constraintDescriptorVar(p.getPropertyName(), count++));
            }
        }
        this.writePropertyDescriptor(sw, p);
        if (p.isCascaded()) {
            this.beansToValidate.add(isIterableOrMap(p.getElementClass())
                    ? this.createBeanHelper(this.beanHelper.getAssociationType(p, true))
                    : this.createBeanHelper(p.getElementClass()));
        }
    }

    // Create a variable for each constraint of this class.
    int count = 0;
    for (final ConstraintDescriptor<?> constraint : this.beanHelper.getBeanDescriptor()
            .getConstraintDescriptors()) {
        final org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?> constraintHibernate = (org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?>) constraint;
        if (this.areConstraintDescriptorGroupsValid(constraint)) {
            this.writeConstraintDescriptor(sw, constraint, ElementType.TYPE,
                    convertConstraintOriginEnum(constraintHibernate.getDefinedOn()),
                    this.constraintDescriptorVar("this", count++));
        }
    }

    // Now write the BeanDescriptor after we already have the
    // PropertyDescriptors and class constraints
    this.writeBeanDescriptor(sw);
    sw.println();
}

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

License:Apache License

private void writeFieldWrapperMethod(final SourceWriter sw, final JField field) {
    this.writeUnsafeNativeLongIfNeeded(sw, field.getType());

    // private native fieldType _fieldName(com.example.Bean object) /*-{
    sw.print("private native ");// www.j a  va 2s  .co  m

    sw.print(field.getType().getQualifiedSourceName());
    sw.print(" ");
    sw.print(this.toWrapperName(field));
    sw.print("(");
    sw.print(field.getEnclosingType().getQualifiedSourceName());
    sw.println(" object) /*-{");
    sw.indent();

    // return object.@com.examples.Bean::myMethod();
    sw.print("return object.@");
    sw.print(field.getEnclosingType().getQualifiedSourceName());
    sw.print("::" + field.getName());
    sw.println(";");

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

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

License:Apache License

private void writeGetBeanMetadata(final SourceWriter sw) {
    // public BeanMetadata getBeanMetadata() {
    sw.println("public BeanMetadata getBeanMetadata() {");
    sw.indent();//  w ww  . j a  v  a2s  . c om

    // return beanMetadata;
    sw.println("return beanMetadata;");

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

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

License:Apache License

private void writeGetDescriptor(final SourceWriter sw) {
    // public GwtBeanDescriptor<beanType>
    // getConstraints(ValidationGroupsMetadata validationGroupsMetadata) {
    sw.print("public ");
    sw.print("GwtBeanDescriptor<" + this.beanHelper.getTypeCanonicalName() + "> ");
    sw.println("getConstraints(ValidationGroupsMetadata validationGroupsMetadata) {");
    sw.indent();/*from   w  ww  .  j  a v a2 s .  c o  m*/

    // beanDescriptor.setValidationGroupsMetadata(validationGroupsMetadata);
    sw.println("beanDescriptor.setValidationGroupsMetadata(validationGroupsMetadata);");

    // return beanDescriptor;
    sw.println("return beanDescriptor;");

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