git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 0/3] userdiff: Java updates

From
Andrei Rybak <rybak.a.v@gmail.com>
Date
Feb 5, 2023, 19:27 UTC
Message-ID
<6ca6ebf0-b357-e1d0-4866-dd04a5f987ad@gmail.com>
In-Reply-To
<45830cf4-41c1-0bc1-3e4e-26b9f713f452@kdbg.org>
On 2023-02-05T11:09, Johannes Sixt wrote:
Show 19 quoted lines
> Am 04.02.23 um 14:43 schrieb Andrei Rybak:
>> On 04/02/2023 10:22, Tassilo Horn wrote:
>>> Thanks for including me being the last contributor to java userdiff.
>>> The patches look good from my POV and are safe-guarded with tests, so
>>> I'm all for it.
>>
>> Thank you for review!
>>
>> I've realized that I've been writing modifiers "abstract" and "sealed" in a
>> technically correct, but not the conventional order.  Here's a reroll with the
>> order of modifiers following the style of original authors of
>> https://openjdk.org/jeps/409.  It doesn't matter for the purposes of the test,
>> but it will be less annoying to any future readers :-)
> 
> I've looked through the patches and run the tests, and they all make
> sense to me. By just looking at the patch text I noted that no
> whitespace between the identifier and the opening angle bracket is
> permitted and whether it should be allowed, but the commit messages make
> quite clear that whitespace is not allowed in this position.

There is some kind of misunderstanding. I guess the wording in commit messages of the first and second patches could have been clearer.

In Java, whitespace is allowed between type name and the brackets. It is permitted both for angle brackets of type parameters:

	class SpacesBeforeTypeParameters         <A, B> {
	}
and for round brackets of components in records:
	record SpacesBeforeComponents      (String comp1, int comp2) {
	}

The common convention, is however, to omit the whitespace before the brackets.

The regular expression on branch master already allows for whitespace after the name of the type:

	"^[ \t]*(([a-z]+[ \t]+)*(class|enum|interface)[ \t]+[A-Za-z][A-Za-z0-9_$]*[ \t]+.*)$\n"
	                                                                          ^^^^^^
so I didn't need to cover this case.  Note that it requires a non-zero
amount of whitespace. This part of the regular expression was left as
is (v2 after patch 3/3):
	"^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+[A-Za-z][A-Za-z0-9_$]*([ \t]+|[<(]).*)$\n"
	                                                                                   ^^^^^^

That being said, I guess it would be an improvement to also allow the name of the type be followed by the end of the line, for users with fairly common code style that puts braces on separate lines:

	class WithLineBreakBeforeOpeningBrace
	{
	}
or `extends` and `implements` clauses after a line break:
	class ExtendsOnSeparateLine
		extends Number
		implements Serializable
	{
	}
even type parameters:
	class TypeParametersOnSeparateLine
		<A, B>
	{
	}
Something like the following:
	"^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+[A-Za-z][A-Za-z0-9_$]*(([ \t]+|[<(]).*)?)$\n"
	                                                                                  ^               ^^
perhaps? Technically, the following is also valid Java:
	class WithComment//comment immediately after class name
	{
	}
but I'm not sure if allowing it is needed.  If so, we might as well just do this:
	"^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+[A-Za-z][A-Za-z0-9_$]*.*)$\n"
	                                                                                  ^^
Previous: Johannes SixtNext: Johannes Sixt
Message 11 of 19 in “userdiff: Java updates”
  1. 0/3 userdiff: Java updatesAndrei Rybak, Feb 3, 2023
  2. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 3, 2023
  3. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 3, 2023
  4. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 3, 2023
  5. Tassilo HornFeb 4, 2023
  6. 0/3 userdiff: Java updatesAndrei Rybak, Feb 4, 2023
  7. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 4, 2023
  8. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 4, 2023
  9. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 4, 2023
  10. Johannes SixtFeb 5, 2023
  11. Andrei RybakFeb 5, 2023
  12. Johannes SixtFeb 5, 2023
  13. 0/3 userdiff: Java updatesAndrei Rybak, Feb 7, 2023
  14. 1/3 userdiff: support Java type parametersAndrei Rybak, Feb 7, 2023
  15. Andrei RybakFeb 8, 2023
  16. 2/3 userdiff: support Java record typesAndrei Rybak, Feb 7, 2023
  17. 3/3 userdiff: support Java sealed classesAndrei Rybak, Feb 7, 2023
  18. Johannes SixtFeb 8, 2023
  19. Junio C HamanoFeb 8, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.