]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Java: Remove unjustified warning "'}' found where ')' was expected".
authorBruno Haible <bruno@clisp.org>
Tue, 30 Sep 2025 22:04:45 +0000 (00:04 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 30 Sep 2025 22:04:45 +0000 (00:04 +0200)
Reported by Alexander Hubmann-Haidvogel <ahubmann@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00000.html>
and by Bjoern Voigt <bjoernv@arcor.de> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00023.html>.

* gettext-tools/src/x-java.c (extract_parenthesized): When a semicolon is seen
inside braces, start a new argparser instead of returning.
* gettext-tools/tests/xgettext-java-1: Add test cases with inner classes.

gettext-tools/src/x-java.c
gettext-tools/tests/xgettext-java-1

index 31864ed79fc1b62f4d93edb772972e8cf330db7a..db09fad30e43a29827b85d775297ac767355d0ec 100644 (file)
@@ -1978,7 +1978,16 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
         case token_type_semicolon:
           arglist_parser_done (argparser, arg);
           unref_region (inner_region);
-          return false;
+          if (terminator == token_type_rbrace)
+            {
+              argparser = arglist_parser_alloc (mlp, NULL);
+              inner_region = new_sub_region (outer_region, curr_context);
+              next_context_iter = null_context_list_iterator;
+              state = 0;
+              continue;
+            }
+          else
+            return false;
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
index 50a1bc4c6240ced8b582b6001685087085d46172..6b390aa68f0b6def77b1759729c8b6022fcf0507 100755 (executable)
@@ -24,12 +24,32 @@ class TestCase {
 
         // empty string
         String test5 = b.getString("");
+
+        // An inner class.
+        addActionListener(new ActionListener() {
+          @Override
+          public void actionPerformed(ActionEvent e) {
+            System.out.println(translate("Click!"));
+          }
+        });
+
+        // An anonymous inner class (Java 8 or newer).
+        Collections.emptySet().stream().filter(item -> {
+          return item != null;
+        });
+  }
     }
 }
 EOF
 
 : ${XGETTEXT=xgettext}
-${XGETTEXT} --omit-header --no-location -c -d xg-j-1.tmp xg-j-1.java || Exit 1
+${XGETTEXT} --omit-header --no-location -c -d xg-j-1.tmp xg-j-1.java 2>xg-j-1.tmq || Exit 1
+grep -v '^==' xg-j-1.tmq > xg-j-1.err
+# Expect no warning here.
+if test -s xg-j-1.err; then
+  cat xg-j-1.err
+  Exit 1
+fi
 LC_ALL=C tr -d '\r' < xg-j-1.tmp.po > xg-j-1.po || Exit 1
 
 cat <<\EOF > xg-j-1.ok