-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect user's existing splits in string concatenations (#192)
Preserve the user's newlines in a long string concatenation (defined as a concatenation with `+` where at least one expression is a literal string). Also allow inlining annotation values.
- Loading branch information
1 parent
08684cb
commit bab5f62
Showing
7 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type: improvement | ||
improvement: | ||
description: Preserve the user's newlines in a long string concatenation (defined | ||
as a concatenation with `+` where at least one expression is a literal string). | ||
links: | ||
- https://github.com/palantir/palantir-java-format/pull/192 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-10.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Palantir10 { | ||
// We preserve input newlines for this long string concatenation (more than 2 lines) | ||
@SqlUpdate("CREATE TABLE things " | ||
+ "(id VARCHAR(" + MAX_LENGTH + ") NOT NULL, " | ||
+ "title VARCHAR(" + MAX_LENGTH + ") NOT NULL, " | ||
+ "description VARCHAR(" + MAX_DESCRIPTION_LENGTH + ") NOT NULL, " | ||
+ "standard BOOLEAN NOT NULL, " | ||
+ "documentJson VARCHAR(" + MAX_DOCUMENT_LENGTH + ") NOT NULL, " | ||
+ "PRIMARY KEY (id))") | ||
void createTable(); | ||
|
||
void foo() { | ||
// Test that we still reflow short string concatenations (spanning exactly 2 lines) | ||
foo( | ||
"foo" | ||
+ "bar" + THING + "baz"); | ||
foo("foo" | ||
+ "bar" + THING + "baz"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...r-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-10.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Palantir10 { | ||
// We preserve input newlines for this long string concatenation (more than 2 lines) | ||
@SqlUpdate("CREATE TABLE things " | ||
+ "(id VARCHAR(" + MAX_LENGTH + ") NOT NULL, " | ||
+ "title VARCHAR(" + MAX_LENGTH + ") NOT NULL, " | ||
+ "description VARCHAR(" + MAX_DESCRIPTION_LENGTH + ") NOT NULL, " | ||
+ "standard BOOLEAN NOT NULL, " | ||
+ "documentJson VARCHAR(" + MAX_DOCUMENT_LENGTH + ") NOT NULL, " | ||
+ "PRIMARY KEY (id))") | ||
void createTable(); | ||
|
||
void foo() { | ||
// Test that we still reflow short string concatenations (spanning exactly 2 lines) | ||
foo("foo" + "bar" + THING + "baz"); | ||
foo("foo" + "bar" + THING + "baz"); | ||
} | ||
} |