-
Notifications
You must be signed in to change notification settings - Fork 316
/
CompilerBug472142Test.xtend
172 lines (157 loc) · 4.38 KB
/
CompilerBug472142Test.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
/*******************************************************************************
* Copyright (c) 2015, 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 CompilerBug472142Test extends AbstractXtendCompilerTest {
@Test def test_01() {
'''
class C {
def boolean m(CharSequence obj) {
return obj?.subSequence(1,1) instanceof String && obj!==null && obj.getClass()!==null;
}
}
'''.assertCompilesTo('''
@SuppressWarnings("all")
public class C {
public boolean m(final CharSequence obj) {
boolean _and = false;
boolean _and_1 = false;
CharSequence _subSequence = null;
if (obj!=null) {
_subSequence=obj.subSequence(1, 1);
}
if (!(_subSequence instanceof String)) {
_and_1 = false;
} else {
_and_1 = (obj != null);
}
if (!_and_1) {
_and = false;
} else {
Class<? extends CharSequence> _class = obj.getClass();
boolean _tripleNotEquals = (_class != null);
_and = _tripleNotEquals;
}
return _and;
}
}
''')
}
@Test def test_02() {
'''
class C {
def boolean m(CharSequence obj) {
return obj?.subSequence(1,1) instanceof String && obj!==null
}
}
'''.assertCompilesTo('''
@SuppressWarnings("all")
public class C {
public boolean m(final CharSequence obj) {
boolean _and = false;
CharSequence _subSequence = null;
if (obj!=null) {
_subSequence=obj.subSequence(1, 1);
}
if (!(_subSequence instanceof String)) {
_and = false;
} else {
_and = (obj != null);
}
return _and;
}
}
''')
}
@Test def test_03() {
'''
class C {
var CharSequence mySeq
def m() {
if(mySeq == null) {
mySeq = (all('s', ''«»'s2'«»'').subList(1,1).head as String).ext
}
mySeq
}
def java.util.List<CharSequence> all(String s, String s2) {
}
def ext(String s) {
s
}
}
'''.assertCompilesTo('''
import java.util.List;
import java.util.Objects;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class C {
private CharSequence mySeq;
public CharSequence m() {
CharSequence _xblockexpression = null;
{
boolean _equals = Objects.equals(this.mySeq, null);
if (_equals) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("s2");
CharSequence _head = IterableExtensions.<CharSequence>head(this.all("s", _builder.toString()).subList(1, 1));
this.mySeq = this.ext(((String) _head));
}
_xblockexpression = this.mySeq;
}
return _xblockexpression;
}
public List<CharSequence> all(final String s, final String s2) {
return null;
}
public String ext(final String s) {
return s;
}
}
''')
}
@Test def test_04() {
'''
class C {
var boolean b
def m() {
return b = (all('s', ''«»'s2'«»'').subList(1,1).head instanceof String).ext
}
def java.util.List<CharSequence> all(String s, String s2) {
}
def ext(boolean b) {
b
}
}
'''.assertCompilesTo('''
import java.util.List;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class C {
private boolean b;
public boolean m() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("s2");
CharSequence _head = IterableExtensions.<CharSequence>head(this.all("s", _builder.toString()).subList(1, 1));
return this.b = this.ext((_head instanceof String));
}
public List<CharSequence> all(final String s, final String s2) {
return null;
}
public boolean ext(final boolean b) {
return b;
}
}
''')
}
}