Git fork

userdiff: support Java sealed classes

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>
Reviewed-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Andrei Rybak and committed by
Junio C Hamano
93d52ed0 575e6fcf

+40 -1
+8
t/t4018/java-non-sealed
··· 1 + public abstract sealed class SealedClass { 2 + public static non-sealed class RIGHT extends SealedClass { 3 + static int ONE; 4 + static int TWO; 5 + static int THREE; 6 + private int ChangeMe; 7 + } 8 + }
+7
t/t4018/java-sealed
··· 1 + public abstract sealed class Sealed { // RIGHT 2 + static int ONE; 3 + static int TWO; 4 + static int THREE; 5 + public final class ChangeMe extends Sealed { 6 + } 7 + }
+6
t/t4018/java-sealed-permits
··· 1 + public abstract sealed class RIGHT permits PermittedA, PermittedB { 2 + static int ONE; 3 + static int TWO; 4 + static int THREE; 5 + private int ChangeMe; 6 + }
+6
t/t4018/java-sealed-type-parameters
··· 1 + public abstract sealed class RIGHT<A, B> { 2 + static int ONE; 3 + static int TWO; 4 + static int THREE; 5 + private int ChangeMe; 6 + }
+6
t/t4018/java-sealed-type-parameters-implements-permits
··· 1 + public abstract sealed class RIGHT<A, B> implements List<A> permits PermittedA, PermittedB { 2 + static int ONE; 3 + static int TWO; 4 + static int THREE; 5 + private int ChangeMe; 6 + }
+6
t/t4018/java-sealed-type-parameters-permits
··· 1 + public abstract sealed class RIGHT<A, B> permits PermittedA, PermittedB { 2 + static int ONE; 3 + static int TWO; 4 + static int THREE; 5 + private int ChangeMe; 6 + }
+1 -1
userdiff.c
··· 171 171 PATTERNS("java", 172 172 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n" 173 173 /* Class, enum, interface, and record declarations */ 174 - "^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n" 174 + "^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n" 175 175 /* Method definitions; note that constructor signatures are not */ 176 176 /* matched because they are indistinguishable from method calls. */ 177 177 "^[ \t]*(([A-Za-z_<>&][][?&<>.,A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",