git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Andrei Rybak <rybak.a.v@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Paolo Bonzini <pbonzini@redhat.com>,
	Johannes Sixt <j6t@kdbg.org>, Tassilo Horn <tsdh@gnu.org>
Subject: [PATCH v1 2/3] userdiff: support Java record types
Date: Sat,  4 Feb 2023 00:23:38 +0100	[thread overview]
Message-ID: <20230203232339.216592-3-rybak.a.v@gmail.com> (raw)
In-Reply-To: <20230203232339.216592-1-rybak.a.v@gmail.com>

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, without separating whitespace.

Code examples:

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

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

Support records in the builtin userdiff pattern for Java.  Add "record"
to the alternatives of keywords for kinds of class, and match an opening
parenthesis as the first character right after the type name.

An alternative approach could be to have an optional group that would
match both the opening and the closing parentheses with some way of
matching the declarations of the components.  Just use the simpler
regular expression for now.

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

Signed-off-by: Andrei Rybak <rybak.a.v@gmail.com>
---
 t/t4018/java-record                 | 6 ++++++
 t/t4018/java-record-type-parameters | 6 ++++++
 userdiff.c                          | 2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/java-record
 create mode 100644 t/t4018/java-record-type-parameters

diff --git a/t/t4018/java-record b/t/t4018/java-record
new file mode 100644
index 0000000000..97aa819dd8
--- /dev/null
+++ b/t/t4018/java-record
@@ -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;
+}
diff --git a/t/t4018/java-record-type-parameters b/t/t4018/java-record-type-parameters
new file mode 100644
index 0000000000..f62a035cc8
--- /dev/null
+++ b/t/t4018/java-record-type-parameters
@@ -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;
+}
diff --git a/userdiff.c b/userdiff.c
index 759e22ffff..f92b3029aa 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)[ \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


  parent reply	other threads:[~2023-02-03 23:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 23:23 [PATCH v1 0/3] userdiff: Java updates Andrei Rybak
2023-02-03 23:23 ` [PATCH v1 1/3] userdiff: support Java type parameters Andrei Rybak
2023-02-03 23:23 ` Andrei Rybak [this message]
2023-02-03 23:23 ` [PATCH v1 3/3] userdiff: support Java sealed classes Andrei Rybak
2023-02-04  9:22 ` [PATCH v1 0/3] userdiff: Java updates Tassilo Horn
2023-02-04 13:43   ` [PATCH v2 " Andrei Rybak
2023-02-04 13:43     ` [PATCH v2 1/3] userdiff: support Java type parameters Andrei Rybak
2023-02-04 13:43     ` [PATCH v2 2/3] userdiff: support Java record types Andrei Rybak
2023-02-04 13:43     ` [PATCH v2 3/3] userdiff: support Java sealed classes Andrei Rybak
2023-02-05 10:09     ` [PATCH v2 0/3] userdiff: Java updates Johannes Sixt
2023-02-05 19:27       ` Andrei Rybak
2023-02-05 21:33         ` Johannes Sixt
2023-02-07 23:42           ` [PATCH v3 " Andrei Rybak
2023-02-07 23:42             ` [PATCH v3 1/3] userdiff: support Java type parameters Andrei Rybak
2023-02-08  0:04               ` Andrei Rybak
2023-02-07 23:42             ` [PATCH v3 2/3] userdiff: support Java record types Andrei Rybak
2023-02-07 23:42             ` [PATCH v3 3/3] userdiff: support Java sealed classes Andrei Rybak
2023-02-08 20:51             ` [PATCH v3 0/3] userdiff: Java updates Johannes Sixt
2023-02-08 20:55               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230203232339.216592-3-rybak.a.v@gmail.com \
    --to=rybak.a.v@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=pbonzini@redhat.com \
    --cc=peff@peff.net \
    --cc=tsdh@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).