added generic params to method call expression

This commit is contained in:
Sergey Ignatov
2011-11-17 18:34:34 +04:00
parent a08fb4fb0a
commit 09a489f9d4
4 changed files with 35 additions and 4 deletions
@@ -1,6 +1,9 @@
package org.jetbrains.jet.j2k.ast;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.j2k.util.AstUtil;
import java.util.List;
/**
* @author ignatov
@@ -9,11 +12,13 @@ public class MethodCallExpression extends Expression {
private final Expression myMethodCall;
private final Element myParamList;
private final boolean myIsResultNullable;
private List<Type> myTypeParameters;
public MethodCallExpression(Expression methodCall, Element paramList, boolean nullable) {
public MethodCallExpression(Expression methodCall, Element paramList, boolean nullable, List<Type> typeParameters) {
myMethodCall = methodCall;
myParamList = paramList;
myIsResultNullable = nullable;
myTypeParameters = typeParameters;
}
@Override
@@ -24,6 +29,7 @@ public class MethodCallExpression extends Expression {
@NotNull
@Override
public String toKotlin() {
return myMethodCall.toKotlin() + "(" + myParamList.toKotlin() + ")";
String typeParamsToKotlin = myTypeParameters.size() > 0 ? "<" + AstUtil.joinNodes(myTypeParameters, COMMA_WITH_SPACE) + ">" : EMPTY;
return myMethodCall.toKotlin() + typeParamsToKotlin + "(" + myParamList.toKotlin() + ")";
}
}
@@ -170,7 +170,8 @@ public class ExpressionVisitor extends StatementVisitor {
new MethodCallExpression(
expressionToExpression(expression.getMethodExpression()),
elementToElement(expression.getArgumentList()),
typeToType(expression.getType()).isNullable()
typeToType(expression.getType()).isNullable(),
typesToTypeList(expression.getTypeArguments())
);
}
@@ -206,7 +207,7 @@ public class ExpressionVisitor extends StatementVisitor {
if (constructor != null && !isConstructorPrimary(constructor)) {
myResult = new CallChainExpression(
new IdentifierImpl(constructor.getName(), false),
new MethodCallExpression(new IdentifierImpl("init"), elementToElement(expression.getArgumentList()), false));
new MethodCallExpression(new IdentifierImpl("init"), elementToElement(expression.getArgumentList()), false, typesToTypeList(expression.getTypeArguments())));
}
}
}
@@ -0,0 +1,12 @@
package demo;
class Map {
<K, V> void put(K k, V v) {}
}
class U {
void test() {
Map m = new Map();
m.<String, int>put("10", 10);
}
}
@@ -0,0 +1,12 @@
namespace demo {
open class Map() {
open fun put<K, V>(k : K?, v : V?) : Unit {
}
}
open class U() {
open fun test() : Unit {
var m : Map? = Map()
m?.put<String?, Int>("10", 10)
}
}
}