Skip to content

Commit a6e5bd9

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Remove some unnecessary reflection now that the formatter only supports JDK 17
PiperOrigin-RevId: 699235273
1 parent a4991be commit a6e5bd9

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java

+1-27
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.sun.tools.javac.util.Position;
4646
import java.io.IOException;
4747
import java.io.UncheckedIOException;
48-
import java.lang.reflect.Method;
4948
import java.net.URI;
5049
import java.util.ArrayDeque;
5150
import java.util.ArrayList;
@@ -61,7 +60,6 @@
6160
import javax.tools.JavaFileObject;
6261
import javax.tools.SimpleJavaFileObject;
6362
import javax.tools.StandardLocation;
64-
import org.jspecify.annotations.Nullable;
6563

6664
/** Wraps string literals that exceed the column limit. */
6765
public final class StringWrapper {
@@ -204,7 +202,7 @@ private void indentTextBlocks(
204202
// The first line of the text block is always """, and it does not affect incidental
205203
// whitespace.
206204
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();
208206
ImmutableList<String> lines = stripped.lines().collect(toImmutableList());
209207
int deindent =
210208
getLast(initialLines).stripTrailing().length()
@@ -280,30 +278,6 @@ private void wrapLongStrings(
280278
}
281279
}
282280

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-
307281
/**
308282
* Returns the source text of the given string literal trees, excluding the leading and trailing
309283
* double-quotes and the `+` operator.

0 commit comments

Comments
 (0)