-
Notifications
You must be signed in to change notification settings - Fork 316
/
CompilerBug491931Test.xtend
159 lines (147 loc) · 3.62 KB
/
CompilerBug491931Test.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
/*******************************************************************************
* Copyright (c) 2016 TypeFox.io (http://www.typefox.io) 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 Sven Efftinge - Initial contribution and API
*/
class CompilerBug491931Test extends AbstractXtendCompilerTest {
@Test def test_01() {
'''
class C {
def void foo(boolean a, boolean b) {
val boolean x1 = !a && !b
val boolean x2 = a && !b
val boolean x3 = !a && b
val boolean x4 = a && b
println(x1 || x2 || x3 || x4)
}
}
'''.assertCompilesTo('''
import org.eclipse.xtext.xbase.lib.InputOutput;
@SuppressWarnings("all")
public class C {
public void foo(final boolean a, final boolean b) {
final boolean x1 = ((!a) && (!b));
final boolean x2 = (a && (!b));
final boolean x3 = ((!a) && b);
final boolean x4 = (a && b);
InputOutput.<Boolean>println(Boolean.valueOf((((x1 || x2) || x3) || x4)));
}
}
''')
}
@Test def test_02() {
'''
class C {
def boolean foo(boolean a, boolean b) {
return a && b
}
}
'''.assertCompilesTo('''
@SuppressWarnings("all")
public class C {
public boolean foo(final boolean a, final boolean b) {
return (a && b);
}
}
''')
}
@Test def test_03() {
'''
class C {
def boolean foo(boolean a, boolean b) {
return !a && !b
}
}
'''.assertCompilesTo('''
@SuppressWarnings("all")
public class C {
public boolean foo(final boolean a, final boolean b) {
return ((!a) && (!b));
}
}
''')
}
@Test def test_04() {
'''
class C {
def boolean m(Object obj) {
return obj?.toString() instanceof String && obj!==null && obj.getClass()!==null;
}
}
'''.assertCompilesTo('''
@SuppressWarnings("all")
public class C {
public boolean m(final Object obj) {
boolean _and = false;
boolean _and_1 = false;
String _string = null;
if (obj!=null) {
_string=obj.toString();
}
if (!(_string instanceof String)) {
_and_1 = false;
} else {
_and_1 = (obj != null);
}
if (!_and_1) {
_and = false;
} else {
Class<?> _class = obj.getClass();
boolean _tripleNotEquals = (_class != null);
_and = _tripleNotEquals;
}
return _and;
}
}
''')
}
@Test def test_05() {
'''
class C {
def boolean foo(CharSequence obj) {
return !((obj.subSequence(1, 1) instanceof String) && obj != null)
}
}
'''.assertCompilesTo('''
import java.util.Objects;
@SuppressWarnings("all")
public class C {
public boolean foo(final CharSequence obj) {
return (!((obj.subSequence(1, 1) instanceof String) && (!Objects.equals(obj, null))));
}
}
''')
}
@Test def test_06() {
'''
class C {
def void foo(java.util.List<String> l) {
l.add("x") && l.add("y")
}
}
'''.assertCompilesTo('''
import java.util.List;
@SuppressWarnings("all")
public class C {
public void foo(final List<String> l) {
boolean _and = false;
boolean _add = l.add("x");
if (!_add) {
_and = false;
} else {
boolean _add_1 = l.add("y");
_and = _add_1;
}
}
}
''')
}
}