diff --git a/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java b/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java index c351d02288a..1576928a56d 100644 --- a/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java +++ b/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java @@ -266,7 +266,7 @@ private static ImmutableSet getAllImports(Inliner inliner, WhichImports whichImports.getExistingImports(inliner), Optional.ofNullable(inliner.getContext()) .map(c -> c.get(JCCompilationUnit.class)) - .map(JCCompilationUnit::getImports) + .map(ImportPolicy::getImports) .map(Collection::stream) .orElse(Stream.of()) .filter(JCImport.class::isInstance) @@ -276,6 +276,15 @@ private static ImmutableSet getAllImports(Inliner inliner, WhichImports .collect(toImmutableSet()); } + @SuppressWarnings("unchecked") + private static Collection getImports(JCCompilationUnit unit) { + try { + return (Collection) JCCompilationUnit.class.getMethod("getImports").invoke(unit); + } catch (ReflectiveOperationException e) { + throw new LinkageError(e.getMessage(), e); + } + } + private static JCTree getQualifiedIdentifier(JCImport i) { try { return (JCTree) JCImport.class.getMethod("getQualifiedIdentifier").invoke(i);