Skip to content

reformat of record wrongly indents closing brace #7043

@homberghp

Description

@homberghp

Apache NetBeans version

Apache NetBeans > 12 (all that support java 14)

What happened

when you have a record, say

record Student( String id, String lastname, String firstname, LocalDate dob ) implements Serializable, Wither<Student, StudentBuilder> {

    @Override
    public StudentBuilder with() {
        return new StudentBuilder(this);
    }

}

and you press reformat, then the resulting code looks like this:

record Student( String id, String lastname, String firstname, LocalDate dob) implements Serializable, Wither<Student, StudentBuilder> {

    @Override
    public StudentBuilder with() {
        return new StudentBuilder( this );
    }

    } // indented wrongly

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.

image

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.

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EditorJava[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)kind:bugBug report or fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions