Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import com.sun.tools.javac.parser.Tokens.TokenKind;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.DeferredDiagnosticHandler;
import com.sun.tools.javac.util.Options;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -366,7 +368,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
});
DeferredDiagnosticHandler diagnostics = new DeferredDiagnosticHandler(log);
ImmutableList<RawTok> rawToks = JavacTokens.getTokens(text, context, stopTokens);
if (diagnostics.getDiagnostics().stream().anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR)) {
if (getDiagnostics(diagnostics).stream().anyMatch(d -> d.getKind() == Diagnostic.Kind.ERROR)) {
return ImmutableList.of(new Tok(0, "", "", 0, 0, true, null)); // EOF
}
int kN = 0;
Expand Down Expand Up @@ -463,6 +465,33 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
return ImmutableList.copyOf(toks);
}

/**
* Gets diagnostics from a DeferredDiagnosticHandler using reflection.
* This method handles the API change in JDK 25 where getDiagnostics()
* changed from returning Queue to List.
*
* @param handler the diagnostic handler
* @return a collection of diagnostics
*/
@SuppressWarnings("unchecked")
private static Collection<JCDiagnostic> getDiagnostics(DeferredDiagnosticHandler handler) {
try {
return (Collection<JCDiagnostic>) GET_DIAGNOSTICS.invoke(handler);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static final Method GET_DIAGNOSTICS;

static {
try {
GET_DIAGNOSTICS = DeferredDiagnosticHandler.class.getMethod("getDiagnostics");
} catch (NoSuchMethodException e) {
throw new LinkageError(e.getMessage(), e);
}
}

@SuppressWarnings("for-rollout:NullAway")
private static int updateColumn(int columnI, String originalTokText) {
Integer last = Iterators.getLast(Newlines.lineOffsetIterator(originalTokText));
Expand Down