Revision: 6809
Author: [email protected]
Date: Tue Nov 10 11:52:25 2009
Log: Fix custom plural rules that are inner classes, and adds a test for  
that case.

Issue: 4175
Patch by: jat
Review by: rice

http://code.google.com/p/google-web-toolkit/source/detail?r=6809

Added:
  /trunk/user/test/com/google/gwt/i18n/client/CustomPluralsTest.java
Modified:
  /trunk/user/src/com/google/gwt/i18n/rebind/MessagesMethodCreator.java
  /trunk/user/test/com/google/gwt/i18n/I18NSuite.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/i18n/client/CustomPluralsTest.java  Tue  
Nov 10 11:52:25 2009
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 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
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.i18n.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests custom plural rules, including as an inner class.
+ *
+ * <p>Captures issue 4175.
+ */
+public class CustomPluralsTest extends GWTTestCase {
+
+  /**
+   * Messages interface with a custom plural rule.
+   */
+  public interface MyMessages extends Messages {
+
+    /**
+     * A custom plural rule that returns "0", "1", or "other".
+     */
+    public static class CustomPluralRule implements PluralRule {
+       public PluralForm[] pluralForms() {
+          return new PluralForm[] {
+             new PluralForm("other", "other"),
+             new PluralForm("0", "first"),
+             new PluralForm("1", "second")
+          };
+       }
+
+       public int select(int n) {
+          if (0 <= n && n <= 1) {
+             return n + 1;
+          }
+          return 0;
+       }
+    }
+
+    @DefaultMessage("other: {0}")
+    @PluralText({"0", "zero", "1", "one"})
+    String customPlural(@PluralCount(CustomPluralRule.class) int cnt);
+  }
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.i18n.I18NTest";
+  }
+
+  public void testCustomPluralRule() {
+    MyMessages m = GWT.create(MyMessages.class);
+    assertEquals("zero", m.customPlural(0));
+    assertEquals("one", m.customPlural(1));
+    assertEquals("other: 2", m.customPlural(2));
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/i18n/rebind/MessagesMethodCreator.java       
 
Mon Mar  2 23:51:53 2009
+++ /trunk/user/src/com/google/gwt/i18n/rebind/MessagesMethodCreator.java       
 
Tue Nov 10 11:52:25 2009
@@ -412,7 +412,7 @@
        if (localizedType != null) {
          try {
            Class<?> testClass = Class.forName(
-              localizedType.getQualifiedSourceName(), false,
+              localizedType.getQualifiedBinaryName(), false,
                PluralRule.class.getClassLoader());
            if (PluralRule.class.isAssignableFrom(testClass)) {
              return (PluralRule) testClass.newInstance();
=======================================
--- /trunk/user/test/com/google/gwt/i18n/I18NSuite.java Tue Jun 23 20:13:51  
2009
+++ /trunk/user/test/com/google/gwt/i18n/I18NSuite.java Tue Nov 10 11:52:25  
2009
@@ -17,6 +17,7 @@

  import com.google.gwt.i18n.client.AnnotationsTest;
  import com.google.gwt.i18n.client.ArabicPluralsTest;
+import com.google.gwt.i18n.client.CustomPluralsTest;
  import com.google.gwt.i18n.client.DateTimeFormat_de_Test;
  import com.google.gwt.i18n.client.DateTimeFormat_en_Test;
  import com.google.gwt.i18n.client.DateTimeParse_en_Test;
@@ -57,6 +58,7 @@
      suite.addTestSuite(AnnotationsTest.class);
      suite.addTestSuite(ConstantMapTest.class);
      suite.addTestSuite(CurrencyTest.class);
+    suite.addTestSuite(CustomPluralsTest.class);
      suite.addTestSuite(DateTimeFormat_de_Test.class);
      suite.addTestSuite(DateTimeFormat_en_Test.class);
      suite.addTestSuite(DateTimeParse_en_Test.class);

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to