no more conversions in PolyadicExpression

This commit is contained in:
Dmitry Jemerov
2012-05-24 21:33:04 +02:00
committed by Pavel V. Talanov
parent 1ddde183f5
commit 6da7fc9799
4 changed files with 17 additions and 69 deletions
-20
View File
@@ -761,26 +761,6 @@ public class Converter {
return expression;
}
@NotNull
public List<String> createConversions(@NotNull PsiPolyadicExpression expression, PsiType expectedType) {
PsiExpression[] arguments = expression.getOperands();
int length = arguments.length;
List<String> conversions = new LinkedList<String>();
List<PsiType> expectedTypes = Collections.nCopies(length, expectedType);
List<PsiType> actualTypes = new LinkedList<PsiType>();
for (PsiExpression e : arguments)
actualTypes.add(e.getType());
assert actualTypes.size() == expectedTypes.size() : "The type list must have the same length";
for (int i = 0; i < actualTypes.size(); i++)
conversions.add(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));
return conversions;
}
@NotNull
private String createConversionForExpression(@Nullable PsiExpression expression, @NotNull PsiType expectedType) {
String conversion = "";
@@ -1,45 +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.List;
/**
* @author ignatov
*/
public class PolyadicExpression extends Expression {
private final List<Expression> myExpressions;
private final String myToken;
private final List<String> myConversions;
public PolyadicExpression(List<Expression> expressions, String token, List<String> conversions) {
super();
myExpressions = expressions;
myToken = token;
myConversions = conversions;
}
@NotNull
@Override
public String toKotlin() {
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myExpressions), myConversions);
return AstUtil.join(expressionsWithConversions, SPACE + myToken + SPACE);
}
}
@@ -0,0 +1,10 @@
package org.jetbrains.jet.j2k.ast
import java.util.List
public open class PolyadicExpression(val expressions: List<Expression>, val token: String): Expression() {
public override fun toKotlin(): String {
val expressionsWithConversions = expressions.map { it.toKotlin() }
return expressionsWithConversions.makeString(" " + token + " ")
}
}
@@ -25,6 +25,7 @@ import org.jetbrains.jet.j2k.ast.*;
import org.jetbrains.jet.j2k.ast.types.Type;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -493,11 +494,13 @@ public class ExpressionVisitor extends StatementVisitor {
@Override
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
super.visitPolyadicExpression(expression);
List<Expression> parameters = new ArrayList<Expression>();
for (PsiExpression operand : expression.getOperands()) {
parameters.add(getConverter().expressionToExpression(operand, expression.getType()));
}
myResult = new PolyadicExpression(
getConverter().expressionsToExpressionList(expression.getOperands()),
getOperatorString(expression.getOperationTokenType()),
getConverter().createConversions(expression, PsiType.BOOLEAN)
parameters,
getOperatorString(expression.getOperationTokenType())
);
}
}