Skip to content

Commit 575e6fc

Browse files
rybakgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39226a8 commit 575e6fc

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

t/t4018/java-record

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public record RIGHT(int comp1, double comp2, String comp3) {
2+
static int ONE;
3+
static int TWO;
4+
static int THREE;
5+
static int ChangeMe;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public record RIGHT (String components, String after, String space) {
2+
static int ONE;
3+
static int TWO;
4+
static int THREE;
5+
static int ChangeMe;
6+
}

t/t4018/java-record-type-parameters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public record RIGHT<A, N extends Number>(A comp1, N comp2, int comp3) {
2+
static int ONE;
3+
static int TWO;
4+
static int THREE;
5+
static int ChangeMe;
6+
}

userdiff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ PATTERNS("html",
170170
"[^<>= \t]+"),
171171
PATTERNS("java",
172172
"!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
173-
/* Class, enum, and interface declarations */
174-
"^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface)[ \t]+.*)$\n"
173+
/* Class, enum, interface, and record declarations */
174+
"^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n"
175175
/* Method definitions; note that constructor signatures are not */
176176
/* matched because they are indistinguishable from method calls. */
177177
"^[ \t]*(([A-Za-z_<>&][][?&<>.,A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",

0 commit comments

Comments
 (0)