wrappers instead of conversions in binary expressions
This commit is contained in:
committed by
Pavel V. Talanov
parent
512e12d26c
commit
d5900a58b2
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class BinaryExpression extends Expression {
|
||||
private final Expression myLeft;
|
||||
private final Expression myRight;
|
||||
private final String myOp;
|
||||
private final List<String> myConversions;
|
||||
|
||||
public BinaryExpression(Expression left, Expression right, String op) {
|
||||
this(left, right, op, Arrays.asList("", ""));
|
||||
}
|
||||
|
||||
public BinaryExpression(Expression left, Expression right, String op, List<String> conversions) {
|
||||
myLeft = left;
|
||||
myRight = right;
|
||||
myOp = op;
|
||||
myConversions = conversions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(Arrays.asList(myLeft, myRight)), myConversions);
|
||||
return AstUtil.join(expressionsWithConversions, SPACE + myOp + SPACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.Arrays
|
||||
import java.util.List
|
||||
|
||||
public open class BinaryExpression(val left: Expression, val right: Expression, val op: String): Expression() {
|
||||
public override fun toKotlin(): String = left.toKotlin() + " " + op + " " + right.toKotlin()
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class MethodCallExpression extends Expression {
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsResultNullable;
|
||||
return myMethodCall.isNullable() || myIsResultNullable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -150,10 +150,9 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
else {
|
||||
myResult =
|
||||
new BinaryExpression(
|
||||
getConverter().expressionToExpression(expression.getLOperand()),
|
||||
getConverter().expressionToExpression(expression.getROperand()),
|
||||
getOperatorString(expression.getOperationSign().getTokenType()),
|
||||
getConverter().createConversions(expression, PsiType.BOOLEAN)
|
||||
getConverter().expressionToExpression(expression.getLOperand(), expression.getType()),
|
||||
getConverter().expressionToExpression(expression.getROperand(), expression.getType()),
|
||||
getOperatorString(expression.getOperationSign().getTokenType())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ open fun test() : String? {
|
||||
var s1 : String? = ""
|
||||
var s2 : String? = ""
|
||||
var s3 : String? = ""
|
||||
if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure())
|
||||
if (s1?.isEmpty()!! && s2?.isEmpty()!!)
|
||||
return "OK"
|
||||
if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure() && (s3?.isEmpty()).sure())
|
||||
return "OOOK"
|
||||
|
||||
Reference in New Issue
Block a user