'is' operator uses not-null type and doesn't generate parentheses
This commit is contained in:
committed by
Pavel V. Talanov
parent
f88f07a6f5
commit
d4c7b7b2b7
@@ -1,38 +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;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class IsOperator extends Expression {
|
||||
private final Expression myExpression;
|
||||
private final Element myTypeElement;
|
||||
|
||||
public IsOperator(Expression expression, Element typeElement) {
|
||||
myExpression = expression;
|
||||
myTypeElement = typeElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "(" + myExpression.toKotlin() + SPACE + "is" + SPACE + myTypeElement.toKotlin() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class IsOperator(val expression: Expression, val typeElement: TypeElement): Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
return expression.toKotlin() + " is " + typeElement.`type`.convertedToNotNull().toKotlin()
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.j2k.ast.types.EmptyType;
|
||||
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
|
||||
@@ -189,9 +190,10 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
@Override
|
||||
public void visitInstanceOfExpression(@NotNull PsiInstanceOfExpression expression) {
|
||||
super.visitInstanceOfExpression(expression);
|
||||
PsiTypeElement checkType = expression.getCheckType();
|
||||
myResult = new IsOperator(
|
||||
getConverter().expressionToExpression(expression.getOperand()),
|
||||
getConverter().elementToElement(expression.getCheckType()));
|
||||
new TypeElement(checkType == null ? new EmptyType() : myConverter.typeToType(checkType.getType())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1 +1 @@
|
||||
(c.getType().getName() is String?)
|
||||
c.getType().getName() is String
|
||||
@@ -1 +1 @@
|
||||
(a is String?)
|
||||
a is String
|
||||
Reference in New Issue
Block a user