1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 22:46:14 +02:00

userdiff: support Java record types

A new kind of class was added in Java 16 -- records.[1]  The syntax of
records is similar to regular classes with one important distinction:
the name of the record class is followed by a mandatory list of
components.  The list is enclosed in parentheses, it may be empty, and
it may immediately follow the name of the class or type parameters, if
any, with or without separating whitespace.  For example:

    public record Example(int i, String s) {
    }

    public record WithTypeParameters<A, B>(A a, B b, String s) {
    }

    record SpaceBeforeComponents (String comp1, int comp2) {
    }

Support records in the builtin userdiff pattern for Java.  Add "record"
to the alternatives of keywords for kinds of class.

Allowing matching various possibilities for the type parameters and/or
list of the components of a record has already been covered by the
preceding patch.

[1] detailed description is available in "JEP 395: Records"
    https://openjdk.org/jeps/395

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>
This commit is contained in:
Andrei Rybak 2023-02-08 00:42:58 +01:00 committed by Junio C Hamano
parent 39226a8dac
commit 575e6fcfcc
4 changed files with 20 additions and 2 deletions

6
t/t4018/java-record Normal file
View File

@ -0,0 +1,6 @@
public record RIGHT(int comp1, double comp2, String comp3) {
static int ONE;
static int TWO;
static int THREE;
static int ChangeMe;
}

View File

@ -0,0 +1,6 @@
public record RIGHT (String components, String after, String space) {
static int ONE;
static int TWO;
static int THREE;
static int ChangeMe;
}

View File

@ -0,0 +1,6 @@
public record RIGHT<A, N extends Number>(A comp1, N comp2, int comp3) {
static int ONE;
static int TWO;
static int THREE;
static int ChangeMe;
}

View File

@ -170,8 +170,8 @@ PATTERNS("html",
"[^<>= \t]+"),
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)[ \t]+.*)$\n"
/* Class, enum, interface, and record declarations */
"^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface|record)[ \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]*\\([^;]*)$",