summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2004-01-07 10:36:46 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:11:34 +0200
commite39a3ca7c428a5bf0fc2e4bcfe374675262af7ac (patch)
tree81ed6c5997e533362cff3716d7d33bffbee7272a
parent47cb2ab955add583eedf71b3dc1dc828d5c2de96 (diff)
downloadexternal_gettext-e39a3ca7c428a5bf0fc2e4bcfe374675262af7ac.zip
external_gettext-e39a3ca7c428a5bf0fc2e4bcfe374675262af7ac.tar.gz
external_gettext-e39a3ca7c428a5bf0fc2e4bcfe374675262af7ac.tar.bz2
Emit a static method instead of a static field; this saves initialization
time.
-rw-r--r--gettext-tools/src/ChangeLog7
-rw-r--r--gettext-tools/src/gnu/gettext/DumpResource.java25
-rw-r--r--gettext-tools/src/write-java.c9
3 files changed, 33 insertions, 8 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index 6d3976d..325d337 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -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'.
diff --git a/gettext-tools/src/gnu/gettext/DumpResource.java b/gettext-tools/src/gnu/gettext/DumpResource.java
index 692cd11..58a5d24 100644
--- a/gettext-tools/src/gnu/gettext/DumpResource.java
+++ b/gettext-tools/src/gnu/gettext/DumpResource.java
@@ -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;
diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c
index 5015bd7..230d28a 100644
--- a/gettext-tools/src/write-java.c
+++ b/gettext-tools/src/write-java.c
@@ -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");
}