Skip to content

Commit aa324c8

Browse files
committed
.
1 parent 96d304a commit aa324c8

7 files changed

Lines changed: 76 additions & 109 deletions

File tree

palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,15 @@ private void indentTextBlocks(TreeRangeMap<Integer, String> replacements, List<T
216216
StringBuilder output = new StringBuilder(initialLines.get(0).stripLeading());
217217
for (int i = 0; i < lines.size(); i++) {
218218
String line = lines.get(i);
219-
String trimmed = line.stripLeading();
220219
output.append(separator);
221-
if (!trimmed.isEmpty()) {
220+
if (!line.isEmpty()) {
222221
// Don't add incidental leading whitespace to empty lines
223222
output.append(prefix);
224223
}
225224
if (i == lines.size() - 1) {
226-
String withoutDelimiter = trimmed.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length())
225+
String withoutDelimiter = line.substring(0, line.length() - TEXT_BLOCK_DELIMITER.length())
227226
.stripTrailing();
228-
if (!withoutDelimiter.stripLeading().isEmpty()) {
227+
if (!withoutDelimiter.isEmpty()) {
229228
output.append(withoutDelimiter)
230229
.append('\\')
231230
.append(separator)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.helloworld;
22

33
class Foo {
4-
void foo() {
5-
var bar = """
4+
void foo() {
5+
var bar = """
66
bar\
7-
bar""";
8-
}
7+
bar\
8+
""";
9+
}
910
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.helloworld;
22

33
class Foo {
4-
void foo() {
5-
var bar =
6-
"""
4+
void foo() {
5+
var bar = """
76
bar\
87
bar\
98
""";
10-
}
9+
}
1110
}
Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
class RSLs {
2-
String a = """
3-
lorem
2+
String a = """
3+
lorem
44
ipsum
5-
""";
6-
String b = """
7-
lorem
8-
ipsum
5+
""";
6+
String b = """
7+
lorem
8+
ipsum
99
""";
10-
String c = """
11-
lorem
12-
ipsum
13-
""";
14-
String d = """
15-
ipsum
16-
""";
17-
String e = """
18-
""";
19-
String f = """
20-
ipsum""";
21-
String g = """
22-
lorem\
23-
ipsum
24-
""";
25-
String h = """
26-
lorem\
27-
ipsum\
28-
""";
29-
String i = """
30-
lorem
10+
String c = """
11+
lorem
12+
ipsum
13+
""";
14+
String d = """
15+
ipsum
16+
""";
17+
String e = """
18+
""";
19+
String f = """
20+
ipsum""";
21+
String g = """
22+
lorem\
23+
ipsum
24+
""";
25+
String h = """
26+
lorem\
27+
ipsum\
28+
""";
29+
String i = """
30+
lorem
3131

32-
ipsum
33-
""";
34-
String j = """
35-
lorem
36-
one long incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt
37-
ipsum
38-
""";
39-
String k = """
40-
lorem
41-
ipsum
42-
""";
43-
{
32+
ipsum
33+
""";
34+
String j = """
35+
lorem
36+
one long incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt
37+
ipsum
38+
""";
39+
String k = """
40+
lorem
41+
ipsum
42+
""";
43+
String l =
44+
"""
45+
foo
46+
bar
47+
baz""";
48+
{
4449
f("""
4550
lorem
4651
ipsum
@@ -69,11 +74,11 @@ ipsum
6974
""";
7075
String t =
7176
"""
72-
foo
73-
"""
74-
+ """
75-
bar
76-
""";
77+
foo
78+
"""
79+
+ """
80+
bar
81+
""";
7782
String u =
7883
stringVariableOne
7984
+
@@ -84,20 +89,9 @@ bar
8489
"""
8590
...
8691
""";
87-
}
92+
}
8893
String x = String.format("""
89-
1. when the block looks like a mustache array specification:
90-
maven-coordinates:
91-
%1$s#dependencyList%2$s
92-
- %1$sthis%2$s
93-
%1$s/dependencyList%2$s
94-
%3$s
95-
2. when the block looks like a mustache array specification:
96-
maven-coordinates: #%1$sdependencyList%2$s
97-
%3$s
98-
3. when the block is a simple template tag:
99-
maven-coordinates: %1$sdependencyList%2$s
100-
%3$s
94+
this very long string that does something using arguments %s %s %s
10195
""",
10296
"@", "@", "something");
10397
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/RSL.output

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class RSLs {
22
String a = """
33
lorem
4-
ipsum
4+
ipsum
55
""";
66
String b = """
77
lorem
@@ -39,9 +39,14 @@ class RSLs {
3939
ipsum
4040
""";
4141
String k = """
42-
lorem
43-
ipsum
44-
""";
42+
lorem
43+
ipsum
44+
""";
45+
String l = """
46+
foo
47+
bar
48+
baz\
49+
""";
4550

4651
{
4752
f("""
@@ -66,10 +71,10 @@ ipsum
6671
bar
6772
""";
6873
String t = """
69-
foo
70-
""" + """
71-
bar
72-
""";
74+
foo
75+
""" + """
76+
bar
77+
""";
7378
String u = stringVariableOne
7479
+ """
7580
...
@@ -82,18 +87,7 @@ bar
8287

8388
String x = String.format(
8489
"""
85-
1. when the block looks like a mustache array specification:
86-
maven-coordinates:
87-
%1$s#dependencyList%2$s
88-
- %1$sthis%2$s
89-
%1$s/dependencyList%2$s
90-
%3$s
91-
2. when the block looks like a mustache array specification:
92-
maven-coordinates: #%1$sdependencyList%2$s
93-
%3$s
94-
3. when the block is a simple template tag:
95-
maven-coordinates: %1$sdependencyList%2$s
96-
%3$s
90+
this very long string that does something using arguments %s %s %s
9791
""",
9892
"@", "@", "something");
9993
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/crogoz.input

Lines changed: 0 additions & 9 deletions
This file was deleted.

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/crogoz.output

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)