author | jlahoda |
Wed, 27 Nov 2019 09:00:01 +0100 | |
changeset 59285 | 7799a51dbe30 |
parent 55306 | ea43db53de91 |
permissions | -rw-r--r-- |
49429 | 1 |
/* |
2 |
* Copyright (c) 2018, Google LLC. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
package com.sun.tools.javac.comp; |
|
25 |
||
26 |
import java.util.function.BiFunction; |
|
27 |
import java.util.function.Consumer; |
|
28 |
import java.util.function.Function; |
|
29 |
import java.util.function.Supplier; |
|
30 |
||
31 |
public class Deduplication { |
|
32 |
void group(Object... xs) {} |
|
33 |
||
34 |
void test() { |
|
49577
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
35 |
|
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
36 |
group( |
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
37 |
(Runnable) () -> { ( (Runnable) () -> {} ).run(); }, |
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
38 |
(Runnable) () -> { ( (Runnable) () -> {} ).run(); } |
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
39 |
); |
faf02d65df7d
8201440: javac should create unique DynamicMethodSymbols at LambdaToMethod
vromero
parents:
49541
diff
changeset
|
40 |
|
49887 | 41 |
group( |
42 |
(Runnable) () -> { Deduplication.class.toString(); }, |
|
43 |
(Runnable) () -> { Deduplication.class.toString(); } |
|
44 |
); |
|
45 |
||
46 |
group( |
|
47 |
(Runnable) () -> { Integer[].class.toString(); }, |
|
48 |
(Runnable) () -> { Integer[].class.toString(); } |
|
49 |
); |
|
50 |
||
51 |
group( |
|
52 |
(Runnable) () -> { char.class.toString(); }, |
|
53 |
(Runnable) () -> { char.class.toString(); } |
|
54 |
); |
|
55 |
||
56 |
group( |
|
57 |
(Runnable) () -> { Void.class.toString(); }, |
|
58 |
(Runnable) () -> { Void.class.toString(); } |
|
59 |
); |
|
60 |
||
61 |
group( |
|
62 |
(Runnable) () -> { void.class.toString(); }, |
|
63 |
(Runnable) () -> { void.class.toString(); } |
|
64 |
); |
|
65 |
||
49429 | 66 |
group((Function<String, Integer>) x -> x.hashCode()); |
67 |
group((Function<Object, Integer>) x -> x.hashCode()); |
|
68 |
||
69 |
{ |
|
70 |
int x = 1; |
|
71 |
group((Supplier<Integer>) () -> x + 1); |
|
72 |
} |
|
73 |
{ |
|
74 |
int x = 1; |
|
75 |
group((Supplier<Integer>) () -> x + 1); |
|
76 |
} |
|
77 |
group( |
|
78 |
(BiFunction<Integer, Integer, ?>) (x, y) -> x + ((y)), |
|
79 |
(BiFunction<Integer, Integer, ?>) (x, y) -> x + (y), |
|
80 |
(BiFunction<Integer, Integer, ?>) (x, y) -> x + y, |
|
81 |
(BiFunction<Integer, Integer, ?>) (x, y) -> (x) + ((y)), |
|
82 |
(BiFunction<Integer, Integer, ?>) (x, y) -> (x) + (y), |
|
83 |
(BiFunction<Integer, Integer, ?>) (x, y) -> (x) + y, |
|
84 |
(BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + ((y)), |
|
85 |
(BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + (y), |
|
86 |
(BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + y); |
|
87 |
||
88 |
group( |
|
89 |
(Function<Integer, Integer>) x -> x + (1 + 2 + 3), |
|
90 |
(Function<Integer, Integer>) x -> x + 6); |
|
91 |
||
92 |
group((Function<Integer, Integer>) x -> x + 1, (Function<Integer, Integer>) y -> y + 1); |
|
93 |
||
94 |
group((Consumer<Integer>) x -> this.f(), (Consumer<Integer>) x -> this.f()); |
|
95 |
||
96 |
group((Consumer<Integer>) y -> this.g()); |
|
97 |
||
98 |
group((Consumer<Integer>) x -> f(), (Consumer<Integer>) x -> f()); |
|
99 |
||
100 |
group((Consumer<Integer>) y -> g()); |
|
101 |
||
102 |
group((Function<Integer, Integer>) x -> this.i, (Function<Integer, Integer>) x -> this.i); |
|
103 |
||
104 |
group((Function<Integer, Integer>) y -> this.j); |
|
105 |
||
106 |
group((Function<Integer, Integer>) x -> i, (Function<Integer, Integer>) x -> i); |
|
107 |
||
108 |
group((Function<Integer, Integer>) y -> j); |
|
109 |
||
110 |
group( |
|
49541
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
111 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
112 |
y -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
113 |
while (true) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
114 |
break; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
115 |
} |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
116 |
return 42; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
117 |
}, |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
118 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
119 |
y -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
120 |
while (true) { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
121 |
break; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
122 |
} |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
123 |
return 42; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
124 |
}); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
125 |
|
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
126 |
group( |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
127 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
128 |
x -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
129 |
int y = x; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
130 |
return y; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
131 |
}, |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
132 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
133 |
x -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
134 |
int y = x; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
135 |
return y; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
136 |
}); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
137 |
|
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
138 |
group( |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
139 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
140 |
x -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
141 |
int y = 0, z = x; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
142 |
return y; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
143 |
}); |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
144 |
group( |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
145 |
(Function<Integer, Integer>) |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
146 |
x -> { |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
147 |
int y = 0, z = x; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
148 |
return z; |
4f6887eade94
8201194: Handle local variable declarations in lambda deduplication
cushon
parents:
49429
diff
changeset
|
149 |
}); |
49429 | 150 |
|
151 |
class Local { |
|
152 |
int i; |
|
153 |
||
154 |
void f() {} |
|
155 |
||
156 |
{ |
|
157 |
group((Function<Integer, Integer>) x -> this.i); |
|
158 |
group((Consumer<Integer>) x -> this.f()); |
|
159 |
group((Function<Integer, Integer>) x -> Deduplication.this.i); |
|
160 |
group((Consumer<Integer>) x -> Deduplication.this.f()); |
|
161 |
} |
|
162 |
} |
|
55306 | 163 |
|
164 |
group((Function<Integer, Integer>) x -> switch (x) { default: yield x; }, |
|
165 |
(Function<Integer, Integer>) x -> switch (x) { default: yield x; }); |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
166 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
167 |
group((Function<Object, Integer>) x -> x instanceof Integer i ? i : -1, |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
55306
diff
changeset
|
168 |
(Function<Object, Integer>) x -> x instanceof Integer i ? i : -1); |
49429 | 169 |
} |
170 |
||
171 |
void f() {} |
|
172 |
||
173 |
void g() {} |
|
174 |
||
175 |
int i; |
|
176 |
int j; |
|
177 |
} |