From 14de9bce2b27ce29540792afc4dc87d60330999d Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 27 Feb 2023 12:03:36 -0800 Subject: [PATCH] Prepare for a change to `TreeMaker.Select` https://github.com/openjdk/jdk/commit/a917fb3fcf0fe1a4c4de86c08ae4041462848b82#diff-0f1b4da56622ccb5ff716ce5a9532819fc5573179a1eb2c803d053196824891aL726-R727 PiperOrigin-RevId: 512693208 --- .../com/google/errorprone/refaster/ImportPolicy.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 150fa1f2357..76d635a8051 100644 --- a/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java +++ b/core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java @@ -27,6 +27,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Streams; import com.sun.tools.javac.code.Symbol.PackageSymbol; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCImport; @@ -269,7 +270,15 @@ private static ImmutableSet getAllImports(Inliner inliner, WhichImports .map(Collection::stream) .orElse(Stream.of()) .filter(whichImports::existingImportMatches) - .map(imp -> imp.getQualifiedIdentifier().toString())) + .map(imp -> getQualifiedIdentifier(imp).toString())) .collect(toImmutableSet()); } + + private static JCTree getQualifiedIdentifier(JCImport i) { + try { + return (JCTree) JCImport.class.getMethod("getQualifiedIdentifier").invoke(i); + } catch (ReflectiveOperationException e) { + throw new LinkageError(e.getMessage(), e); + } + } }