Add support -adaptclassstrings [class_filter] (w/ different parsing).
First, user-given rules w/ that option in pg config will be converted
to ProguardClassNameList, which is in turn used to match classes.
After the normal minifier process is done, IdentifierMinifier, a newly
introduced minifier that uses aforementioned matched classes and naming
lense that is generated from the other minifiers, will walk through
candidate classes to find string literal usages:
1) in <clinit> (for static field initialization), and
2) in method's code_item.
Those string literals will be replaced with the renamed ones only if
1) they correspond to class identifiers; and
2) corresponding types are indeed renamed by the previous minifier.
Bug: 36799092
Change-Id: I3f09a22fa0d0eda6671f4c60d29b9363fb991df3
diff --git a/src/test/examples/adaptclassstrings/Main.java b/src/test/examples/adaptclassstrings/Main.java
new file mode 100644
index 0000000..4cee1d5
--- /dev/null
+++ b/src/test/examples/adaptclassstrings/Main.java
@@ -0,0 +1,30 @@
+// 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 adaptclassstrings;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ int f = 3;
+ A a = new A(f);
+ AA aa = new AA(f);
+ assert a.foo() != aa.foo();
+
+ a.bar();
+
+ Object a_foo =
+ Class.forName("adaptclassstrings.A").getMethod("foo").invoke(a);
+ Object aa_foo =
+ Class.forName("adaptclassstrings.AA").getMethod("foo").invoke(aa);
+ assert !a_foo.equals(aa_foo);
+
+ Object c_to_a_foo =
+ Class.forName((String)
+ Class.forName("adaptclassstrings.C").getField("OTHER").get(null))
+ .getMethod("foo").invoke(a);
+ assert a_foo.equals(c_to_a_foo);
+
+ String cName = (String) Class.forName(C.ITSELF).getField("ITSELF").get(null);
+ assert cName.equals(A.OTHER);
+ }
+}