we don't need no DummyMethodCallExpression

This commit is contained in:
Dmitry Jemerov
2012-06-01 18:08:42 +02:00
committed by Pavel V. Talanov
parent 192cdd7028
commit 152d214870
6 changed files with 16 additions and 16 deletions
+2 -2
View File
@@ -465,7 +465,7 @@ public open class Converter() {
{ {
val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText()) val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
if (conversion != null) { if (conversion != null) {
expression = DummyMethodCallExpression(expression, conversion, Identifier.EMPTY_IDENTIFIER) expression = MethodCallExpression.build(expression, conversion)
} }
} }
@@ -476,7 +476,7 @@ public open class Converter() {
class object { class object {
public val NOT_NULL_ANNOTATIONS: Set<String> = ImmutableSet.of<String>("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!! public val NOT_NULL_ANNOTATIONS: Set<String> = ImmutableSet.of<String>("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!!
private val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = ImmutableMap.builder<String, String>() public val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = ImmutableMap.builder<String, String>()
?.put("byte", BYTE.getName()) ?.put("byte", BYTE.getName())
?.put("short", SHORT.getName()) ?.put("short", SHORT.getName())
?.put("int", INT.getName()) ?.put("int", INT.getName())
@@ -1,8 +0,0 @@
package org.jetbrains.jet.j2k.ast
public open class DummyMethodCallExpression(val who: Element, val methodName: String, val what: Element): Expression() {
public override fun toKotlin(): String {
return who.toKotlin() + "." + methodName + "(" + what.toKotlin() + ")"
}
}
@@ -14,4 +14,12 @@ public open class MethodCallExpression(val methodCall: Expression,
val argumentsMapped = arguments.map { it.toKotlin() } val argumentsMapped = arguments.map { it.toKotlin() }
return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")" return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")"
} }
class object {
fun build(receiver: Expression, methodName: String, arguments: List<Expression> = arrayList()): MethodCallExpression {
return MethodCallExpression(CallChainExpression(receiver, Identifier(methodName, false)),
arguments,
arrayList(), false)
}
}
} }
@@ -59,7 +59,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
val lhs = getConverter().expressionToExpression(expression?.getLOperand()!!, expression?.getType()) val lhs = getConverter().expressionToExpression(expression?.getLOperand()!!, expression?.getType())
val rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType()) val rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType())
if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) { if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) {
myResult = DummyMethodCallExpression(lhs, "ushr", rhs) myResult = MethodCallExpression.build(lhs, "ushr", arrayList(rhs))
} }
else { else {
myResult = BinaryExpression(lhs, rhs, myResult = BinaryExpression(lhs, rhs,
@@ -204,7 +204,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
val operand = getConverter().expressionToExpression(expression?.getOperand(), expression?.getOperand()!!.getType()) val operand = getConverter().expressionToExpression(expression?.getOperand(), expression?.getOperand()!!.getType())
val token = expression?.getOperationTokenType()!! val token = expression?.getOperationTokenType()!!
if (token == JavaTokenType.TILDE) { if (token == JavaTokenType.TILDE) {
myResult = DummyMethodCallExpression(ParenthesizedExpression(operand), "inv", Expression.EMPTY_EXPRESSION) myResult = MethodCallExpression.build(ParenthesizedExpression(operand), "inv", arrayList())
} }
else { else {
myResult = PrefixOperator(getOperatorString(token), operand) myResult = PrefixOperator(getOperatorString(token), operand)
@@ -2,19 +2,19 @@ package org.jetbrains.jet.j2k.visitors
import com.intellij.psi.* import com.intellij.psi.*
import org.jetbrains.jet.j2k.Converter import org.jetbrains.jet.j2k.Converter
import org.jetbrains.jet.j2k.ast.DummyMethodCallExpression
import org.jetbrains.jet.j2k.ast.DummyStringExpression import org.jetbrains.jet.j2k.ast.DummyStringExpression
import org.jetbrains.jet.j2k.ast.Identifier import org.jetbrains.jet.j2k.ast.Identifier
import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
import org.jetbrains.jet.j2k.ast.MethodCallExpression
public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) { public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) {
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
val methodExpression = expression?.getMethodExpression()!! val methodExpression = expression?.getMethodExpression()!!
if (superMethodInvocation(methodExpression, "hashCode")) { if (superMethodInvocation(methodExpression, "hashCode")) {
myResult = DummyMethodCallExpression(Identifier("System"), "identityHashCode", Identifier("this")) myResult = MethodCallExpression.build(Identifier("System", false), "identityHashCode", arrayList(Identifier("this")))
} }
else if (superMethodInvocation(methodExpression, "equals")) { else if (superMethodInvocation(methodExpression, "equals")) {
myResult = DummyMethodCallExpression(Identifier("this"), "identityEquals", getConverter().elementToElement(expression?.getArgumentList())) myResult = MethodCallExpression.build(Identifier("this", false), "identityEquals", getConverter().argumentsToExpressionList(expression!!))
} }
else if (superMethodInvocation(methodExpression, "toString")) { else if (superMethodInvocation(methodExpression, "toString")) {
myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())",
@@ -6,6 +6,6 @@ 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())
} }
} }