Add tests for (package-)naming.
These tests and keep-rules came from:
http://cs/android/toolchain/jack/jack-tests/tests/com/android/jack/shrob/
with the same numberings for tracking purpose.
Bug: 37764746
Change-Id: I4909cfa38d1e55980eb203622d0bd298cb68716d
diff --git a/src/test/examples/naming001/A.java b/src/test/examples/naming001/A.java
new file mode 100644
index 0000000..092bcf7
--- /dev/null
+++ b/src/test/examples/naming001/A.java
@@ -0,0 +1,25 @@
+// 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 naming001;
+
+public class A {
+
+ A() {
+ }
+
+ A(int i) {
+ }
+
+ static {
+ C.m();
+ }
+
+ void m() {
+ }
+
+ @SuppressWarnings("unused")
+ private void privateFunc() {
+ }
+}
+
diff --git a/src/test/examples/naming001/B.java b/src/test/examples/naming001/B.java
new file mode 100644
index 0000000..30e520c
--- /dev/null
+++ b/src/test/examples/naming001/B.java
@@ -0,0 +1,8 @@
+// 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 naming001;
+
+public class B {
+}
+
diff --git a/src/test/examples/naming001/C.java b/src/test/examples/naming001/C.java
new file mode 100644
index 0000000..24cd8ec
--- /dev/null
+++ b/src/test/examples/naming001/C.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 naming001;
+
+public class C {
+ static void f() {
+ }
+
+ static void m() {
+ }
+}
+
diff --git a/src/test/examples/naming001/D.java b/src/test/examples/naming001/D.java
new file mode 100644
index 0000000..c1ec759
--- /dev/null
+++ b/src/test/examples/naming001/D.java
@@ -0,0 +1,21 @@
+// 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 naming001;
+
+public class D {
+ public void keep() {
+ System.out.println();
+ }
+
+ public static void main(String[] args) {
+ D d = new E();
+ d.keep();
+ }
+
+ public static void main2(String[] args) {
+ D d = new D();
+ d.keep();
+ }
+}
+
diff --git a/src/test/examples/naming001/E.java b/src/test/examples/naming001/E.java
new file mode 100644
index 0000000..b445323
--- /dev/null
+++ b/src/test/examples/naming001/E.java
@@ -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.
+package naming001;
+
+public class E extends D {
+ @Override
+ public void keep() {
+ }
+}
+
diff --git a/src/test/examples/naming001/F.java b/src/test/examples/naming001/F.java
new file mode 100644
index 0000000..3ca60f3
--- /dev/null
+++ b/src/test/examples/naming001/F.java
@@ -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.
+package naming001;
+
+public class F extends E {
+ @Override
+ public void keep() {
+ }
+}
+
diff --git a/src/test/examples/naming001/G.java b/src/test/examples/naming001/G.java
new file mode 100644
index 0000000..175ae8c
--- /dev/null
+++ b/src/test/examples/naming001/G.java
@@ -0,0 +1,16 @@
+// 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 naming001;
+
+public class G implements H {
+ @Override
+ public void m() {
+ }
+
+ public static void main(String[] args) {
+ H i = new G();
+ i.m();
+ }
+}
+
diff --git a/src/test/examples/naming001/H.java b/src/test/examples/naming001/H.java
new file mode 100644
index 0000000..5a82977
--- /dev/null
+++ b/src/test/examples/naming001/H.java
@@ -0,0 +1,8 @@
+// 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 naming001;
+
+public interface H extends I {
+}
+
diff --git a/src/test/examples/naming001/I.java b/src/test/examples/naming001/I.java
new file mode 100644
index 0000000..6ee9ef1
--- /dev/null
+++ b/src/test/examples/naming001/I.java
@@ -0,0 +1,9 @@
+// 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 naming001;
+
+public interface I {
+ void m();
+}
+
diff --git a/src/test/examples/naming001/J.java b/src/test/examples/naming001/J.java
new file mode 100644
index 0000000..f609989
--- /dev/null
+++ b/src/test/examples/naming001/J.java
@@ -0,0 +1,31 @@
+// 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 naming001;
+
+public class J {
+ int[][][] m5(int a, boolean b, long c) {
+ return null;
+ }
+
+ int[][][] m3() {
+ return null;
+ }
+
+ int[][] m2() {
+ return null;
+ }
+
+ int[] m1() {
+ return null;
+ }
+
+ int m0() {
+ return 0;
+ }
+
+ int[][][] m() {
+ return null;
+ }
+}
+
diff --git a/src/test/examples/naming001/K.java b/src/test/examples/naming001/K.java
new file mode 100644
index 0000000..4998773
--- /dev/null
+++ b/src/test/examples/naming001/K.java
@@ -0,0 +1,29 @@
+// 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 naming001;
+
+public class K {
+ private int i;
+ private int h;
+ private final int i2 = 7;
+ private static int j;
+ private final static int i3 = 7;
+
+ private static final Object o = "TAG";
+ private static final String TAG = "TAG";
+ private final String TAG2 = "TAG";
+
+ static {
+ j = 6;
+ }
+
+ {
+ i = 6;
+ }
+
+ void keep() {
+ h = 7;
+ }
+}
+
diff --git a/src/test/examples/naming001/L.java b/src/test/examples/naming001/L.java
new file mode 100644
index 0000000..7e8b03a
--- /dev/null
+++ b/src/test/examples/naming001/L.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 naming001;
+
+public class L {
+ private static final String TAG = "TAG";
+
+ void onReceive() {
+ System.out.println(TAG);
+ }
+}
+
diff --git a/src/test/examples/naming001/Reflect.java b/src/test/examples/naming001/Reflect.java
new file mode 100644
index 0000000..15b920e
--- /dev/null
+++ b/src/test/examples/naming001/Reflect.java
@@ -0,0 +1,53 @@
+// 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 naming001;
+
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import java.util.concurrent.atomic.AtomicLongFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+public class Reflect {
+ void keep() throws ClassNotFoundException {
+ Class.forName("naming001.Reflect2");
+ Class.forName("ClassThatDoesNotExists");
+ }
+
+ void keep2() throws NoSuchFieldException, SecurityException {
+ Reflect2.class.getField("fieldPublic");
+ Reflect2.class.getField("fieldPrivate");
+ }
+
+ void keep3() throws NoSuchFieldException, SecurityException {
+ Reflect2.class.getDeclaredField("fieldPublic");
+ Reflect2.class.getDeclaredField("fieldPrivate");
+ }
+
+ void keep4() throws SecurityException, NoSuchMethodException {
+ Reflect2.class.getMethod("m", new Class[] {naming001.Reflect2.A.class});
+ Reflect2.class.getMethod("m", new Class[] {naming001.Reflect2.B.class});
+ Reflect2.class.getMethod("methodThatDoesNotExist",
+ new Class[] {naming001.Reflect2.A.class});
+ }
+
+ void keep5() throws SecurityException, NoSuchMethodException {
+ Reflect2.class.getDeclaredMethod("m", new Class[] {naming001.Reflect2.A.class});
+ Reflect2.class.getDeclaredMethod("m", new Class[] {naming001.Reflect2.B.class});
+ }
+
+ void keep6() throws SecurityException {
+ AtomicIntegerFieldUpdater.newUpdater(Reflect2.class, "fieldPublic");
+ }
+
+ void keep7() throws SecurityException {
+ AtomicLongFieldUpdater.newUpdater(Reflect2.class, "fieldLong");
+ AtomicLongFieldUpdater.newUpdater(Reflect2.class, "fieldLong2");
+ }
+
+ void keep8() throws SecurityException {
+ AtomicReferenceFieldUpdater.newUpdater(Reflect2.class, Reflect2.A.class, "a");
+ AtomicReferenceFieldUpdater.newUpdater(Reflect2.class, Reflect2.A.class, "b");
+ AtomicReferenceFieldUpdater.newUpdater(Reflect2.class, Object.class, "c");
+ }
+}
+
diff --git a/src/test/examples/naming001/Reflect2.java b/src/test/examples/naming001/Reflect2.java
new file mode 100644
index 0000000..42b3075
--- /dev/null
+++ b/src/test/examples/naming001/Reflect2.java
@@ -0,0 +1,40 @@
+// 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 naming001;
+
+public class Reflect2 {
+ public volatile int fieldPublic;
+
+ private volatile int fieldPrivate;
+
+ public volatile long fieldLong;
+
+ private volatile long fieldLong2;
+
+ volatile long fieldLong3;
+
+ protected volatile long fieldLong4;
+
+ public volatile A a;
+
+ public volatile B b;
+
+ private volatile Object c;
+
+ private void calledMethod() {
+ }
+
+ public void m(A a) {
+ }
+
+ private void privateMethod(B b) {
+ }
+
+ class A {
+ }
+
+ class B {
+ }
+}
+
diff --git a/src/test/examples/naming001/keep-rules-001.txt b/src/test/examples/naming001/keep-rules-001.txt
new file mode 100644
index 0000000..72be5a2
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-001.txt
@@ -0,0 +1,7 @@
+# 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.
+
+-allowaccessmodification
+
+-keep class naming001.A
diff --git a/src/test/examples/naming001/keep-rules-002.txt b/src/test/examples/naming001/keep-rules-002.txt
new file mode 100644
index 0000000..1554e31
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-002.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep !final class naming001.A {
+ private <methods>;
+}
diff --git a/src/test/examples/naming001/keep-rules-003.txt b/src/test/examples/naming001/keep-rules-003.txt
new file mode 100644
index 0000000..cdcab79
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-003.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep !final class naming001.A {
+ !private <methods>;
+}
diff --git a/src/test/examples/naming001/keep-rules-005.txt b/src/test/examples/naming001/keep-rules-005.txt
new file mode 100644
index 0000000..ef4b5c8
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-005.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep class naming001.D {
+ public static void main(...);
+}
diff --git a/src/test/examples/naming001/keep-rules-006.txt b/src/test/examples/naming001/keep-rules-006.txt
new file mode 100644
index 0000000..7a8e99e
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-006.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep class naming001.G {
+ public static void main(...);
+}
diff --git a/src/test/examples/naming001/keep-rules-014.txt b/src/test/examples/naming001/keep-rules-014.txt
new file mode 100644
index 0000000..6423782
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-014.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep class naming001.Reflect {
+ *** keep6();
+}
diff --git a/src/test/examples/naming001/keep-rules-017.txt b/src/test/examples/naming001/keep-rules-017.txt
new file mode 100644
index 0000000..b146df8
--- /dev/null
+++ b/src/test/examples/naming001/keep-rules-017.txt
@@ -0,0 +1,9 @@
+# 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.
+
+-allowaccessmodification
+
+-keep class naming001.K {
+ void keep();
+}
diff --git a/src/test/examples/naming044/A.java b/src/test/examples/naming044/A.java
new file mode 100644
index 0000000..799f765
--- /dev/null
+++ b/src/test/examples/naming044/A.java
@@ -0,0 +1,8 @@
+// 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 naming044;
+
+public class A {
+ static int f = 8;
+}
diff --git a/src/test/examples/naming044/B.java b/src/test/examples/naming044/B.java
new file mode 100644
index 0000000..7580945
--- /dev/null
+++ b/src/test/examples/naming044/B.java
@@ -0,0 +1,10 @@
+// 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 naming044;
+
+public class B {
+ public static int m() {
+ return A.f;
+ }
+}
diff --git a/src/test/examples/naming044/keep-rules-001.txt b/src/test/examples/naming044/keep-rules-001.txt
new file mode 100644
index 0000000..a191b54
--- /dev/null
+++ b/src/test/examples/naming044/keep-rules-001.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.
+
+-allowaccessmodification
+
+-repackageclasses ''
+
+-keep,allowobfuscation class * {
+ *;
+}
diff --git a/src/test/examples/naming044/keep-rules-002.txt b/src/test/examples/naming044/keep-rules-002.txt
new file mode 100644
index 0000000..c6e495b
--- /dev/null
+++ b/src/test/examples/naming044/keep-rules-002.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.
+
+-allowaccessmodification
+
+-repackageclasses 'p44.x'
+
+-keep,allowobfuscation class * {
+ *;
+}