Add test for reflectively looking up type parameters in inner class

Bug: 184927364
Change-Id: I1f9ca761d8865264c0e6bb507a17556f73ce14c6
diff --git a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureReflectiveInnerTest.java b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureReflectiveInnerTest.java
new file mode 100644
index 0000000..0908f05
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureReflectiveInnerTest.java
@@ -0,0 +1,86 @@
+// Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.graph.genericsignature;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.lang.reflect.TypeVariable;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class GenericSignatureReflectiveInnerTest extends TestBase {
+
+  private final String EXPECTED = "S";
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public GenericSignatureReflectiveInnerTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testRuntime() throws Exception {
+    testForRuntime(parameters)
+        .addInnerClasses(getClass())
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines(EXPECTED);
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    testForR8(parameters.getBackend())
+        .addInnerClasses(getClass())
+        .addKeepMainRule(Main.class)
+        .addKeepAttributeInnerClassesAndEnclosingMethod()
+        .addKeepAttributeSignature()
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines(EXPECTED)
+        .inspect(
+            inspector -> {
+              assertThat(inspector.clazz(Foo.class), not(isPresent()));
+              assertThat(inspector.clazz(Foo.Bar.class), isPresent());
+            });
+  }
+
+  public static class Foo<T> {
+
+    public class Bar<S> {
+
+      public void test() {
+        Class<? extends Bar> aClass = (Class<? extends Bar>) this.getClass();
+        for (TypeVariable<? extends Class<? extends Bar>> typeParameter :
+            aClass.getTypeParameters()) {
+          System.out.println(typeParameter);
+        }
+      }
+    }
+
+    public Bar<String> foo() {
+      return new Bar<>();
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      Foo<Integer>.Bar<String> foo = new Foo<Integer>().foo();
+      foo.test();
+    }
+  }
+}