-
Notifications
You must be signed in to change notification settings - Fork 316
/
CompilerBug424763Test.xtend
393 lines (329 loc) · 10.5 KB
/
CompilerBug424763Test.xtend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*******************************************************************************
* Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtend.core.tests.compiler
import org.junit.Test
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
class CompilerBug424763Test extends AbstractXtendCompilerTest {
@Test def void testBug_424763_01() {
assertCompilesTo('''
import static com.google.common.base.Preconditions.*
class NoConstructor<JAVA_TYPE> implements Functions.Function0<JAVA_TYPE> {
val String type
new(String theTypeName) {
type = checkNotNull(theTypeName, "theTypeName")
}
new(Class<JAVA_TYPE> theType) {
type = checkNotNull(theType, "theType").name
}
override apply() {
throw new UnsupportedOperationException("Instances of type "+type
+" cannot be created (without parameters?)")
}
}
class Test<JAVA_TYPE> {
val Functions.Function0<JAVA_TYPE> constructor
new(Functions.Function0<JAVA_TYPE> theConstructor,
Class<JAVA_TYPE> theType) {
constructor = if (theConstructor == null)
new NoConstructor<JAVA_TYPE>(theType) else theConstructor
}
def static test(){
new Test(null, String)
}
}
''', '''
import com.google.common.base.Preconditions;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class NoConstructor<JAVA_TYPE extends Object> implements Function0<JAVA_TYPE> {
private final String type;
public NoConstructor(final String theTypeName) {
this.type = Preconditions.<String>checkNotNull(theTypeName, "theTypeName");
}
public NoConstructor(final Class<JAVA_TYPE> theType) {
this.type = Preconditions.<Class<JAVA_TYPE>>checkNotNull(theType, "theType").getName();
}
public JAVA_TYPE apply() {
throw new UnsupportedOperationException(
(("Instances of type " + this.type) + " cannot be created (without parameters?)"));
}
}
''')
}
@Test def void testBug_424763_02() {
assertCompilesTo('''
import static com.google.common.base.Preconditions.*
class Test<JAVA_TYPE> {
val Functions.Function0<JAVA_TYPE> constructor
val list = new java.util.ArrayList(1)
new(Functions.Function0<JAVA_TYPE> theConstructor, Class<JAVA_TYPE> theType) {
constructor = if (theConstructor == null)
new NoConstructor<JAVA_TYPE>(theType)
else
theConstructor
}
def static test(){
new Test(null, String)
}
}
class NoConstructor<JAVA_TYPE> implements Functions.Function0<JAVA_TYPE> {
val String type
new(String theTypeName) {
type = checkNotNull(theTypeName, "theTypeName")
}
new(Class<JAVA_TYPE> theType) {
type = checkNotNull(theType, "theType").name
}
override apply() {
throw new UnsupportedOperationException("Instances of type "+type
+" cannot be created (without parameters?)")
}
}
''', '''
import java.util.ArrayList;
import java.util.Objects;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class Test<JAVA_TYPE extends Object> {
private final Function0<JAVA_TYPE> constructor;
private final ArrayList<Object> list = new ArrayList<Object>(1);
public Test(final Function0<JAVA_TYPE> theConstructor, final Class<JAVA_TYPE> theType) {
Function0<JAVA_TYPE> _xifexpression = null;
boolean _equals = Objects.equals(theConstructor, null);
if (_equals) {
_xifexpression = new NoConstructor<JAVA_TYPE>(theType);
} else {
_xifexpression = theConstructor;
}
this.constructor = _xifexpression;
}
public static Test<String> test() {
return new Test<String>(null, String.class);
}
}
''')
}
@Test def void testBug_424763_03() {
assertCompilesTo('''
class C<T> {
val Functions.Function0<T> constructor
new(C<T> theConstructor) {
this.constructor = theConstructor?.constructor
}
}
''', '''
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class C<T extends Object> {
private final Function0<T> constructor;
public C(final C<T> theConstructor) {
Function0<T> _constructor = null;
if (theConstructor!=null) {
_constructor=theConstructor.constructor;
}
this.constructor = _constructor;
}
}
''')
}
@Test def void testBug_424763_04() {
assertCompilesTo('''
class C<T> {
val Functions.Function0<T> constructor
new(C<T> theConstructor) {
this.constructor = theConstructor?.doGetConstructor(try {''} finally {})
}
def doGetConstructor(String s) {
constructor
}
}
''', '''
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class C<T extends Object> {
private final Function0<T> constructor;
public C(final C<T> theConstructor) {
Function0<T> _doGetConstructor = null;
if (theConstructor!=null) {
String _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = "";
} finally {
}
_doGetConstructor=theConstructor.doGetConstructor(_xtrycatchfinallyexpression);
}
this.constructor = _doGetConstructor;
}
public Function0<T> doGetConstructor(final String s) {
return this.constructor;
}
}
''')
}
@Test def void testBug_424763_05() {
assertCompilesTo('''
import static com.google.common.base.Preconditions.*
class Test<JAVA_TYPE> {
val Functions.Function0<JAVA_TYPE> constructor
new(Functions.Function0<JAVA_TYPE> theConstructor, Class<JAVA_TYPE> theType) {
constructor = if (theConstructor == null)
new NoConstructor<JAVA_TYPE>(try { theType } finally {})
else
theConstructor
}
def static test(){
new Test(null, String)
}
}
class NoConstructor<JAVA_TYPE> implements Functions.Function0<JAVA_TYPE> {
val String type
new(String theTypeName) {
type = checkNotNull(theTypeName, "theTypeName")
}
new(Class<JAVA_TYPE> theType) {
type = checkNotNull(theType, "theType").name
}
override apply() {
throw new UnsupportedOperationException("Instances of type "+type
+" cannot be created (without parameters?)")
}
}
''', '''
import java.util.Objects;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class Test<JAVA_TYPE extends Object> {
private final Function0<JAVA_TYPE> constructor;
public Test(final Function0<JAVA_TYPE> theConstructor, final Class<JAVA_TYPE> theType) {
Function0<JAVA_TYPE> _xifexpression = null;
boolean _equals = Objects.equals(theConstructor, null);
if (_equals) {
Class<JAVA_TYPE> _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = theType;
} finally {
}
_xifexpression = new NoConstructor<JAVA_TYPE>(_xtrycatchfinallyexpression);
} else {
_xifexpression = theConstructor;
}
this.constructor = _xifexpression;
}
public static Test<String> test() {
return new Test<String>(null, String.class);
}
}
''')
}
@Test def void testBug_424763_06() {
assertCompilesTo('''
class C<T> {
val Functions.Function0<T> constructor
new(C<T> theConstructor) {
this(theConstructor?.constructor)
}
new(Functions.Function0<T> f) {
this.constructor = f
}
}
''', '''
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class C<T extends Object> {
private final Function0<T> constructor;
public C(final C<T> theConstructor) {
this(new Function0<Function0<T>>() {
public Function0<T> apply() {
Function0<T> _constructor = null;
if (theConstructor!=null) {
_constructor=theConstructor.constructor;
}
return _constructor;
}
}.apply());
}
public C(final Function0<T> f) {
this.constructor = f;
}
}
''')
}
@Test def void testBug_424763_07() {
assertCompilesTo('''
class C<T> {
val Functions.Function0<T> constructor
new(C<T> theConstructor) {
this.constructor = theConstructor.doGetConstructor(try {''} finally {})
}
def doGetConstructor(String s) {
constructor
}
}
''', '''
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class C<T extends Object> {
private final Function0<T> constructor;
public C(final C<T> theConstructor) {
String _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = "";
} finally {
}
this.constructor = theConstructor.doGetConstructor(_xtrycatchfinallyexpression);
}
public Function0<T> doGetConstructor(final String s) {
return this.constructor;
}
}
''')
}
@Test def void testBug_424763_08() {
assertCompilesTo('''
class C<T> {
val Functions.Function0<T> constructor
new(C<T> theConstructor) {
this(theConstructor.doGetConstructor(try {''} finally {}))
}
new(Functions.Function0<T> f) {
this.constructor = f
}
def doGetConstructor(String s) {
constructor
}
}
''', '''
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class C<T extends Object> {
private final Function0<T> constructor;
public C(final C<T> theConstructor) {
this(theConstructor.doGetConstructor(new Function0<String>() {
public String apply() {
String _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = "";
} finally {
}
return _xtrycatchfinallyexpression;
}
}.apply()));
}
public C(final Function0<T> f) {
this.constructor = f;
}
public Function0<T> doGetConstructor(final String s) {
return this.constructor;
}
}
''')
}
}