palantir-java-format icon indicating copy to clipboard operation
palantir-java-format copied to clipboard

Improve formatting for stacked annotations

Open jerzozwierz opened this issue 4 years ago • 4 comments

What happened?

        public void foo(
                @FirstAnnotation(value = SOME_CONSTANT, another = "string")
                        @SecondAnnotation(
                                something = SOME_CONSTANT,
                                array = {"one", "two", "three"})
                        @ThirdAnnotation("value")
                        MyType whatever,
                 MyOtherType somethingElse) {
        }

It's a bit difficult to see why it got formatted this way?

What did you want to happen?

        public void foo(
                @FirstAnnotation(value = SOME_CONSTANT, another = "string")
                @SecondAnnotation(
                        something = SOME_CONSTANT,
                        array = {"one", "two", "three"})
                @ThirdAnnotation("value")
                MyType whatever,
                MyOtherType somethingElse) {
        }

When a parameter has multiple annotations, I'd like them to be aligned to the left.

jerzozwierz avatar Jun 23 '20 18:06 jerzozwierz

IMHO this would be an improvement. Want to submit a pr?

robert3005 avatar Jun 23 '20 18:06 robert3005

@robert3005 can you provide some guidance on how to get that implemented? I'm also interested.

renannprado avatar May 26 '22 16:05 renannprado

Not sure I can give you more beyond - start with a test case in https://github.com/palantir/palantir-java-format/tree/develop/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata and from there figure out where the formatter decides to add new indentation level

robert3005 avatar May 30 '22 12:05 robert3005

I think I prefer it the way it is, personally. You can scan the first column of the parameters and easily see their number / where each one's definition begins. With your desired example you have to take a moment (however short) to see if it's another annotation or not.

MatthewRyanRead avatar Jun 11 '22 20:06 MatthewRyanRead