no more conversions in MethodCallExpression
This commit is contained in:
committed by
Pavel V. Talanov
parent
d5900a58b2
commit
1ddde183f5
@@ -761,35 +761,6 @@ public class Converter {
|
|||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public List<String> createConversions(@NotNull PsiCallExpression expression) {
|
|
||||||
PsiExpressionList argumentList = expression.getArgumentList();
|
|
||||||
PsiExpression[] arguments = argumentList != null ? argumentList.getExpressions() : new PsiExpression[]{};
|
|
||||||
List<String> conversions = new LinkedList<String>();
|
|
||||||
//noinspection UnusedDeclaration
|
|
||||||
for (final PsiExpression a : arguments) {
|
|
||||||
conversions.add("");
|
|
||||||
}
|
|
||||||
|
|
||||||
PsiMethod resolve = expression.resolveMethod();
|
|
||||||
if (resolve != null) {
|
|
||||||
List<PsiType> expectedTypes = new LinkedList<PsiType>();
|
|
||||||
List<PsiType> actualTypes = new LinkedList<PsiType>();
|
|
||||||
|
|
||||||
for (PsiParameter p : resolve.getParameterList().getParameters())
|
|
||||||
expectedTypes.add(p.getType());
|
|
||||||
|
|
||||||
for (PsiExpression e : arguments)
|
|
||||||
actualTypes.add(e.getType());
|
|
||||||
|
|
||||||
if (conversions.size() == actualTypes.size() && actualTypes.size() == expectedTypes.size()) {
|
|
||||||
for (int i = 0; i < actualTypes.size(); i++)
|
|
||||||
conversions.set(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return conversions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> createConversions(@NotNull PsiPolyadicExpression expression, PsiType expectedType) {
|
public List<String> createConversions(@NotNull PsiPolyadicExpression expression, PsiType expectedType) {
|
||||||
PsiExpression[] arguments = expression.getOperands();
|
PsiExpression[] arguments = expression.getOperands();
|
||||||
|
|||||||
@@ -1,61 +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.ast.types.Type;
|
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class MethodCallExpression extends Expression {
|
|
||||||
private final Expression myMethodCall;
|
|
||||||
private final List<Expression> myArguments;
|
|
||||||
private final List<String> myConversions;
|
|
||||||
private final boolean myIsResultNullable;
|
|
||||||
private final List<Type> myTypeParameters;
|
|
||||||
|
|
||||||
public MethodCallExpression(Expression methodCall, List<Expression> arguments, List<Type> typeParameters) {
|
|
||||||
this(methodCall, arguments, AstUtil.createListWithEmptyString(arguments), typeParameters, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodCallExpression(Expression methodCall, List<Expression> arguments, List<String> conversions, List<Type> typeParameters, boolean nullable) {
|
|
||||||
myMethodCall = methodCall;
|
|
||||||
myArguments = arguments;
|
|
||||||
myConversions = conversions;
|
|
||||||
myIsResultNullable = nullable;
|
|
||||||
myTypeParameters = typeParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNullable() {
|
|
||||||
return myMethodCall.isNullable() || myIsResultNullable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
String typeParamsToKotlin = myTypeParameters.size() > 0
|
|
||||||
? "<" + AstUtil.joinNodes(myTypeParameters, COMMA_WITH_SPACE) + ">"
|
|
||||||
: EMPTY;
|
|
||||||
List<String> applyConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myArguments), myConversions);
|
|
||||||
return myMethodCall.toKotlin() + typeParamsToKotlin + "(" + AstUtil.join(applyConversions, COMMA_WITH_SPACE) + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
import org.jetbrains.jet.j2k.util.AstUtil
|
||||||
|
import java.util.List
|
||||||
|
|
||||||
|
public open class MethodCallExpression(val methodCall: Expression,
|
||||||
|
val arguments: List<Expression>,
|
||||||
|
val typeParameters: List<Type>,
|
||||||
|
val resultIsNullable: Boolean = false): Expression() {
|
||||||
|
public override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable
|
||||||
|
|
||||||
|
public override fun toKotlin(): String {
|
||||||
|
val typeParamsToKotlin: String? = (if (typeParameters.size() > 0)
|
||||||
|
"<" + AstUtil.joinNodes(typeParameters, ", ") + ">"
|
||||||
|
else
|
||||||
|
"")
|
||||||
|
val argumentsMapped = arguments.map { it.toKotlin() }
|
||||||
|
return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,8 +236,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
|||||||
myResult = // TODO: not resolved
|
myResult = // TODO: not resolved
|
||||||
new MethodCallExpression(
|
new MethodCallExpression(
|
||||||
getConverter().expressionToExpression(expression.getMethodExpression()),
|
getConverter().expressionToExpression(expression.getMethodExpression()),
|
||||||
getConverter().expressionsToExpressionList(expression.getArgumentList().getExpressions()),
|
getConverter().argumentsToExpressionList(expression),
|
||||||
getConverter().createConversions(expression),
|
|
||||||
getConverter().typesToTypeList(expression.getTypeArguments()), getConverter().typeToType(expression.getType()).getNullable()
|
getConverter().typesToTypeList(expression.getTypeArguments()), getConverter().typeToType(expression.getType()).getNullable()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -289,7 +288,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
|||||||
new MethodCallExpression(
|
new MethodCallExpression(
|
||||||
new IdentifierImpl("init"),
|
new IdentifierImpl("init"),
|
||||||
getConverter().expressionsToExpressionList(arguments),
|
getConverter().expressionsToExpressionList(arguments),
|
||||||
typeParameters));
|
typeParameters, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ open fun putInt(i : Int?) : Unit {
|
|||||||
}
|
}
|
||||||
open fun test() : Unit {
|
open fun test() : Unit {
|
||||||
var b : Byte = 10
|
var b : Byte = 10
|
||||||
putInt((b).toInt())
|
putInt(b.toInt())
|
||||||
var b2 : Byte? = 10
|
var b2 : Byte? = 10
|
||||||
putInt((b2).toInt())
|
putInt(b2.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@ open fun putInt(i : Int) : Unit {
|
|||||||
}
|
}
|
||||||
open fun test() : Unit {
|
open fun test() : Unit {
|
||||||
var b : Byte = 10
|
var b : Byte = 10
|
||||||
putInt((b).toInt())
|
putInt(b.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ open class Test() {
|
|||||||
open fun putInt(i : Int) : Unit {
|
open fun putInt(i : Int) : Unit {
|
||||||
}
|
}
|
||||||
open fun test() : Unit {
|
open fun test() : Unit {
|
||||||
putInt((One.myContainer?.myInt).sure())
|
putInt(One.myContainer?.myInt!!)
|
||||||
IntContainer(One.myContainer?.myInt!!)
|
IntContainer(One.myContainer?.myInt!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user