Apply the given pg-map via graph lense.

While visiting types in a subtyping order, mappings in the pg-map will
be converted to a custom graph lense. One caveat is to detect mapping
conflicts, e.g., so-called diamond problem.

Another caveat is to apply class mappings on-the-fly. We should rename
all the occurrences of renamed types while applying member mappings.

Yet another caveat is uses of renamed lib classes inside pgr classes.
We have a separate step that fixes trees by explicitly substitute those
type appearances with applied names.

------

Note that, instead of way too general support (http://go/r8g/4880),
we decided to support only the simple use case: compile a new piece
of code (e.g., test) against an obfuscated app.
See http://b/64802420#comment7 for more details.

Bug: 64802420
Change-Id: Ib3cb35811061c046e94a4fc9a021a783f15050dc
diff --git a/src/test/examples/applymapping044/AsubB.java b/src/test/examples/applymapping044/AsubB.java
new file mode 100644
index 0000000..2c5fd0c
--- /dev/null
+++ b/src/test/examples/applymapping044/AsubB.java
@@ -0,0 +1,13 @@
+// Copyright (c) 2017, 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 applymapping044;
+
+import naming044.A;
+import naming044.sub.SubB;
+
+public class AsubB extends SubB {
+  public int boo(A a) {
+    return f(a) * 3;
+  }
+}
diff --git a/src/test/examples/applymapping044/Main.java b/src/test/examples/applymapping044/Main.java
new file mode 100644
index 0000000..9d5f577
--- /dev/null
+++ b/src/test/examples/applymapping044/Main.java
@@ -0,0 +1,20 @@
+// Copyright (c) 2017, 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 applymapping044;
+
+import naming044.A;
+import naming044.B;
+import naming044.sub.SubB;
+
+public class Main {
+  public static void main(String[] args) {
+    B.m();
+    SubB.n();
+    A a = new A();
+    B b = new B();
+    b.f(a);
+    AsubB subB = new AsubB();
+    subB.f(a);
+  }
+}
diff --git a/src/test/examples/applymapping044/keep-rules-apply-mapping.txt b/src/test/examples/applymapping044/keep-rules-apply-mapping.txt
new file mode 100644
index 0000000..56f43b2
--- /dev/null
+++ b/src/test/examples/applymapping044/keep-rules-apply-mapping.txt
@@ -0,0 +1,13 @@
+# Copyright (c) 2017, 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.
+
+-keep public class applymapping044.Main {
+  public static void main(...);
+}
+
+-keep,allowobfuscation class * {
+  *;
+}
+
+-applymapping test-mapping.txt
diff --git a/src/test/examples/applymapping044/keep-rules.txt b/src/test/examples/applymapping044/keep-rules.txt
new file mode 100644
index 0000000..efed0ec
--- /dev/null
+++ b/src/test/examples/applymapping044/keep-rules.txt
@@ -0,0 +1,11 @@
+# Copyright (c) 2017, 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.
+
+-keep public class applymapping044.Main {
+  public static void main(...);
+}
+
+-keep,allowobfuscation class * {
+  *;
+}
diff --git a/src/test/examples/applymapping044/test-mapping.txt b/src/test/examples/applymapping044/test-mapping.txt
new file mode 100644
index 0000000..41c2c5c
--- /dev/null
+++ b/src/test/examples/applymapping044/test-mapping.txt
@@ -0,0 +1,9 @@
+naming044.A -> naming044.x:
+    int f -> o
+naming044.B -> naming044.y:
+    int m() -> n
+    int f(naming044.A) -> p
+naming044.sub.SubA -> naming044.z.x:
+    int f -> q
+naming044.sub.SubB -> naming044.z.y:
+    int n() -> m