Reviewers: rchandia,
Description:
Pass the root bean class to constraint violation from validateValue
[JSR 303 TCK Result] 124 of 257 (48.25%) Pass with 8 Failures and 7
Errors.
Please review this at http://gwt-code-reviews.appspot.com/1428806/
Affected files:
M user/src/com/google/gwt/validation/client/impl/GwtValidationContext.java
M
user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
M user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
M
user/test/org/hibernate/jsr303/tck/tests/validation/ValidateValueGwtTest.java
M
user/test/org/hibernate/jsr303/tck/tests/validation/graphnavigation/TckTestValidatorFactory.java
Index:
user/src/com/google/gwt/validation/client/impl/GwtValidationContext.java
===================================================================
---
user/src/com/google/gwt/validation/client/impl/GwtValidationContext.java
(revision 10115)
+++
user/src/com/google/gwt/validation/client/impl/GwtValidationContext.java
(working copy)
@@ -36,6 +36,7 @@
private final BeanDescriptor beanDescriptor;
private PathImpl path = new PathImpl();
+ private final Class<T> rootBeanClass;
private final T rootBean;
private final MessageInterpolator messageInterpolator;
private final AbstractGwtValidator validator;
@@ -49,15 +50,18 @@
*/
private final Set<Object> validatedObjects;
- public GwtValidationContext(T rootBean, BeanDescriptor beanDescriptor,
+ public GwtValidationContext(Class<T> rootBeanClass, T rootBean,
+ BeanDescriptor beanDescriptor,
MessageInterpolator messageInterpolator, AbstractGwtValidator
validator) {
- this(rootBean, beanDescriptor, messageInterpolator, validator,
+ this(rootBeanClass, rootBean, beanDescriptor, messageInterpolator,
+ validator,
new HashSet<Object>());
}
- private GwtValidationContext(T rootBean, BeanDescriptor beanDescriptor,
+ private GwtValidationContext(Class<T> rootBeanClass, T rootBean,
BeanDescriptor beanDescriptor,
MessageInterpolator messageInterpolator, AbstractGwtValidator
validator,
Set<Object> validatedObjects) {
+ this.rootBeanClass = rootBeanClass;
this.rootBean = rootBean;
this.beanDescriptor = beanDescriptor;
this.messageInterpolator = messageInterpolator;
@@ -79,8 +83,9 @@
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> append(String name) {
- GwtValidationContext<T> temp = new GwtValidationContext<T>(rootBean,
- beanDescriptor, messageInterpolator, validator, validatedObjects);
+ GwtValidationContext<T> temp = new
GwtValidationContext<T>(rootBeanClass,
+ rootBean, beanDescriptor, messageInterpolator, validator,
+ validatedObjects);
temp.path = path.append(name);
return temp;
}
@@ -91,8 +96,9 @@
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendIndex(String name, int index) {
- GwtValidationContext<T> temp = new GwtValidationContext<T>(rootBean,
- beanDescriptor, messageInterpolator, validator, validatedObjects);
+ GwtValidationContext<T> temp = new
GwtValidationContext<T>(rootBeanClass,
+ rootBean, beanDescriptor, messageInterpolator, validator,
+ validatedObjects);
temp.path = path.appendIndex(name, index);
return temp;
}
@@ -103,8 +109,9 @@
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendIterable(String name) {
- GwtValidationContext<T> temp = new GwtValidationContext<T>(rootBean,
- beanDescriptor, messageInterpolator, validator, validatedObjects);
+ GwtValidationContext<T> temp = new
GwtValidationContext<T>(rootBeanClass,
+ rootBean, beanDescriptor, messageInterpolator, validator,
+ validatedObjects);
temp.path = path.appendIterable(name);
return temp;
}
@@ -115,8 +122,9 @@
* @return the new GwtValidationContext.
*/
public GwtValidationContext<T> appendKey(String name, Object key) {
- GwtValidationContext<T> temp = new GwtValidationContext<T>(rootBean,
- beanDescriptor, messageInterpolator, validator, validatedObjects);
+ GwtValidationContext<T> temp = new
GwtValidationContext<T>(rootBeanClass,
+ rootBean, beanDescriptor, messageInterpolator, validator,
+ validatedObjects);
temp.path = path.appendKey(name, key);
return temp;
}
@@ -134,9 +142,8 @@
return rootBean;
}
- @SuppressWarnings("unchecked")
public Class<T> getRootBeanClass() {
- return (Class<T>) rootBean.getClass();
+ return rootBeanClass;
}
public AbstractGwtValidator getValidator() {
Index:
user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
===================================================================
---
user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
(revision 10115)
+++
user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
(working copy)
@@ -1028,7 +1028,7 @@
* {@link javax.validation.ReportAsSingleViolation
ReportAsSingleViolation},
* then is called recursively and the {@code violationsVar} is changed to
* match the the {@code constraintDescriptorVar}.
- *
+ *
* @param sw the Source Writer
* @param p the property
* @param elementClass The class of the Element
@@ -1043,7 +1043,7 @@
String constraintDescriptorVar, String violationsVar)
throws UnableToCompleteException {
boolean isComposite = !constraint.getComposingConstraints().isEmpty();
- boolean firstReportAsSingleViolation =
+ boolean firstReportAsSingleViolation =
constraint.isReportAsSingleViolation()
&& violationsVar.equals(DEFAULT_VIOLATION_VAR) && isComposite;
boolean reportAsSingleViolation = firstReportAsSingleViolation
@@ -1393,6 +1393,10 @@
private void writeValidatePropertyCall(SourceWriter sw,
PropertyDescriptor property, boolean useValue) {
+ if (useValue) {
+ // boolean valueTypeMatches = false;
+ sw.println("boolean valueTypeMatches = false;");
+ }
if (beanHelper.hasGetter(property)) {
if (useValue) {
// if ( value == null || value instanceof propertyType) {
@@ -1401,13 +1405,16 @@
property, false)));
sw.println(") {");
sw.indent();
+
+ // valueTypeMatches = true;
+ sw.println("valueTypeMatches = true;");
}
// validate_getMyProperty
writeValidateGetterCall(sw, property, useValue);
if (useValue) {
- // } else
+ // }
sw.outdent();
- sw.print("} else ");
+ sw.println("}");
}
}
@@ -1419,19 +1426,22 @@
property, true)));
sw.println(") {");
sw.indent();
+
+ // valueTypeMatches = true;
+ sw.println("valueTypeMatches = true;");
}
// validate_myProperty
writeValidateFieldCall(sw, property, useValue);
if (useValue) {
// } else
sw.outdent();
- sw.print("} else ");
+ sw.println("}");
}
}
if (useValue & (beanHelper.hasGetter(property) ||
beanHelper.hasField(property))) {
- // {
- sw.println(" {");
+ // if(!valueTypeMatches) {
+ sw.println("if(!valueTypeMatches) {");
sw.indent();
// throw new ValidationException(value.getClass +
Index: user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
===================================================================
--- user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
(revision 10115)
+++ user/src/com/google/gwt/validation/rebind/ValidatorCreator.java
(working copy)
@@ -120,11 +120,15 @@
private void writeContext(SourceWriter sw, BeanHelper bean, String
objectName) {
// GwtValidationContext<T> context = new GwtValidationContext<T>(
sw.print(GwtValidationContext.class.getSimpleName());
- sw.print("<T> context =");
- sw.print(" new " + GwtValidationContext.class.getSimpleName());
- sw.println("<T>" + "(");
- sw.indent();
- sw.indent();
+ sw.print("<T> context = new ");
+ sw.print(GwtValidationContext.class.getSimpleName());
+ sw.println("<T>(");
+ sw.indent();
+ sw.indent();
+
+ // (Class<T>) MyBean.class,
+ sw.print("(Class<T>) ");
+ sw.println(bean.getTypeCanonicalName() + ".class, ");
// object,
sw.println(objectName + ", ");
Index:
user/test/org/hibernate/jsr303/tck/tests/validation/ValidateValueGwtTest.java
===================================================================
---
user/test/org/hibernate/jsr303/tck/tests/validation/ValidateValueGwtTest.java
(revision 10115)
+++
user/test/org/hibernate/jsr303/tck/tests/validation/ValidateValueGwtTest.java
(working copy)
@@ -15,7 +15,6 @@
*/
package org.hibernate.jsr303.tck.tests.validation;
-import org.hibernate.jsr303.tck.util.client.Failing;
/**
* Test wrapper for {@link ValidateValueTest}.
@@ -28,12 +27,10 @@
delegate.testExistingPropertyWoConstraintsNorCascaded();
}
- @Failing(issue = 5804)
public void testValidateValue() {
delegate.testValidateValue();
}
- @Failing(issue = 5804)
public void testValidateValueFailure() {
delegate.testValidateValueFailure();
}
@@ -62,7 +59,6 @@
delegate.testValidateValueWithNullPropertyName();
}
- // This passes but the desired behavior is still not working
public void testValidIsNotHonoredValidateValue() {
delegate.testValidIsNotHonoredValidateValue();
}
Index:
user/test/org/hibernate/jsr303/tck/tests/validation/graphnavigation/TckTestValidatorFactory.java
===================================================================
---
user/test/org/hibernate/jsr303/tck/tests/validation/graphnavigation/TckTestValidatorFactory.java
(revision 10115)
+++
user/test/org/hibernate/jsr303/tck/tests/validation/graphnavigation/TckTestValidatorFactory.java
(working copy)
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors