From patchwork Tue Feb 7 23:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Rybak X-Patchwork-Id: 13132216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83A0BC636CD for ; Tue, 7 Feb 2023 23:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbjBGXnK (ORCPT ); Tue, 7 Feb 2023 18:43:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbjBGXnI (ORCPT ); Tue, 7 Feb 2023 18:43:08 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4912618AB4 for ; Tue, 7 Feb 2023 15:43:07 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id q19so18346979edd.2 for ; Tue, 07 Feb 2023 15:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1BLFt0zcHRIjKEnapqb2muIO1OhPrUabIFt7ghKd7n4=; b=ZJL0TNxZt7dbm2S1ybo2hwswPNa2/MKATDTu1gAqoEsGjKiXUIiM/e/3lcURzfOaUa KXq3IYTKhLH7qeCgBMB7mJi4OYH4hM0s7ZKpB6zDcJdRNFlW1df1qN9o7ahQrqPDdOC4 ug2cMLdI3pfcPTtfVoARh6+X0SYyIwkMjuksFBabIOf7GAYvaAx8BKsIRhVHFU944MEX /R3pOot3sdQaleQdEHUSyZrj3k8Uxkun7pt9EAnRqKJKt76dIKI9jlnmIi4m/q/xEAkM N/ZXAYxD48eLvbRO4bCWsYny2HNTVmH5f2RPUUuFHgr3IuPXZjkVEey895H4c8HY1EsO 32Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1BLFt0zcHRIjKEnapqb2muIO1OhPrUabIFt7ghKd7n4=; b=NYt37aOCseRzI4Qi9Q79BVCP2MZVGbpYMnXMDyGgmAZgEykKRyc+k2C8jjqCosCGQ1 UIkBjq9H7T5Aq0RxKq2nWRGOWdwnq57jiIQKUymNwzp0TsYjT3jUEFWTM3ij65GBai11 eFB9ACg9Npr65ZBDuonNlMbX0WRXEJkP8cPPBj2uxv8DQCSVV2FH0rkBHRwZaHC3slf5 syu0u0HIDmQFS3NQQPrf13aaopbmG0/Al23QOo0UjfxJpVmGrRHKFRoGsNZMF0aKhqWl +THNWZgdLk3BQPZaw/mZM1nRQMUDad+0fvx18Dv/dAODq7g4HElmJeW9WcSoWOR2sTgq kVzw== X-Gm-Message-State: AO0yUKWuNWOCbZI/dpeY055tppR8ck1wS4hii9DQJwt29Zo+8BojxqHp gDjZCCLX05utsRrS45hc8CzAKQ7IgJBnLoJrQsc= X-Google-Smtp-Source: AK7set8mSo9ZSxwaoFTgCHc+Qs14kuFy4CKsaKjVTEm+IMj2veH5bV3Ex1lvVPb96KwzgWp3/rp4nA== X-Received: by 2002:a50:ce4e:0:b0:4aa:c355:bc92 with SMTP id k14-20020a50ce4e000000b004aac355bc92mr5211620edj.32.1675813385647; Tue, 07 Feb 2023 15:43:05 -0800 (PST) Received: from titov.fritz.box ([181.214.173.18]) by smtp.gmail.com with ESMTPSA id x91-20020a50bae4000000b0049b58744f93sm5346198ede.81.2023.02.07.15.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 15:43:05 -0800 (PST) From: Andrei Rybak To: Johannes Sixt , git@vger.kernel.org Cc: Jeff King , Paolo Bonzini , Tassilo Horn Subject: [PATCH v3 1/3] userdiff: support Java type parameters Date: Wed, 8 Feb 2023 00:42:57 +0100 Message-Id: <20230207234259.452141-2-rybak.a.v@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207234259.452141-1-rybak.a.v@gmail.com> References: <64601c4b-9ced-672f-a5fd-9a9b3b65859d@kdbg.org> <20230207234259.452141-1-rybak.a.v@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A class or interface in Java can have type parameters following the name in the declared type, surrounded by angle brackets (paired less than and greater than signs).[2] The type parameters -- `A` and `B` in the examples -- may follow the class name immediately: public class ParameterizedClass { } or may be separated by whitespace: public class SpaceBeforeTypeParameters { } A part of the builtin userdiff pattern for Java matches declarations of classes, enums, and interfaces. The regular expression requires at least one whitespace character after the name of the declared type. This disallows matching for opening angle bracket of type parameters immediately after the name of the type. Mandatory whitespace after the name of the type also disallows using the pattern in repositories with a fairly common code style that puts braces for the body of a class on separate lines: class WithLineBreakBeforeOpeningBrace { } Support matching Java code in more diverse code styles and declarations of classes and interfaces with type parameters immediately following the name of the type in the builtin userdiff pattern for Java. Do so by just matching anything until the end of the line after the keywords for the kind of type being declared. [1] Since Java 5 released in 2004. [2] Detailed description is available in the Java Language Specification, sections "Type Variables" and "Parameterized Types": https://docs.oracle.com/javase/specs/jls/se17/html/jls-4.html#jls-4.4 Signed-off-by: Andrei Rybak --- t/t4018/java-class-brace-on-separate-line | 6 ++++++ t/t4018/java-class-space-before-type-parameters | 6 ++++++ t/t4018/java-class-type-parameters | 6 ++++++ t/t4018/java-class-type-parameters-implements | 6 ++++++ t/t4018/java-interface-type-parameters | 6 ++++++ t/t4018/java-interface-type-parameters-extends | 6 ++++++ userdiff.c | 2 +- 7 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 t/t4018/java-class-brace-on-separate-line create mode 100644 t/t4018/java-class-space-before-type-parameters create mode 100644 t/t4018/java-class-type-parameters create mode 100644 t/t4018/java-class-type-parameters-implements create mode 100644 t/t4018/java-interface-type-parameters create mode 100644 t/t4018/java-interface-type-parameters-extends diff --git a/t/t4018/java-class-brace-on-separate-line b/t/t4018/java-class-brace-on-separate-line new file mode 100644 index 0000000000..8795acd4cf --- /dev/null +++ b/t/t4018/java-class-brace-on-separate-line @@ -0,0 +1,6 @@ +class RIGHT +{ + static int ONE; + static int TWO; + static int ChangeMe; +} diff --git a/t/t4018/java-class-space-before-type-parameters b/t/t4018/java-class-space-before-type-parameters new file mode 100644 index 0000000000..0bdef1dfbe --- /dev/null +++ b/t/t4018/java-class-space-before-type-parameters @@ -0,0 +1,6 @@ +class RIGHT { + static int ONE; + static int TWO; + static int THREE; + private A ChangeMe; +} diff --git a/t/t4018/java-class-type-parameters b/t/t4018/java-class-type-parameters new file mode 100644 index 0000000000..579aa7af21 --- /dev/null +++ b/t/t4018/java-class-type-parameters @@ -0,0 +1,6 @@ +class RIGHT { + static int ONE; + static int TWO; + static int THREE; + private A ChangeMe; +} diff --git a/t/t4018/java-class-type-parameters-implements b/t/t4018/java-class-type-parameters-implements new file mode 100644 index 0000000000..b8038b1866 --- /dev/null +++ b/t/t4018/java-class-type-parameters-implements @@ -0,0 +1,6 @@ +class RIGHT implements List { + static int ONE; + static int TWO; + static int THREE; + private A ChangeMe; +} diff --git a/t/t4018/java-interface-type-parameters b/t/t4018/java-interface-type-parameters new file mode 100644 index 0000000000..a4baa1ae68 --- /dev/null +++ b/t/t4018/java-interface-type-parameters @@ -0,0 +1,6 @@ +interface RIGHT { + static int ONE; + static int TWO; + static int THREE; + public B foo(A ChangeMe); +} diff --git a/t/t4018/java-interface-type-parameters-extends b/t/t4018/java-interface-type-parameters-extends new file mode 100644 index 0000000000..31d7fb3244 --- /dev/null +++ b/t/t4018/java-interface-type-parameters-extends @@ -0,0 +1,6 @@ +interface RIGHT extends Function { + static int ONE; + static int TWO; + static int THREE; + public B foo(A ChangeMe); +} diff --git a/userdiff.c b/userdiff.c index d71b82feb7..bc5f3ed4c3 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)[ \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]*\\([^;]*)$", From patchwork Tue Feb 7 23:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Rybak X-Patchwork-Id: 13132217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0FF4C636D6 for ; Tue, 7 Feb 2023 23:43:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbjBGXnM (ORCPT ); Tue, 7 Feb 2023 18:43:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjBGXnJ (ORCPT ); Tue, 7 Feb 2023 18:43:09 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1602BEC5 for ; Tue, 7 Feb 2023 15:43:08 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id l12so9423869edb.0 for ; Tue, 07 Feb 2023 15:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sh/5RfxuA5CtofeNDLPSVDYesgwiWwnSV2BK7dWzn8Y=; b=iexCTW3YlK6gR2dXToXQFK53J+5b3sIxYqpXKm3vO2VxIQfbziCUfR7ZDmMtBa2XI6 MdLM/ZhgWTo4xdllU15xebRe3fMU2NqWjaw0XzLPuOEJe7CDk96pwxpqt5t1LHs24Ahn YR0diqLJvs7JAbkglmvdjp7Nhhhy1fYbvVyzIOUWkk/FYbz9FrK0sJUabh93UCzR5Btn m1JHbiGfBZrCo2AvTGl7SaNE4hmSLPHdXCML0FJebfgA8fF53AzepCGqdptE0PiBphnr 4N+WApb9T8RxfsHIOLfC/6KNsge7LZ6ePL+gPE+S3kNnLy/UBy4ZPXutUXRrcKfQylnp w2cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sh/5RfxuA5CtofeNDLPSVDYesgwiWwnSV2BK7dWzn8Y=; b=N9cHdry0cNLlyTbYbft8KCZ4JiX24SXTZrbHq2MyqKwjA5t2A35XCiEG0h+WD5Asrq bTxwPyCh40b7LciDIBugh1l+yvW2CZL+FD0TIoHi4rVsNvXN0sd8amLHiAyICsXq86oM QAAi6uqDvZQW+HDqOJlbwLIPUI8HZV9rH40QffUr20wVrfyDsbIeiQ67DvKUQL7cts60 sbgpc6YZD4XP0sWuZtEIV0Rt03OqlBwOtBvUhzY+mlymUeMI/kjnjdWRynho2WKBpr+c vPtW3iOrGcm+awURZbLKQpsBq2ivxyy4ANED3z7jK1U9OEejRbYn12eXquuB2146zgj9 jlkg== X-Gm-Message-State: AO0yUKWqe9KluZDi8F0z6ageLWGhNoZNZ83dRltq6BMKj3GfVZrwsb40 HnGLk97HUsqXUwYxDajqhtdKdjBFv7EtHJZ3Z+E= X-Google-Smtp-Source: AK7set+4SSIc2AsoCEexAHWcuMK0JBDLBHaE6wpOgUy9PpS3b9bxH+yKReAwPuCKB5u5UT7kcjBLvA== X-Received: by 2002:a05:6402:540f:b0:4aa:b228:eb72 with SMTP id ev15-20020a056402540f00b004aab228eb72mr843815edb.17.1675813386799; Tue, 07 Feb 2023 15:43:06 -0800 (PST) Received: from titov.fritz.box ([181.214.173.18]) by smtp.gmail.com with ESMTPSA id x91-20020a50bae4000000b0049b58744f93sm5346198ede.81.2023.02.07.15.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 15:43:06 -0800 (PST) From: Andrei Rybak To: Johannes Sixt , git@vger.kernel.org Cc: Jeff King , Paolo Bonzini , Tassilo Horn Subject: [PATCH v3 2/3] userdiff: support Java record types Date: Wed, 8 Feb 2023 00:42:58 +0100 Message-Id: <20230207234259.452141-3-rybak.a.v@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207234259.452141-1-rybak.a.v@gmail.com> References: <64601c4b-9ced-672f-a5fd-9a9b3b65859d@kdbg.org> <20230207234259.452141-1-rybak.a.v@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 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 --- t/t4018/java-record | 6 ++++++ t/t4018/java-record-space-before-components | 6 ++++++ t/t4018/java-record-type-parameters | 6 ++++++ userdiff.c | 4 ++-- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 t/t4018/java-record create mode 100644 t/t4018/java-record-space-before-components 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-space-before-components b/t/t4018/java-record-space-before-components new file mode 100644 index 0000000000..9827f22583 --- /dev/null +++ b/t/t4018/java-record-space-before-components @@ -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; +} 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 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 bc5f3ed4c3..37ac98e177 100644 --- a/userdiff.c +++ b/userdiff.c @@ -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]*\\([^;]*)$", From patchwork Tue Feb 7 23:42:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Rybak X-Patchwork-Id: 13132218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8262AC636CD for ; Tue, 7 Feb 2023 23:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbjBGXnW (ORCPT ); Tue, 7 Feb 2023 18:43:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbjBGXnK (ORCPT ); Tue, 7 Feb 2023 18:43:10 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16ADB13DC1 for ; Tue, 7 Feb 2023 15:43:09 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id eq11so18313981edb.6 for ; Tue, 07 Feb 2023 15:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+LIWKiW7QQxRLQ9r+sdkAt5JGoFAgN4QRG4LmIfEqy0=; b=f1XmQxiFOpPwnlUPgh52INwQRmqHukDphNFEIi72U1jbktjuhfBCSVbQlKhNToc/RN 4jN8rSL/NPBNwELk2oxislaGa1LyZzoqE2Et9jpFiHhz7fTWV+9uqz+2oUn2wgQQ7d4F KAe0Ho3+ZxGGqDQUa/EELbJYPXK5x2sokMpwvt/54Pc0irxIL5p9b4zsdDJHA/MXer51 89rFDG1e1HYu1pVgs3KekgpLs5/8mQ08w9YRSwVWL9e2X/wih+1Pie5QMKcLib4TDzqz 0sN1BvcUE1yZ76W+NH5gvEudg2vmdfxe8HY5c//xwGC3L7mi2kt6GS24r/sOwmioLMv5 2LeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+LIWKiW7QQxRLQ9r+sdkAt5JGoFAgN4QRG4LmIfEqy0=; b=TM2zKN5ghvUwBHZE7IuuNwVNr5LhiaGdbuI9d5UwxwvABjQ/3kdW/lvyEzX4FO5Cme b341cbanjhUfzfb7O9xpaZo7qIFZr8OSAzyUNi//t1foQkFLInH7AoO6Bq+uOU9RFnL/ yVNu+6T+PJpY7xFou2rlUjWyvN9D18d/1VCnx/AmOZNfx7tcmD60++n4tg1XqvG89l4P oJVpceyF7iK7M+ZwoYgVMmwrftXi97UPYxzO1sou41rdGKHE9yK6jboSmIVQC1iKTr/z wC19HbnK7lBpHdGcOiitJ7GumauoWNR+QCVFmfuVBAQxmyzEIdjCXhNhuooxE1MzLFgP de7Q== X-Gm-Message-State: AO0yUKWoUreo9s3/XLC5E5x//8SsnRfc6O/GYYq+hDRJO4zcnMhVm/CM sU+nr7ZubgV1CpFalqJoDCg= X-Google-Smtp-Source: AK7set9YpSAs/qvMWd5RGMuLIkHT0WprNeYQqru70U5rvI9uEcY+90nJ3L0qePA0Wpn6oWmRFz106w== X-Received: by 2002:a50:d7cd:0:b0:4a0:af87:b3ab with SMTP id m13-20020a50d7cd000000b004a0af87b3abmr5212214edj.36.1675813387636; Tue, 07 Feb 2023 15:43:07 -0800 (PST) Received: from titov.fritz.box ([181.214.173.18]) by smtp.gmail.com with ESMTPSA id x91-20020a50bae4000000b0049b58744f93sm5346198ede.81.2023.02.07.15.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 15:43:07 -0800 (PST) From: Andrei Rybak To: Johannes Sixt , git@vger.kernel.org Cc: Jeff King , Paolo Bonzini , Tassilo Horn Subject: [PATCH v3 3/3] userdiff: support Java sealed classes Date: Wed, 8 Feb 2023 00:42:59 +0100 Message-Id: <20230207234259.452141-4-rybak.a.v@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207234259.452141-1-rybak.a.v@gmail.com> References: <64601c4b-9ced-672f-a5fd-9a9b3b65859d@kdbg.org> <20230207234259.452141-1-rybak.a.v@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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..069087c1c6 --- /dev/null +++ b/t/t4018/java-non-sealed @@ -0,0 +1,8 @@ +public abstract sealed 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..785fbc62bc --- /dev/null +++ b/t/t4018/java-sealed @@ -0,0 +1,7 @@ +public abstract sealed 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..18dd4894cf --- /dev/null +++ b/t/t4018/java-sealed-permits @@ -0,0 +1,6 @@ +public abstract sealed 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..e6530c47c3 --- /dev/null +++ b/t/t4018/java-sealed-type-parameters @@ -0,0 +1,6 @@ +public abstract sealed class RIGHT { + 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..bd6e6d3582 --- /dev/null +++ b/t/t4018/java-sealed-type-parameters-implements-permits @@ -0,0 +1,6 @@ +public abstract sealed class RIGHT implements List 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..25a0da6442 --- /dev/null +++ b/t/t4018/java-sealed-type-parameters-permits @@ -0,0 +1,6 @@ +public abstract sealed class RIGHT permits PermittedA, PermittedB { + static int ONE; + static int TWO; + static int THREE; + private int ChangeMe; +} diff --git a/userdiff.c b/userdiff.c index 37ac98e177..94cca1a2a8 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, interface, and record declarations */ - "^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n" + "^[ \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]*\\([^;]*)$",