Made foreach work with nullable iterables
This commit is contained in:
committed by
Pavel V. Talanov
parent
475d02a80f
commit
55c00b08e7
@@ -107,8 +107,15 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
}
|
||||
|
||||
public override fun visitForeachStatement(statement: PsiForeachStatement?): Unit {
|
||||
val iterator = {
|
||||
val iteratorExpr = getConverter().expressionToExpression(statement?.getIteratedValue())
|
||||
if (iteratorExpr.isNullable())
|
||||
BangBangExpression(iteratorExpr)
|
||||
else
|
||||
iteratorExpr
|
||||
}()
|
||||
myResult = ForeachStatement(getConverter().parameterToParameter(statement?.getIterationParameter()!!),
|
||||
getConverter().expressionToExpression(statement?.getIteratedValue()),
|
||||
iterator,
|
||||
getConverter().statementToStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.*;
|
||||
|
||||
public class ForEach {
|
||||
public void test() {
|
||||
ArrayList<Object> xs = new ArrayList<Object>();
|
||||
List<Object> ys = new LinkedList<Object>();
|
||||
for (Object x : xs) {
|
||||
ys.add(x);
|
||||
}
|
||||
for (Object y : ys) {
|
||||
xs.add(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.*
|
||||
public open class ForEach() {
|
||||
public open fun test() : Unit {
|
||||
var xs : ArrayList<Any?>? = ArrayList<Any?>()
|
||||
var ys : MutableList<Any?>? = LinkedList<Any?>()
|
||||
for (x : Any? in xs!!)
|
||||
{
|
||||
ys?.add(x)
|
||||
}
|
||||
for (y : Any? in ys!!)
|
||||
{
|
||||
xs?.add(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user