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 @@ -42,6 +42,7 @@
import com.sun.tools.javac.util.Log.DeferredDiagnosticHandler;
import com.sun.tools.javac.util.Options;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -365,7 +366,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
return text;
}
});
DeferredDiagnosticHandler diagnostics = new DeferredDiagnosticHandler(log);
DeferredDiagnosticHandler diagnostics = deferredDiagnosticHandler(log);
ImmutableList<RawTok> rawToks = JavacTokens.getTokens(text, context, stopTokens);
Collection<JCDiagnostic> ds;
try {
Expand Down Expand Up @@ -482,6 +483,29 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
return ImmutableList.copyOf(toks);
}

private static final Constructor<DeferredDiagnosticHandler>
DEFERRED_DIAGNOSTIC_HANDLER_CONSTRUCTOR = getDeferredDiagnosticHandlerConstructor();

// Depending on the JDK version, we might have a static class whose constructor has an explicit
// Log parameter, or an inner class whose constructor has an *implicit* Log parameter. They are
// different at the source level, but look the same to reflection.

private static Constructor<DeferredDiagnosticHandler> getDeferredDiagnosticHandlerConstructor() {
try {
return DeferredDiagnosticHandler.class.getConstructor(Log.class);
} catch (NoSuchMethodException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static DeferredDiagnosticHandler deferredDiagnosticHandler(Log log) {
try {
return DEFERRED_DIAGNOSTIC_HANDLER_CONSTRUCTOR.newInstance(log);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static final Method GET_DIAGNOSTICS = getGetDiagnostics();

private static @Nullable Method getGetDiagnostics() {
Expand Down
Loading