-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reformat of record wrongly indents closing brace #7043
Comments
homberghp
added
kind:bug
Bug report or fix
needs:triage
Requires attention from one of the committers
labels
Feb 8, 2024
mbien
added
Java
[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Editor
and removed
needs:triage
Requires attention from one of the committers
labels
Feb 8, 2024
New findings after adding tests.I also noted that the formatting of records also drops a space before the closing parenthesis in the record header. I expected this
but got
that is, the space after |
homberghp
added a commit
to homberghp/netbeans
that referenced
this issue
Dec 19, 2024
to show the effect of propery spaceswithinMethodDeclaration on record. See issue apache#7043. moved Sample spaces from bundle to text block. To show effect of apache#7043. added test RecordFormattingTest to show problem \apache#7043 There are two tests in the test class, one that passws with the spaceWithinMethodDeclParens set to false, and one that fails when this is set to true.
homberghp
added a commit
to homberghp/netbeans
that referenced
this issue
Dec 27, 2024
solves missing space before closing RPAREN in record.
homberghp
added a commit
to homberghp/netbeans
that referenced
this issue
Dec 27, 2024
Indetantion of the closing brace of a record was off and dependent of preference spaceWithinMethodDeclParens. fixed in Java Source Base/org.netbeans.modules.java.source.save.Reformatter. Tests added in file org.netbeans.modules.java.source.save.RecordFormattingTest
homberghp
added a commit
to homberghp/netbeans
that referenced
this issue
Dec 30, 2024
…ition adds tests to show the error adds inner and outer record in ui template text for setting java format spaces solves the error by moving spaces(cs.spaceWithinMethodDeclParens() ? 1 : 0, true); to the correct place. solves apache#7043 formatter to handle record closing braces correctly squashed commits of test and solution.
mbien
pushed a commit
to mbien/netbeans
that referenced
this issue
Jan 2, 2025
…ition adds tests to show the error adds inner and outer record in ui template text for setting java format spaces solves the error by moving spaces(cs.spaceWithinMethodDeclParens() ? 1 : 0, true); to the correct place. solves apache#7043 formatter to handle record closing braces correctly squashed commits of test and solution.
mbien
added a commit
to mbien/netbeans
that referenced
this issue
Jan 2, 2025
…ition - adds tests to show the error - adds inner and outer record in ui template text for setting java format spaces - solves the error by moving spaces(cs.spaceWithinMethodDeclParens() ? 1 : 0, true); to the correct place. Co-authored-by: Michael Bien <mbien42@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apache NetBeans version
Apache NetBeans > 12 (all that support java 14)
What happened
when you have a record, say
and you press reformat, then the resulting code looks like this:
with the last brace at the wrong place.
This happens if I set spaces within method declaration in the
Options > editor> formatting> spaces > checkbox "method declarations", see below.
I like my code spacious so both in method declaration and calls, because I consider readability paramount.
Language / Project Type / NetBeans Component
java editor
How to reproduce
turn on within parenthesis> Method Declaration and reformat with the well know shortcut or menu.
Shortcut is on my machine.
Did this work correctly in an earlier version?
No / Don't know
Operating System
Linux Ubuntu 22.04 LTS
Windows 11 with Java 21, Netbeans 20
JDK
all since 14
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
The problem is always there and repeatably reproducible.
If I had a clue how this reformating is implemented I might be able to write a pull request.
For me the reformat tries to be too smart, and considers the code in the record before the first parenthesis as a method declaration too (which it is more or less) and becomes confused when it finds a method declaration before the opening brace of a class, in this case a record.
I would be fine to put spaces inside all pairs of <>, (), [], {}, but that might not be to everyone's taste.
Are you willing to submit a pull request?
No, missing doc on where to find the problem.
The text was updated successfully, but these errors were encountered: