Skip to content

Commit f0a9748

Browse files
cushongoogle-java-format Team
authored andcommitted
Update workaround for JDK-8372948
The upstream change is removing the overload of `newParser`. PiperOrigin-RevId: 865273867
1 parent 9b97973 commit f0a9748

File tree

1 file changed

+19
-40
lines changed
  • core/src/main/java/com/google/googlejavaformat/java

1 file changed

+19
-40
lines changed

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

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@ public String getCharContent(boolean ignoreEncodingErrors) {
179179
JavacParser parser;
180180
try {
181181
parser =
182-
(JavacParser)
183-
NEW_PARSER_HANDLE.invokeExact(
184-
parserFactory,
185-
(CharSequence) javaInput,
186-
/* keepDocComments */ true,
187-
/* keepEndPos */ true,
188-
/* keepLineMap */ true);
182+
newParser(
183+
parserFactory,
184+
javaInput,
185+
/* keepDocComments= */ true,
186+
/* keepEndPos= */ true,
187+
/* keepLineMap= */ true);
189188
} catch (Throwable e) {
190189
Throwables.throwIfUnchecked(e);
191190
throw new AssertionError(e);
@@ -195,6 +194,19 @@ public String getCharContent(boolean ignoreEncodingErrors) {
195194
return unit;
196195
}
197196

197+
private static JavacParser newParser(
198+
ParserFactory parserFactory,
199+
CharSequence source,
200+
boolean keepDocComments,
201+
boolean keepEndPos,
202+
boolean keepLineMap) {
203+
if (END_POS_TABLE_CLASS != null) {
204+
return parserFactory.newParser(source, keepDocComments, keepEndPos, keepLineMap);
205+
}
206+
return parserFactory.newParser(
207+
source, keepDocComments, keepLineMap, /* parseModuleInfo */ false);
208+
}
209+
198210
private static boolean errorDiagnostic(Diagnostic<?> input) {
199211
if (input.getKind() != Diagnostic.Kind.ERROR) {
200212
return false;
@@ -215,39 +227,6 @@ private static boolean errorDiagnostic(Diagnostic<?> input) {
215227
}
216228
}
217229

218-
private static final MethodHandle NEW_PARSER_HANDLE = getNewParserHandle();
219-
220-
private static MethodHandle getNewParserHandle() {
221-
MethodHandles.Lookup lookup = MethodHandles.lookup();
222-
if (END_POS_TABLE_CLASS == null) {
223-
try {
224-
// (parserFactory, input, keepDocComments, keepEndPos, keepLineMap) ->
225-
// parserFactory.newParser(input, keepDocComments, keepLineMap)
226-
return MethodHandles.dropArguments(
227-
lookup.findVirtual(
228-
ParserFactory.class,
229-
"newParser",
230-
MethodType.methodType(
231-
JavacParser.class, CharSequence.class, boolean.class, boolean.class)),
232-
3,
233-
boolean.class);
234-
} catch (ReflectiveOperationException e) {
235-
throw new LinkageError(e.getMessage(), e);
236-
}
237-
}
238-
try {
239-
// (parserFactory, input, keepDocComments, keepEndPos, keepLineMap) ->
240-
// parserFactory.newParser(input, keepDocComments, keepEndPos, keepLineMap)
241-
return lookup.findVirtual(
242-
ParserFactory.class,
243-
"newParser",
244-
MethodType.methodType(
245-
JavacParser.class, CharSequence.class, boolean.class, boolean.class, boolean.class));
246-
} catch (ReflectiveOperationException e) {
247-
throw new LinkageError(e.getMessage(), e);
248-
}
249-
}
250-
251230
private static final MethodHandle GET_END_POS_HANDLE = getEndPosMethodHandle();
252231

253232
private static MethodHandle getEndPosMethodHandle() {

0 commit comments

Comments
 (0)