Test ReflectiveCallExtractor against several libs
Change-Id: I8657a312760307eae75231c2ce9d38a1beb93e7e
diff --git a/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractor.java b/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractor.java
index 4dd7e86..ff544a4 100644
--- a/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractor.java
+++ b/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractor.java
@@ -58,9 +58,10 @@
DexMethod theMethod = cfInvoke.getMethod();
DexType holderType = theMethod.getHolderType();
DexClass def = appInfo.definitionFor(holderType);
- if (!holderType.isArrayType() && def.isLibraryClass()) {
+ if (def != null && def.isLibraryClass()) {
if (holderType.toSourceString().startsWith("java.lang.reflect")
- || holderType.isIdenticalTo(appInfo.dexItemFactory().classType)) {
+ || holderType.isIdenticalTo(factory.unsafeType)
+ || holderType.isIdenticalTo(factory.classType)) {
methods
.computeIfAbsent(holderType, t -> Sets.newIdentityHashSet())
.add(theMethod);
diff --git a/src/test/java/com/android/tools/r8/assistant/GsonReflectiveCallExtractorTest.java b/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractorTest.java
similarity index 78%
rename from src/test/java/com/android/tools/r8/assistant/GsonReflectiveCallExtractorTest.java
rename to src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractorTest.java
index 02a40a5..82f58ef 100644
--- a/src/test/java/com/android/tools/r8/assistant/GsonReflectiveCallExtractorTest.java
+++ b/src/test/java/com/android/tools/r8/assistant/ReflectiveCallExtractorTest.java
@@ -13,6 +13,7 @@
import com.android.tools.r8.graph.DexItemFactory;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.DexType;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
@@ -25,7 +26,7 @@
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
-public class GsonReflectiveCallExtractorTest extends TestBase {
+public class ReflectiveCallExtractorTest extends TestBase {
@Parameter(0)
public TestParameters parameters;
@@ -37,9 +38,22 @@
@Test
public void testGson() throws Exception {
+ test(ToolHelper.GSON, 6, 69);
+ }
+
+ @Test
+ public void testGuava() throws Exception {
+ test(ToolHelper.GUAVA_JRE, 6, 99);
+ }
+
+ @Test
+ public void testJacoco() throws Exception {
+ test(ToolHelper.JACOCO_AGENT, 3, 17);
+ }
+
+ private void test(Path jar, int success, int failure) throws Exception {
DexItemFactory factory = new DexItemFactory();
- Map<DexType, Collection<DexMethod>> reflectiveMethods =
- extractReflectiveCalls(ToolHelper.GSON, factory);
+ Map<DexType, Collection<DexMethod>> reflectiveMethods = extractReflectiveCalls(jar, factory);
Set<DexMethod> instrumentedMethodsForTesting =
new InstrumentedReflectiveMethodList(factory).getInstrumentedMethodsForTesting();
int supported = 0;
@@ -57,7 +71,7 @@
}
methods.removeAll(toRemove);
}
- Assert.assertEquals(6, supported);
- Assert.assertEquals("Missing :\n" + printMethods(reflectiveMethods), 69, unsupported);
+ Assert.assertEquals(success, supported);
+ Assert.assertEquals("Missing :\n" + printMethods(reflectiveMethods), failure, unsupported);
}
}