Public: Use jsni to access private fields and methods.
This allows
org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest
.testFieldAndPropertyVisibilityIsNotConstrained()
to pass.
[JSR 303 TCK Result] 6 of 258 (2.33%) Pass with 6 Failures and 29 Errors.

Review at http://gwt-code-reviews.appspot.com/1206801

Review by: rchandia@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9404 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/SampleValidator.java b/samples/validation/src/com/google/gwt/sample/validation/client/SampleValidator.java
index dffe96a..4ad4ef7 100644
--- a/samples/validation/src/com/google/gwt/sample/validation/client/SampleValidator.java
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/SampleValidator.java
@@ -27,7 +27,6 @@
  * the {@link GwtValidation} annotation can be validated.
  */
 @GwtValidation(value = Person.class,
- groups = {
-    Default.class, ClientGroup.class})
+     groups = {Default.class, ClientGroup.class})
 public interface SampleValidator extends Validator {
 }
diff --git a/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java b/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java
index 0f8d0d3..867dcf8 100644
--- a/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java
+++ b/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java
@@ -35,7 +35,6 @@
   @Size(min = 4)
   private String name;
 
-  @Max(999999999)
   private long ssn;
 
   public Address getAddress() {
@@ -46,10 +45,6 @@
     return name;
   }
 
-  public long getSsn() {
-    return ssn;
-  }
-
   public void setAddress(Address address) {
     this.address = address;
   }
@@ -61,4 +56,9 @@
   public void setSsn(long ssn) {
     this.ssn = ssn;
   }
+
+  @Max(999999999)
+  protected long getSsn() {
+    return ssn;
+  }
 }
diff --git a/samples/validationtck/style/html/junit-noframes.xsl b/samples/validationtck/style/html/junit-noframes.xsl
index d793c26..5ce74c0 100644
--- a/samples/validationtck/style/html/junit-noframes.xsl
+++ b/samples/validationtck/style/html/junit-noframes.xsl
@@ -248,11 +248,11 @@
 
     <xsl:template name="summary">
         <h2>Summary</h2>
-        <xsl:variable name="testCount" select="259"/>
+        <xsl:variable name="testCount" select="258"/>
         <!-- 
           testCount from
           jar -xf jsr303-tck-1.0.3.GA-sources.jar 
-          grep -r \@Test org/hibernate/jsr303/tck/tests/ | wc -l
+          grep -r \@Test org/hibernate/jsr303/tck/tests/ | grep -v "enabled = false" | wc -l
         -->
         <xsl:variable name="testExecutedCount" select="sum(testsuite/@tests)"/>
         <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
@@ -260,13 +260,16 @@
         <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
         <xsl:variable name="passedCount" select="($testExecutedCount - $failureCount - $errorCount)"/>
         <xsl:variable name="successRate" select="($passedCount) div $testCount"/>
-        <h3><xsl:value-of select="$passedCount"/>P 
-            <xsl:value-of select="$failureCount"/>F
-            <xsl:value-of select="$errorCount"/>E 
-            of <xsl:value-of select="$testCount"/> 
-            (<xsl:call-template name="display-percent">
-               <xsl:with-param name="value" select="$successRate"/>
-             </xsl:call-template>)</h3>
+        <h3>
+          <xsl:value-of select="$passedCount" /> <xsl:text> of </xsl:text>
+          <xsl:value-of select="$testCount"/> <xsl:text> (</xsl:text>
+          <xsl:call-template name="display-percent">
+            <xsl:with-param name="value" select="$successRate"/>
+          </xsl:call-template> 
+         <xsl:text>) Pass with </xsl:text>
+         <xsl:value-of select="$failureCount"/> <xsl:text> Failures and </xsl:text>
+         <xsl:value-of select="$errorCount" /> <xsl:text> Errors.</xsl:text>
+    </h3>
         <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
         <tr valign="top">
             <th>Tests</th>
diff --git a/samples/validationtck/style/text/junit-noframes.xsl b/samples/validationtck/style/text/junit-noframes.xsl
index ab0a55a..701148d 100644
--- a/samples/validationtck/style/text/junit-noframes.xsl
+++ b/samples/validationtck/style/text/junit-noframes.xsl
@@ -30,11 +30,11 @@
 
 -->
 <xsl:template match="testsuites">
-	<xsl:variable name="testCount" select="259"/>
+	<xsl:variable name="testCount" select="258"/>
     <!-- 
       testCount from
       jar -xf jsr303-tck-1.0.3.GA-sources.jar 
-      grep -r \@Test org/hibernate/jsr303/tck/tests/ | wc -l
+      grep -r \@Test org/hibernate/jsr303/tck/tests/| grep -v "enabled = false"  | wc -l
     -->
     <xsl:variable name="testExecutedCount" select="sum(testsuite/@tests)"/>
     <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
@@ -42,14 +42,14 @@
     <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
     <xsl:variable name="passedCount" select="($testExecutedCount - $failureCount - $errorCount)"/>
     <xsl:variable name="successRate" select="($passedCount) div $testCount"/>
-    <xsl:value-of select="$passedCount" /> <xsl:text> Pass </xsl:text>
-    <xsl:value-of select="$failureCount"/> <xsl:text> Fail </xsl:text>
-    <xsl:value-of select="$errorCount" /> <xsl:text> Error from a total of </xsl:text>
-    <xsl:value-of select="$testCount"/> <xsl:text> tests for a success rate of </xsl:text>
+    <xsl:value-of select="$passedCount" /> <xsl:text> of </xsl:text>
+    <xsl:value-of select="$testCount"/> <xsl:text> (</xsl:text>
     <xsl:call-template name="display-percent">
          <xsl:with-param name="value" select="$successRate"/>
     </xsl:call-template> 
-   <xsl:text>.</xsl:text> 
+    <xsl:text>) Pass with </xsl:text>
+    <xsl:value-of select="$failureCount"/> <xsl:text> Failures and </xsl:text>
+    <xsl:value-of select="$errorCount" /> <xsl:text> Errors.</xsl:text>
 </xsl:template>
 
 <xsl:template name="display-percent">
