Allow properties files for inner classes to use _ as the separator in addition
to $ -- some build tools make it awkward to use $ in file names.  Added tests
for looking up inner classes.

Patch by: jat
Review by: ajr


git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@3855 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/rebind/ResourceFactory.java b/user/src/com/google/gwt/i18n/rebind/ResourceFactory.java
index ee5f501..f404f24 100644
--- a/user/src/com/google/gwt/i18n/rebind/ResourceFactory.java
+++ b/user/src/com/google/gwt/i18n/rebind/ResourceFactory.java
@@ -304,8 +304,15 @@
     String partialPath = localizedPath.replace('.', '/');
     for (int i = 0; i < loaders.size(); i++) {
       ResourceFactory element = loaders.get(i);
-      String path = partialPath + "." + element.getExt();
+      String ext = "." + element.getExt();
+      String path = partialPath + ext;
       InputStream m = loader.getResourceAsStream(path);
+      if (m == null && partialPath.contains("$")) {
+        // Also look for A_B for inner classes, as $ in path names
+        // can cause issues for some build tools.
+        path = partialPath.replace('$', '_') + ext;
+        m = loader.getResourceAsStream(path);
+      }
       if (m != null) {
         AbstractResource found = element.load(m);
         found.setPath(path);
diff --git a/user/test/com/google/gwt/i18n/client/I18N2Test.java b/user/test/com/google/gwt/i18n/client/I18N2Test.java
index 3cc843b..9e9da3d 100644
--- a/user/test/com/google/gwt/i18n/client/I18N2Test.java
+++ b/user/test/com/google/gwt/i18n/client/I18N2Test.java
@@ -16,6 +16,7 @@
 package com.google.gwt.i18n.client;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.TestAnnotatedMessages.Nested;
 import com.google.gwt.i18n.client.gen.Colors;
 import com.google.gwt.i18n.client.gen.TestBadKeys;
 import com.google.gwt.junit.client.GWTTestCase;
@@ -32,6 +33,7 @@
     return "com.google.gwt.i18n.I18N2Test";
   }
 
+  @SuppressWarnings("deprecation")
   public void testAnnotatedMessages() {
     TestAnnotatedMessages m = GWT.create(TestAnnotatedMessages.class);
     assertEquals("Test me", m.basicText());
@@ -125,6 +127,18 @@
     assertEquals("a circle", s.circle());
   }
 
+  /**
+   * Verify that nested annotations are looked up with both A$B names
+   * and A_B names.  Note that $ takes precedence and only one file for a
+   * given level in the inheritance tree will be used, so A$B_locale will
+   * be used and A_B_locale ignored.
+   */
+  public void testNestedAnnotations() {
+    Nested m = GWT.create(Nested.class);
+    assertEquals("nested dollar b_C", m.nestedDollar());
+    assertEquals("nested underscore b", m.nestedUnderscore());
+  }
+
   public void testWalkUpColorTree() {
     Colors colors = (Colors) GWT.create(Colors.class);
     assertEquals("red_b_C_d", colors.red());
diff --git a/user/test/com/google/gwt/i18n/client/I18NTest.java b/user/test/com/google/gwt/i18n/client/I18NTest.java
index 1e5e2a7..f94edb9 100644
--- a/user/test/com/google/gwt/i18n/client/I18NTest.java
+++ b/user/test/com/google/gwt/i18n/client/I18NTest.java
@@ -16,6 +16,7 @@
 package com.google.gwt.i18n.client;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.TestAnnotatedMessages.Nested;
 import com.google.gwt.i18n.client.gen.Colors;
 import com.google.gwt.i18n.client.gen.Shapes;
 import com.google.gwt.i18n.client.gen.TestMessages;
@@ -51,6 +52,7 @@
     return "com.google.gwt.i18n.I18NTest";
   }
 
+  @SuppressWarnings("unchecked") // intentional test of raw map
   public void testAnnotatedConstants() {
     TestAnnotatedConstants c = GWT.create(TestAnnotatedConstants.class);
     assertEquals(14, c.fourteen());
@@ -115,8 +117,10 @@
     assertEquals("PL: Total is US$11,305.01", m.currencyFormat(11305.01));
     assertEquals("PL: Default number format is 1,017.1",
         m.defaultNumberFormat(1017.1));
+    @SuppressWarnings("deprecation")
+    Date date = new Date(107, 11, 1, 12, 1, 2);
     assertEquals("PL: It is 12:01 PM on Saturday, December 1, 2007",
-        m.getTimeDate(new Date(107, 11, 1, 12, 1, 2)));
+        m.getTimeDate(date));
     assertEquals("PL: 13 widgets", m.pluralWidgetsOther(13));
     assertEquals("Too many widgets to count (150) in pig-latin",
         m.pluralWidgetsOther(150));
@@ -519,6 +523,13 @@
     assertEquals("Extend Protected Inner", extendProtectedInner);
   }
 
+  public void testNestedAnnotations() {
+    Nested m = GWT.create(Nested.class);
+    // no translation exists in piglatin for nested dollar
+    assertEquals("nested dollar", m.nestedDollar());
+    assertEquals("estednay underscoray", m.nestedUnderscore());
+  }
+
   public void testShapesFamily() {
     Shapes shapes = (Shapes) GWT.create(Shapes.class);
     // test overload
diff --git a/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties
new file mode 100644
index 0000000..57a9bd3
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages$Nested_b_C.properties
@@ -0,0 +1 @@
+nestedDollar = nested dollar b_C
diff --git a/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java
index 437a559..4bafffc 100644
--- a/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java
+++ b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages.java
@@ -31,6 +31,15 @@
 @Generate(format = "com.google.gwt.i18n.rebind.format.PropertiesFormat")
 public interface TestAnnotatedMessages extends Messages {
 
+  public interface Nested extends Messages {
+
+    @DefaultMessage("nested dollar")
+    String nestedDollar();
+
+    @DefaultMessage("nested underscore")
+    String nestedUnderscore();
+}
+
   @DefaultMessage("Test me")
   String basicText();
   
diff --git a/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties
new file mode 100644
index 0000000..50b477c
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_b.properties
@@ -0,0 +1 @@
+nestedUnderscore = nested underscore b
diff --git a/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties
new file mode 100644
index 0000000..4732950
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/TestAnnotatedMessages_Nested_piglatin.properties
@@ -0,0 +1 @@
+nestedUnderscore = estednay underscoray