|
37 | 37 | import com.sun.tools.javac.parser.Tokens.TokenKind;
|
38 | 38 | import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
39 | 39 | import com.sun.tools.javac.util.Context;
|
| 40 | +import com.sun.tools.javac.util.JCDiagnostic; |
40 | 41 | import com.sun.tools.javac.util.Log;
|
41 | 42 | import com.sun.tools.javac.util.Log.DeferredDiagnosticHandler;
|
42 | 43 | import com.sun.tools.javac.util.Options;
|
43 | 44 | import java.io.IOException;
|
| 45 | +import java.lang.reflect.Method; |
44 | 46 | import java.net.URI;
|
45 | 47 | import java.util.ArrayList;
|
46 | 48 | import java.util.Collection;
|
|
53 | 55 | import javax.tools.JavaFileObject;
|
54 | 56 | import javax.tools.JavaFileObject.Kind;
|
55 | 57 | import javax.tools.SimpleJavaFileObject;
|
| 58 | +import org.jspecify.annotations.Nullable; |
56 | 59 |
|
57 | 60 | /** {@code JavaInput} extends {@link Input} to represent a Java input document. */
|
58 | 61 | public final class JavaInput extends Input {
|
@@ -364,7 +367,15 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
|
364 | 367 | });
|
365 | 368 | DeferredDiagnosticHandler diagnostics = new DeferredDiagnosticHandler(log);
|
366 | 369 | ImmutableList<RawTok> rawToks = JavacTokens.getTokens(text, context, stopTokens);
|
367 |
| - if (diagnostics.getDiagnostics().stream().anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR)) { |
| 370 | + Collection<JCDiagnostic> ds; |
| 371 | + try { |
| 372 | + @SuppressWarnings("unchecked") |
| 373 | + var extraLocalForSuppression = (Collection<JCDiagnostic>) GET_DIAGNOSTICS.invoke(diagnostics); |
| 374 | + ds = extraLocalForSuppression; |
| 375 | + } catch (ReflectiveOperationException e) { |
| 376 | + throw new LinkageError(e.getMessage(), e); |
| 377 | + } |
| 378 | + if (ds.stream().anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR)) { |
368 | 379 | return ImmutableList.of(new Tok(0, "", "", 0, 0, true, null)); // EOF
|
369 | 380 | }
|
370 | 381 | int kN = 0;
|
@@ -471,6 +482,16 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
|
471 | 482 | return ImmutableList.copyOf(toks);
|
472 | 483 | }
|
473 | 484 |
|
| 485 | + private static final Method GET_DIAGNOSTICS = getGetDiagnostics(); |
| 486 | + |
| 487 | + private static @Nullable Method getGetDiagnostics() { |
| 488 | + try { |
| 489 | + return DeferredDiagnosticHandler.class.getMethod("getDiagnostics"); |
| 490 | + } catch (NoSuchMethodException e) { |
| 491 | + throw new LinkageError(e.getMessage(), e); |
| 492 | + } |
| 493 | + } |
| 494 | + |
474 | 495 | private static int updateColumn(int columnI, String originalTokText) {
|
475 | 496 | Integer last = Iterators.getLast(Newlines.lineOffsetIterator(originalTokText));
|
476 | 497 | if (last > 0) {
|
|
0 commit comments