|
45 | 45 | import com.sun.tools.javac.util.Position;
|
46 | 46 | import java.io.IOException;
|
47 | 47 | import java.io.UncheckedIOException;
|
48 |
| -import java.lang.reflect.Method; |
49 | 48 | import java.net.URI;
|
50 | 49 | import java.util.ArrayDeque;
|
51 | 50 | import java.util.ArrayList;
|
|
61 | 60 | import javax.tools.JavaFileObject;
|
62 | 61 | import javax.tools.SimpleJavaFileObject;
|
63 | 62 | import javax.tools.StandardLocation;
|
64 |
| -import org.jspecify.annotations.Nullable; |
65 | 63 |
|
66 | 64 | /** Wraps string literals that exceed the column limit. */
|
67 | 65 | public final class StringWrapper {
|
@@ -204,7 +202,7 @@ private void indentTextBlocks(
|
204 | 202 | // The first line of the text block is always """, and it does not affect incidental
|
205 | 203 | // whitespace.
|
206 | 204 | ImmutableList<String> initialLines = text.lines().collect(toImmutableList());
|
207 |
| - String stripped = stripIndent(initialLines.stream().skip(1).collect(joining(separator))); |
| 205 | + String stripped = initialLines.stream().skip(1).collect(joining(separator)).stripIndent(); |
208 | 206 | ImmutableList<String> lines = stripped.lines().collect(toImmutableList());
|
209 | 207 | int deindent =
|
210 | 208 | getLast(initialLines).stripTrailing().length()
|
@@ -280,30 +278,6 @@ private void wrapLongStrings(
|
280 | 278 | }
|
281 | 279 | }
|
282 | 280 |
|
283 |
| - private static final Method STRIP_INDENT = getStripIndent(); |
284 |
| - |
285 |
| - private static @Nullable Method getStripIndent() { |
286 |
| - if (Runtime.version().feature() < 15) { |
287 |
| - return null; |
288 |
| - } |
289 |
| - try { |
290 |
| - return String.class.getMethod("stripIndent"); |
291 |
| - } catch (NoSuchMethodException e) { |
292 |
| - throw new LinkageError(e.getMessage(), e); |
293 |
| - } |
294 |
| - } |
295 |
| - |
296 |
| - private static String stripIndent(String input) { |
297 |
| - if (STRIP_INDENT == null) { |
298 |
| - return input; |
299 |
| - } |
300 |
| - try { |
301 |
| - return (String) STRIP_INDENT.invoke(input); |
302 |
| - } catch (ReflectiveOperationException e) { |
303 |
| - throw new LinkageError(e.getMessage(), e); |
304 |
| - } |
305 |
| - } |
306 |
| - |
307 | 281 | /**
|
308 | 282 | * Returns the source text of the given string literal trees, excluding the leading and trailing
|
309 | 283 | * double-quotes and the `+` operator.
|
|
0 commit comments