blob: e76a8e39a9447ee886cc0d8a160b0e1d6bc2fc3d [file] [log] [blame]
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +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
Christoffer Quist Adamsenf0277632023-05-12 12:25:55 +02007
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +02008public class ConflictInGeneratedNameTest {
9 public static void main(String[] args) {
10 B obj = new B();
11 obj.run();
12 }
13
14 public static class A {
Christoffer Quist Adamsenf0277632023-05-12 12:25:55 +020015 @NeverPropagateValue @NoRedundantFieldLoadElimination private String name = "A";
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +020016
17 public A() {
18 print("In A.<init>()");
Christoffer Quist Adamsen4fcaa652020-11-27 09:49:11 +010019 $r8$constructor$classmerging$ConflictInGeneratedNameTest$A();
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +020020 }
21
Christoffer Quist Adamsen4fcaa652020-11-27 09:49:11 +010022 private void $r8$constructor$classmerging$ConflictInGeneratedNameTest$A() {
23 print("In A.$r8$constructor$classmerging$ConflictInGeneratedNameTest$A()");
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +020024 }
25
26 public void printState() {
27 print("In A.printState()");
28 print("A=" + name + "=" + getName());
29 }
30
31 // This method is not overridden.
32 public void foo() {
33 print("In A.foo()");
34 }
35
36 // This method is overridden.
37 public void bar() {
38 print("In A.bar()");
39 }
40
41 // This method is overridden and there is a PUBLIC method in B with the same name
42 // as the direct version of this method in B.
43 public void baz() {
44 print("In A.baz()");
45 }
46
47 // This method is overridden and there is a PRIVATE method in B with the same name
48 // as the direct version of this method in B.
49 public void boo() {
50 print("In A.boo()");
51 }
52
53 // There is a private method in B with the same name as this one.
Christoffer Quist Adamsen801af252023-06-21 14:20:08 +020054 @NoAccessModification
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +020055 private String getName() {
56 return name;
57 }
58 }
59
60 public static class B extends A {
Christoffer Quist Adamsenf0277632023-05-12 12:25:55 +020061 @NeverPropagateValue @NoRedundantFieldLoadElimination private String name = "B";
62
63 @NeverPropagateValue @NoRedundantFieldLoadElimination
64 private String name$classmerging$ConflictInGeneratedNameTest$A = "C";
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +020065
66 public B() {
67 print("In B.<init>()");
68 print("A=" + super.name + "=" + super.getName());
69 print("B=" + name + "=" + getName());
70 print("C=" + name$classmerging$ConflictInGeneratedNameTest$A);
71 }
72
73 public void run() {
74 printState();
75 foo();
76 bar();
77 baz();
78 baz$classmerging$ConflictInGeneratedNameTest$A();
79 boo();
80 boo$classmerging$ConflictInGeneratedNameTest$A();
81 }
82
83 @Override
84 public void bar() {
85 print("In B.bar()");
86 super.bar();
87 }
88
89 @Override
90 public void baz() {
91 print("In B.baz()");
92 super.baz();
93 }
94
95 public void baz$classmerging$ConflictInGeneratedNameTest$A() {
96 print("In B.baz$classmerging$ConflictInGeneratedNameTest$A()");
97 }
98
99 @Override
100 public void boo() {
101 print("In B.boo()");
102 super.boo();
103 }
104
Christoffer Quist Adamsen801af252023-06-21 14:20:08 +0200105 @NoAccessModification
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +0200106 private void boo$classmerging$ConflictInGeneratedNameTest$A() {
107 print("In B.boo$classmerging$ConflictInGeneratedNameTest$A()");
108 }
109
Christoffer Quist Adamsen801af252023-06-21 14:20:08 +0200110 @NoAccessModification
Christoffer Quist Adamsen1cbc7642018-06-26 09:48:25 +0200111 private String getName() {
112 return name;
113 }
114 }
115
116 public static void print(String message) {
117 System.out.println(message);
118 }
119}