Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,25 @@ public final class StringWrapper {

public static final String TEXT_BLOCK_DELIMITER = "\"\"\"";

/**
* How many times {@link #wrapOnce} may be re-run while it is still changing the source. The indentation chosen
* for a text block is derived from the layout around it, which this pass can itself move, so a single round is
* not always a fixed point and the formatter would not be idempotent. See
* <a href="https://github.com/palantir/open-java-format/issues/1343">#1343</a>.
*/
private static final int MAX_ROUNDS = 5;

/** Reflows string literals in the given Java source code that extend past the given column limit. */
static String wrap(final int columnLimit, String input, Formatter formatter) throws FormatterException {
String result = wrapOnce(columnLimit, input, formatter);
for (int round = 1; round < MAX_ROUNDS && !result.equals(input); round++) {
input = result;
result = wrapOnce(columnLimit, input, formatter);
}
return result;
}

private static String wrapOnce(final int columnLimit, String input, Formatter formatter) throws FormatterException {
if (!needWrapping(columnLimit, input)) {
// fast path
return input;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class T {
void f() {
LOGGER.warning(String.format("""
@Gauge is configured on a bean %s that is neither ApplicationScoped nor \
Singleton. This is most likely a bug. You may set 'metrics.warn-dependent' \
configuration option to 'false' to remove this warning.""", clazz.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class T {
void f() {
LOGGER.warning(String.format("""
@Gauge is configured on a bean %s that is neither ApplicationScoped nor \
Singleton. This is most likely a bug. You may set 'metrics.warn-dependent' \
configuration option to 'false' to remove this warning.\
""", clazz.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class TernaryBug {
boolean flag = true;

String a = flag
? """
yes
"""
: """
no
""";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TernaryBug {
boolean flag = true;

String a = flag ? """
yes
""" : """
no
""";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class PalantirIssue1343TextBlockIndentStable {
String[][] withCommentFirstLine = {
{
"""
// tmp fix
@Deprecated
class Test {}
"""
},
{
"""

@Deprecated
class Test {}
"""
}
};

String[][] blankLineInTheMiddle = {
{
"""
import java.util.List;

@Deprecated
class Test {}
"""
},
{
"""

class Test {}
"""
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class PalantirIssue1343TextBlockIndentStable {
String[][] withCommentFirstLine = {{"""
// tmp fix
@Deprecated
class Test {}
"""}, {"""

@Deprecated
class Test {}
"""}};

String[][] blankLineInTheMiddle = {{"""
import java.util.List;

@Deprecated
class Test {}
"""}, {"""

class Test {}
"""}};
}
Loading