]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Emit a static method instead of a static field; this saves initialization
authorBruno Haible <bruno@clisp.org>
Wed, 7 Jan 2004 10:36:46 +0000 (10:36 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:34 +0000 (12:11 +0200)
time.

gettext-tools/src/ChangeLog
gettext-tools/src/gnu/gettext/DumpResource.java
gettext-tools/src/write-java.c

index 6d3976d14e531027f448d46889206f1788351bcf..325d3375c4f5f35bfed5a728d538bc6345b6aae4 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-26  Bruno Haible  <bruno@clisp.org>
+
+       * write-java.c (write_java_code): Emit a static method
+       'get_msgid_plural_table' instead of a static field 'plural'.
+       * gnu/gettext/DumpResource.java (DumpResource.dump): Exploit a
+       'get_msgid_plural_table' method if it exists.
+
 2003-12-14  Bruno Haible  <bruno@clisp.org>
 
        * message.h (format_type): New enum value 'format_csharp'.
index 692cd11a2d2fb7d152393b5e9bdf10a7fde4eec9..58a5d24da2db1247b3d6e0dba61fce018bd887b7 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext for Java
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001-2003 Free Software Foundation, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -68,7 +68,6 @@ public class DumpResource {
   }
   private ResourceBundle catalog;
   private Method lookupMethod;
-  private Field pluralField;
   // Lookup the value corresponding to a key found in catalog.getKeys().
   // Here we assume that the catalog returns a non-inherited value for
   // these keys. FIXME: Not true. Better see whether handleGetObject is
@@ -98,7 +97,13 @@ public class DumpResource {
     } catch (NoSuchMethodException e) {
     } catch (SecurityException e) {
     }
-    pluralField = null;
+    Method pluralMethod = null;
+    try {
+      pluralMethod = catalog.getClass().getMethod("get_msgid_plural_table", new Class[0]);
+    } catch (NoSuchMethodException e) {
+    } catch (SecurityException e) {
+    }
+    Field pluralField = null;
     try {
       pluralField = catalog.getClass().getField("plural");
     } catch (NoSuchFieldException e) {
@@ -124,12 +129,24 @@ public class DumpResource {
     {
       Enumeration keys = catalog.getKeys();
       Object plural = null;
-      if (pluralField != null)
+      if (pluralMethod != null) {
+        // msgfmt versions > 0.13.1 create a static get_msgid_plural_table()
+        // method.
+        try {
+          plural = pluralMethod.invoke(catalog, new Object[0]);
+        } catch (IllegalAccessException e) {
+          e.printStackTrace();
+        } catch (InvocationTargetException e) {
+          e.getTargetException().printStackTrace();
+        }
+      } else if (pluralField != null) {
+        // msgfmt versions <= 0.13.1 create a static plural field.
         try {
           plural = pluralField.get(catalog);
         } catch (IllegalAccessException e) {
           e.printStackTrace();
         }
+      }
       if (plural instanceof String[]) {
         // A GNU gettext created class with plural handling, Java2 format.
         int i = 0;
index 5015bd7d468217f6b2cd34fe3b6225caa4dfb696..230d28a9c2abdce1000bb259c5be91c6e938d595 100644 (file)
@@ -742,7 +742,8 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
       if (plurals)
        {
          bool first;
-         fprintf (stream, "  public static final java.lang.String[] plural = new java.lang.String[] { ");
+         fprintf (stream, "  public static final java.lang.String[] get_msgid_plural_table () {\n");
+         fprintf (stream, "    return new java.lang.String[] { ");
          first = true;
          for (j = 0; j < mlp->nitems; j++)
            {
@@ -756,6 +757,7 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
                }
            }
          fprintf (stream, " };\n");
+         fprintf (stream, "  }\n");
        }
 
       if (plurals)
@@ -821,8 +823,7 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
       /* Emit the msgid_plural strings.  Only used by msgunfmt.  */
       if (plurals)
        {
-         fprintf (stream, "  public static final java.util.Hashtable plural;\n");
-         fprintf (stream, "  static {\n");
+         fprintf (stream, "  public static final java.util.Hashtable get_msgid_plural_table () {\n");
          fprintf (stream, "    java.util.Hashtable p = new java.util.Hashtable();\n");
          for (j = 0; j < mlp->nitems; j++)
            if (mlp->item[j]->msgid_plural != NULL)
@@ -833,7 +834,7 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
                write_java_string (stream, mlp->item[j]->msgid_plural);
                fprintf (stream, ");\n");
              }
-         fprintf (stream, "    plural = p;\n");
+         fprintf (stream, "    return p;\n");
          fprintf (stream, "  }\n");
        }