From a6e5bd96de304510d0d338ae1dd149114f3e3a78 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Fri, 22 Nov 2024 11:29:59 -0800 Subject: [PATCH] Remove some unnecessary reflection now that the formatter only supports JDK 17 PiperOrigin-RevId: 699235273 --- .../googlejavaformat/java/StringWrapper.java | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java index eb7eacfa4..c1c38d34b 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java +++ b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java @@ -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; @@ -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 { @@ -204,7 +202,7 @@ private void indentTextBlocks( // The first line of the text block is always """, and it does not affect incidental // whitespace. ImmutableList 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 lines = stripped.lines().collect(toImmutableList()); int deindent = getLast(initialLines).stripTrailing().length() @@ -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.