Skip to content
Merged
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 @@ -45,7 +45,6 @@
import com.sun.tools.javac.util.Position;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand All @@ -61,7 +60,6 @@
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardLocation;
import org.jspecify.annotations.Nullable;

/** Wraps string literals that exceed the column limit. */
public final class StringWrapper {
Expand Down Expand Up @@ -204,7 +202,7 @@ private void indentTextBlocks(
// The first line of the text block is always """, and it does not affect incidental
// whitespace.
ImmutableList<String> initialLines = text.lines().collect(toImmutableList());
String stripped = stripIndent(initialLines.stream().skip(1).collect(joining(separator)));
String stripped = initialLines.stream().skip(1).collect(joining(separator)).stripIndent();
ImmutableList<String> lines = stripped.lines().collect(toImmutableList());
int deindent =
getLast(initialLines).stripTrailing().length()
Expand Down Expand Up @@ -280,30 +278,6 @@ private void wrapLongStrings(
}
}

private static final Method STRIP_INDENT = getStripIndent();

private static @Nullable Method getStripIndent() {
if (Runtime.version().feature() < 15) {
return null;
}
try {
return String.class.getMethod("stripIndent");
} catch (NoSuchMethodException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static String stripIndent(String input) {
if (STRIP_INDENT == null) {
return input;
}
try {
return (String) STRIP_INDENT.invoke(input);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

/**
* Returns the source text of the given string literal trees, excluding the leading and trailing
* double-quotes and the `+` operator.
Expand Down
Loading