Skip to content
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

Refactor codebase to use textblocks instead of multiline string concatenation #1186

Open
HoussemNasri opened this issue Sep 18, 2024 · 1 comment

Comments

@HoussemNasri
Copy link
Member

HoussemNasri commented Sep 18, 2024

The codebase contains many instances of multiline string concatenation, especially in testing classes when hardcoded JSON strings are defined. This leads to hard to read/maintan code like this:

"{" +
        "  \"newUser\":\"geraldine\"," +
        "  \"oldUser\":\"user\"," +
        "  \"status\":{" +
        "    \"A\":\"DONE\"," +
        "    \"B\":\"WAITING\"," +
        "    \"C\":\"FAILED\"," +
        "    \"D\":\"ABORTED\"}," +
        "  \"timestamp\":\"2018-11-13T12:00:55Z\"," +
        "  \"type\":\"UsernameChangeTask\"" +
        "}"

Text blocks is a new feature introduced in Java 15 that fixes this exact problem, turning the above string to:

"""
            {
              "newUser":"geraldine",
              "oldUser":"user",
              "status":{
                "A":"DONE",
                "B":"WAITING",
                "C":"FAILED",
                "D":"ABORTED"},
              "timestamp":"2018-11-13T12:00:55Z",
              "type":"UsernameChangeTask"
            }"""
""""                  

Automated mass refactoring tools such as Rewrite could be of use, especially the UseTextBlocks recipe.

When text blocks are used one could use IntelliJ's language injection feature to add syntax highlighting and error detection when dealing with JSON strings.

@chibenwa
Copy link
Member

+1

Needs to idealy be discussed on the James mailing list.

Ok as long as we do not rely on Java string templates whose JEP is removed in Java 23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants