Skip to content
Merged
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 @@ -37,10 +37,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 All @@ -53,6 +55,7 @@
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
import javax.tools.SimpleJavaFileObject;
import org.jspecify.annotations.Nullable;

/** {@code JavaInput} extends {@link Input} to represent a Java input document. */
public final class JavaInput extends Input {
Expand Down Expand Up @@ -364,7 +367,15 @@ 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)) {
Collection<JCDiagnostic> ds;
try {
@SuppressWarnings("unchecked")
var extraLocalForSuppression = (Collection<JCDiagnostic>) GET_DIAGNOSTICS.invoke(diagnostics);
ds = extraLocalForSuppression;
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
if (ds.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 @@ -471,6 +482,16 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
return ImmutableList.copyOf(toks);
}

private static final Method GET_DIAGNOSTICS = getGetDiagnostics();

private static @Nullable Method getGetDiagnostics() {
try {
return DeferredDiagnosticHandler.class.getMethod("getDiagnostics");
} catch (NoSuchMethodException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static int updateColumn(int columnI, String originalTokText) {
Integer last = Iterators.getLast(Newlines.lineOffsetIterator(originalTokText));
if (last > 0) {
Expand Down