Skip to content

Commit

Permalink
Fix JDK 11 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Jan 13, 2024
1 parent c7fc8a9 commit 82b9024
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.google.errorprone.suppliers.Supplier;
import com.sun.tools.javac.code.ClassFinder;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.CompletionFailure;
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.Name;
import javax.lang.model.element.Modifier;

/**
* Utility class that helps decide whether it is appropriate to introduce references to (well-known)
Expand Down Expand Up @@ -91,7 +93,7 @@ private static boolean isKnownClass(String typeName, VisitorState state) {

private static boolean isPublicClassInSymbolTable(String typeName, VisitorState state) {
Type type = state.getTypeFromString(typeName);
return type != null && type.tsym.isPublic();
return type != null && isPublic(type.tsym);
}

private static boolean canLoadPublicClass(String typeName, VisitorState state) {
Expand All @@ -104,14 +106,19 @@ private static boolean canLoadPublicClass(String typeName, VisitorState state) {
: symtab.unnamedModule;
Name binaryName = state.binaryNameFromClassname(typeName);
try {
return classFinder.loadClass(module, binaryName).isPublic();
return isPublic(classFinder.loadClass(module, binaryName));
} catch (
@SuppressWarnings("java:S1166" /* Not exceptional. */)
CompletionFailure e) {
return false;
}
}

// XXX: Once we target JDK 14+, drop this method in favour of `Symbol#isPublic()`.
private static boolean isPublic(Symbol symbol) {
return symbol.getModifiers().contains(Modifier.PUBLIC);
}

private static boolean shouldIgnoreClasspath(VisitorState state) {
return state
.errorProneOptions()
Expand Down

0 comments on commit 82b9024

Please sign in to comment.