blob: 56095b598f890ba95d71be1899ab43785f1fe240 [file] [log] [blame]
Christoffer Quist Adamsen10c8a162018-06-11 09:53:03 +02001// Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package classmerging;
6
7import classmerging.pkg.SimpleInterfaceImplRetriever;
8
9public class SimpleInterfaceAccessTest {
10 public static void main(String[] args) {
Christoffer Quist Adamsen510b7992018-06-20 12:53:32 +020011 // Without access modifications, it is not possible to merge the interface SimpleInterface into
12 // SimpleInterfaceImpl, since this would lead to an illegal class access here.
13 SimpleInterface x = SimpleInterfaceImplRetriever.getSimpleInterfaceImpl();
14 x.foo();
15
16 // Without access modifications, it is not possible to merge the interface OtherSimpleInterface
17 // into OtherSimpleInterfaceImpl, since this could lead to an illegal class access if another
18 // package references OtherSimpleInterface.
19 OtherSimpleInterface y = new OtherSimpleInterfaceImpl();
20 y.bar();
Christoffer Quist Adamsenbfdbe602019-10-18 12:03:31 +020021
22 // Ensure that the instantiations are not dead code eliminated.
23 escape(x);
24 escape(y);
25 }
26
27 @NeverInline
28 static void escape(Object o) {
29 if (System.currentTimeMillis() < 0) {
30 System.out.println(o);
31 }
Christoffer Quist Adamsen510b7992018-06-20 12:53:32 +020032 }
33
34 // Should only be merged into OtherSimpleInterfaceImpl if access modifications are allowed.
Christoffer Quist Adamsen6fe706d2021-05-21 08:49:12 +020035 @NoHorizontalClassMerging
Christoffer Quist Adamsen510b7992018-06-20 12:53:32 +020036 public interface SimpleInterface {
37
38 void foo();
39 }
40
41 // Should only be merged into OtherSimpleInterfaceImpl if access modifications are allowed.
Christoffer Quist Adamsen6fe706d2021-05-21 08:49:12 +020042 @NoHorizontalClassMerging
Christoffer Quist Adamsen510b7992018-06-20 12:53:32 +020043 public interface OtherSimpleInterface {
44
45 void bar();
46 }
47
Christoffer Quist Adamsen801af252023-06-21 14:20:08 +020048 @NoAccessModification
Christoffer Quist Adamsen510b7992018-06-20 12:53:32 +020049 private static class OtherSimpleInterfaceImpl implements OtherSimpleInterface {
50
51 @Override
52 public void bar() {
53 System.out.println("In bar on OtherSimpleInterfaceImpl");
54 }
Christoffer Quist Adamsen10c8a162018-06-11 09:53:03 +020055 }
56}