git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v1 3/3] userdiff: support Java sealed classes

From
Andrei Rybak <rybak.a.v@gmail.com>
Date
Feb 3, 2023, 23:23 UTC
Message-ID
<20230203232339.216592-4-rybak.a.v@gmail.com>
In-Reply-To
<20230203232339.216592-1-rybak.a.v@gmail.com>

A new kind of class was added in Java 17 -- sealed classes.[1] This feature includes several new keywords that may appear in a declaration of a class. New modifiers before name of the class: "sealed" and "non-sealed", and a clause after name of the class marked by keyword "permits".

The current set of regular expressions in userdiff.c already allows the modifier "sealed" and the "permits" clause, but not the modifier "non-sealed", which is the first hyphenated keyword in Java.[2] Allow hyphen in the words that precede the name of type to match the "non-sealed" modifier.

In new input file "java-sealed" for the test t4018-diff-funcname.sh, use a Java code comment for the marker "RIGHT". This workaround is needed, because the name of the sealed class appears on the line of code that has the "ChangeMe" marker.

[1] Detailed description in "JEP 409: Sealed Classes"
    https://openjdk.org/jeps/409
[2] "JEP draft: Keyword Management for the Java Language"
    https://openjdk.org/jeps/8223002
Signed-off-by: Andrei Rybak <rybak.a.v@gmail.com>
---
 t/t4018/java-non-sealed                                | 8 ++++++++
 t/t4018/java-sealed                                    | 7 +++++++
 t/t4018/java-sealed-permits                            | 6 ++++++
 t/t4018/java-sealed-type-parameters                    | 6 ++++++
 t/t4018/java-sealed-type-parameters-implements-permits | 6 ++++++
 t/t4018/java-sealed-type-parameters-permits            | 6 ++++++
 userdiff.c                                             | 2 +-
 7 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/java-non-sealed
 create mode 100644 t/t4018/java-sealed
 create mode 100644 t/t4018/java-sealed-permits
 create mode 100644 t/t4018/java-sealed-type-parameters
 create mode 100644 t/t4018/java-sealed-type-parameters-implements-permits
 create mode 100644 t/t4018/java-sealed-type-parameters-permits
diff --git a/t/t4018/java-non-sealed b/t/t4018/java-non-sealed
new file mode 100644
index 0000000000..f68ffd4ff3
--- /dev/null
+++ b/t/t4018/java-non-sealed
@@ -0,0 +1,8 @@
+public sealed abstract class SealedClass {
+    public static non-sealed class RIGHT extends SealedClass {
+        static int ONE;
+        static int TWO;
+        static int THREE;
+        private int ChangeMe;
+    }
+}
diff --git a/t/t4018/java-sealed b/t/t4018/java-sealed
new file mode 100644
index 0000000000..e722fee803
--- /dev/null
+++ b/t/t4018/java-sealed
@@ -0,0 +1,7 @@
+public sealed abstract class Sealed { // RIGHT
+    static int ONE;
+    static int TWO;
+    static int THREE;
+    public final class ChangeMe extends Sealed {
+    }
+}
diff --git a/t/t4018/java-sealed-permits b/t/t4018/java-sealed-permits
new file mode 100644
index 0000000000..8573f2a7e8
--- /dev/null
+++ b/t/t4018/java-sealed-permits
@@ -0,0 +1,6 @@
+public sealed abstract class RIGHT permits PermittedA, PermittedB {
+    static int ONE;
+    static int TWO;
+    static int THREE;
+    private int ChangeMe;
+}
diff --git a/t/t4018/java-sealed-type-parameters b/t/t4018/java-sealed-type-parameters
new file mode 100644
index 0000000000..ec31115961
--- /dev/null
+++ b/t/t4018/java-sealed-type-parameters
@@ -0,0 +1,6 @@
+public sealed abstract class RIGHT<A, B> {
+    static int ONE;
+    static int TWO;
+    static int THREE;
+    private int ChangeMe;
+}
diff --git a/t/t4018/java-sealed-type-parameters-implements-permits b/t/t4018/java-sealed-type-parameters-implements-permits
new file mode 100644
index 0000000000..9fd4dd5633
--- /dev/null
+++ b/t/t4018/java-sealed-type-parameters-implements-permits
@@ -0,0 +1,6 @@
+public sealed abstract class RIGHT<A, B> implements List<A> permits PermittedA, PermittedB {
+    static int ONE;
+    static int TWO;
+    static int THREE;
+    private int ChangeMe;
+}
diff --git a/t/t4018/java-sealed-type-parameters-permits b/t/t4018/java-sealed-type-parameters-permits
new file mode 100644
index 0000000000..6af2352e46
--- /dev/null
+++ b/t/t4018/java-sealed-type-parameters-permits
@@ -0,0 +1,6 @@
+public sealed abstract class RIGHT<A, B> permits PermittedA, PermittedB {
+    static int ONE;
+    static int TWO;
+    static int THREE;
+    private int ChangeMe;
+}
diff --git a/userdiff.c b/userdiff.c
index f92b3029aa..040deb7439 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -171,7 +171,7 @@ PATTERNS("html",
 PATTERNS("java",
 	 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
 	 /* Class, enum, and interface declarations */
-	 "^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface|record)[ \t]+[A-Za-z][A-Za-z0-9_$]*([ \t]+|[<(]).*)$\n"
+	 "^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+[A-Za-z][A-Za-z0-9_$]*([ \t]+|[<(]).*)$\n"
 	 /* Method definitions; note that constructor signatures are not */
 	 /* matched because they are indistinguishable from method calls. */
 	 "^[ \t]*(([A-Za-z_<>&][][?&<>.,A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
-- 
2.39.1
Previous: Andrei RybakNext: Tassilo Horn
Message 4 of 19 in “userdiff: Java updates”
  1. 0/3 userdiff: Java updatesAndrei Rybak, Feb 3, 2023
  2. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 3, 2023
  3. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 3, 2023
  4. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 3, 2023
  5. Tassilo HornFeb 4, 2023
  6. 0/3 userdiff: Java updatesAndrei Rybak, Feb 4, 2023
  7. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 4, 2023
  8. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 4, 2023
  9. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 4, 2023
  10. Johannes SixtFeb 5, 2023
  11. Andrei RybakFeb 5, 2023
  12. Johannes SixtFeb 5, 2023
  13. 0/3 userdiff: Java updatesAndrei Rybak, Feb 7, 2023
  14. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 7, 2023
  15. Andrei RybakFeb 8, 2023
  16. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 7, 2023
  17. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 7, 2023
  18. Johannes SixtFeb 8, 2023
  19. Junio C HamanoFeb 8, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.