diff --git a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
index f91f14c..0c08cf1 100644
--- a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
+++ b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
@@ -16,6 +16,7 @@
 package com.google.gwt.validation.rebind;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.UnsafeNativeLong;
 import com.google.gwt.core.ext.GeneratorContext;
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
@@ -170,6 +171,14 @@
     writeValidatorInstances(sw);
   }
 
+  protected void writeUnsafeNativeLongIfNeeded(SourceWriter sw, JType jType) {
+    if (JPrimitiveType.LONG.equals(jType)) {
+      // @com.google.gwt.core.client.UnsafeNativeLong
+      sw.print("@");
+      sw.println(UnsafeNativeLong.class.getCanonicalName());
+    }
+  }
+
   private <T> T[] asArray(Collection<?> collection, T[] array) {
     if (collection == null) {
       return null;
@@ -378,10 +387,6 @@
     sw.println();
   }
 
-  /**
-   * @param sourceWriter
-   * @throws UnableToCompleteException
-   */
   private void writeFields(SourceWriter sw) throws UnableToCompleteException {
     // MyBeanDescriptor beanDescriptor = GWT.create(MyBeanDescriptor);
     sw.println(GwtBeanDescriptor.class.getCanonicalName());
@@ -413,27 +418,28 @@
   }
 
   private void writeFieldWrapperMethod(SourceWriter sw, JField field) {
-    // private fieldType _fieldName(Bean object) {
-    sw.print("private ");
+    writeUnsafeNativeLongIfNeeded(sw, field.getType());
+
+    // private native fieldType _fieldName(Bean object) /*-{
+    sw.print("private native ");
+
     sw.print(field.getType().getQualifiedSourceName());
     sw.print(" ");
     sw.print(toWrapperName(field));
     sw.print("(");
     sw.print(beanType.getName());
-    sw.println(" object) {");
+    sw.println(" object) /*-{");
     sw.indent();
 
-    // TOOD (nchalko) javascript magic to get private vars
-    JPrimitiveType primitive = field.getType().isPrimitive();
-    if (primitive != null) {
-      sw.println("return 0;");
-    } else {
-      sw.println("return null;");
-    }
+    // 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("}");
+    sw.println("}-*/;");
   }
 
   private void writeGetDescriptor(SourceWriter sw) {
@@ -450,32 +456,27 @@
     sw.println("}");
   }
 
-  /**
-   * @param sw
-   * @param method
-   */
   private void writeGetterWrapperMethod(SourceWriter sw, JMethod method) {
-    // private fieldType _getter(Bean object) {
-    sw.print("private ");
+    writeUnsafeNativeLongIfNeeded(sw, method.getReturnType());
+
+    // private native fieldType _getter(Bean object) /*={
+    sw.print("private native ");
     sw.print(method.getReturnType().getQualifiedSourceName());
     sw.print(" ");
     sw.print(toWrapperName(method));
     sw.print("(");
     sw.print(beanType.getName());
-    sw.println(" object) {");
+    sw.println(" object) /*-{");
     sw.indent();
 
-    // TOOD (nchalko) javascript magic to call private methods
-    JPrimitiveType primitive = method.getReturnType().isPrimitive();
-    if (primitive != null) {
-      sw.println("return 0;");
-    } else {
-      sw.println("return null;");
-    }
+    // return object.@com.examples.Bean::myMethod()();
+    sw.print("return object.");
+    sw.print(method.getJsniSignature());
+    sw.println("();");
 
-    // }
+    // }-*/;
     sw.outdent();
-    sw.println("}");
+    sw.println("}-*/;");
   }
 
   private void writeNewAnnotation(SourceWriter sw,
@@ -659,7 +660,6 @@
   private void writeValidateGetterCall(SourceWriter sw, PropertyDescriptor p,
       boolean useValue) {
     // validateProperty_get<<field>>(context, violations,
-
     sw.print(validateMethodGetterName(p));
     sw.print("(context, ");
     sw.print("violations, ");
@@ -965,10 +965,12 @@
     sw.println("// Write the  wrappers after we know which are needed");
     for (JField field : fieldsToWrap) {
       writeFieldWrapperMethod(sw, field);
+      sw.println();
     }
 
     for (JMethod method : gettersToWrap) {
       writeGetterWrapperMethod(sw, method);
+      sw.println();
     }
   }
 }
diff --git a/user/test/com/google/gwt/validation/example/client/Author.java b/user/test/com/google/gwt/validation/example/client/Author.java
index 1515533..fc84f893f 100644
--- a/user/test/com/google/gwt/validation/example/client/Author.java
+++ b/user/test/com/google/gwt/validation/example/client/Author.java
@@ -27,6 +27,7 @@
   @NotEmpty(message = "lastname must not be null")
   private String lastName;
 
+  @Size(max = 30)
   private String company;
 
   public String getFirstName() {
@@ -41,9 +42,6 @@
     return lastName;
   }
 
-  // TODO(nchalko) move constraint to the field once the JNSI wrappers are
-  // working.
-  @Size(max = 30)
   public String getCompany() {
     return company;
   }