Skip to content

Generate more readable code for custom annotations #2895

Description

@filiphr

With PR #2792 we are generating custom annotations for the generated mappers.
The generated code currently looks like:

@CustomAnnotationWithParams(stringArray = "test", stringParam = "test", booleanArray = true, booleanParam = true, byteArray = 16, byteParam = 19, charArray = 'd', charParam = 'a', enumArray = AnnotateWithEnum.EXISTING, enumParam = AnnotateWithEnum.EXISTING, doubleArray = 0.3, doubleParam = 1.2, floatArray = 0.300000011920929f, floatParam = 1.2000000476837158f, intArray = 3, intParam = 1, longArray = 3L, longParam = 1L, shortArray = 3, shortParam = 1)

and

@CustomAnnotationWithParams(stringArray = { "test1", "test2" }, booleanArray = { false, true }, byteArray = { 8, 31 }, charArray = { 'b', 'c' }, doubleArray = { 1.2, 3.4 }, floatArray = { 1.2000000476837158f, 3.4000000953674316f }, intArray = { 12, 34 }, longArray = { 12L, 34L }, shortArray = { 12, 34 }, classArray = { Mapper.class, CustomAnnotationWithParams.class }, stringParam = "required parameter")

Everything is on one line.

I think that things would be more readable if we generate something like:

@CustomAnnotationWithParams(
    stringArray = "test",
    stringParam = "test",
    booleanArray = true,
    booleanParam = true,
    byteArray = 16,
    byteParam = 19,
    charArray = 'd',
    charParam = 'a',
    enumArray = AnnotateWithEnum.EXISTING,
    enumParam = AnnotateWithEnum.EXISTING,
    doubleArray = 0.3,
    doubleParam = 1.2,
    floatArray = 0.300000011920929f,
    floatParam = 1.2000000476837158f,
    intArray = 3,
    intParam = 1,
    longArray = 3L,
    longParam = 1L,
    shortArray = 3,
    shortParam = 1
)

and

@CustomAnnotationWithParams(
    stringArray = { "test1", "test2" },
    booleanArray = { false, true },
    byteArray = { 8, 31 },
    charArray = { 'b', 'c' },
    doubleArray = { 1.2, 3.4 },
    floatArray = { 1.2000000476837158f, 3.4000000953674316f },
    intArray = { 12, 34 },
    longArray = { 12L, 34L },
    shortArray = { 12, 34 },
    classArray = { Mapper.class, CustomAnnotationWithParams.class },
    stringParam = "required parameter"
)

We need to be smarter in the code generation and do not always generate multiple lines.

An annotation with single parameter should look like:

@CustomAnnotationWithParams( stringArray = "test" )

We also need to see how to generate elements with multiple values.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions