we don't need no DummyMethodCallExpression
This commit is contained in:
committed by
Pavel V. Talanov
parent
192cdd7028
commit
152d214870
@@ -465,7 +465,7 @@ public open class Converter() {
|
||||
{
|
||||
val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
|
||||
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 {
|
||||
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("short", SHORT.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() }
|
||||
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 rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType())
|
||||
if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) {
|
||||
myResult = DummyMethodCallExpression(lhs, "ushr", rhs)
|
||||
myResult = MethodCallExpression.build(lhs, "ushr", arrayList(rhs))
|
||||
}
|
||||
else {
|
||||
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 token = expression?.getOperationTokenType()!!
|
||||
if (token == JavaTokenType.TILDE) {
|
||||
myResult = DummyMethodCallExpression(ParenthesizedExpression(operand), "inv", Expression.EMPTY_EXPRESSION)
|
||||
myResult = MethodCallExpression.build(ParenthesizedExpression(operand), "inv", arrayList())
|
||||
}
|
||||
else {
|
||||
myResult = PrefixOperator(getOperatorString(token), operand)
|
||||
|
||||
@@ -2,19 +2,19 @@ package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import com.intellij.psi.*
|
||||
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.Identifier
|
||||
import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
|
||||
import org.jetbrains.jet.j2k.ast.MethodCallExpression
|
||||
|
||||
public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
val methodExpression = expression?.getMethodExpression()!!
|
||||
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")) {
|
||||
myResult = DummyMethodCallExpression(Identifier("this"), "identityEquals", getConverter().elementToElement(expression?.getArgumentList()))
|
||||
myResult = MethodCallExpression.build(Identifier("this", false), "identityEquals", getConverter().argumentsToExpressionList(expression!!))
|
||||
}
|
||||
else if (superMethodInvocation(methodExpression, "toString")) {
|
||||
myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())",
|
||||
|
||||
@@ -6,6 +6,6 @@ open fun test() : Unit {
|
||||
var b : Byte = 10
|
||||
putInt(b.toInt())
|
||||
var b2 : Byte? = 10
|
||||
putInt(b2.toInt())
|
||||
putInt(b2?.toInt())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user