diff --git a/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/expressions.kt b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/expressions.kt new file mode 100644 index 00000000000..047f5f145fe --- /dev/null +++ b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/expressions.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.j2k.tree + +import org.jetbrains.kotlin.j2k.JKSymbolProvider +import org.jetbrains.kotlin.j2k.conversions.resolveFqName +import org.jetbrains.kotlin.j2k.tree.impl.JKClassSymbol +import org.jetbrains.kotlin.j2k.tree.impl.JKClassTypeImpl +import org.jetbrains.kotlin.name.ClassId + +fun kotlinTypeByName(name: String, symbolProvider: JKSymbolProvider): JKClassType { + val symbol = + symbolProvider.provideDirectSymbol( + resolveFqName(ClassId.fromString(name), symbolProvider.symbolsByPsi.keys.first())!! + ) as JKClassSymbol + return JKClassTypeImpl(symbol, emptyList()) +} \ No newline at end of file diff --git a/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/impl/jk.kt b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/impl/jk.kt index 0b340052245..5d1b71a7555 100644 --- a/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/impl/jk.kt +++ b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/impl/jk.kt @@ -139,10 +139,13 @@ class JKBinaryExpressionImpl( else -> TODO(leftType::class.java.toString()) } + val operatorNames = + if(token.operatorName == "equals") listOf("equals", "compareTo") + else listOf(token.operatorName) return classSymbol.target.declarations// todo look for extensions .asSequence() .filterIsInstance() - .filter { it.name == token.operatorName } + .filter { it.name in operatorNames } .mapNotNull { symbolProvider.provideDirectSymbol(it) as? JKMethodSymbol } .firstOrNull { it.parameterTypes.singleOrNull()?.takeIf { it.isSubtypeOf(rightType, symbolProvider) } != null }!! } diff --git a/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/types.kt b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/types.kt index 5fcd1ca5aad..566bbbe27e1 100644 --- a/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/types.kt +++ b/j2k/newSrc/org/jetbrains/kotlin/j2k/tree/types.kt @@ -22,11 +22,17 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.idea.caches.resolve.util.* +import org.jetbrains.kotlin.load.java.structure.impl.JavaPrimitiveTypeImpl fun JKExpression.type(context: ConversionContext): JKType = when (this) { is JKLiteralExpression -> type.toJkType(context.symbolProvider) - is JKBinaryExpression -> (operator as JKKtOperatorImpl).methodSymbol.returnType + is JKBinaryExpression -> { + val operatorSymbol = (operator as JKKtOperatorImpl).methodSymbol + if (operatorSymbol.name == "compareTo") { + kotlinTypeByName("kotlin.Boolean", context.symbolProvider) + } else operatorSymbol.returnType + } is JKMethodCallExpression -> identifier.returnType is JKFieldAccessExpressionImpl -> identifier.fieldType is JKQualifiedExpressionImpl -> this.selector.type(context) @@ -84,6 +90,8 @@ fun KtTypeElement.toJK(symbolProvider: JKSymbolProvider): JKType = fun JKType.toKtType(symbolProvider: JKSymbolProvider): KotlinType = when (this) { is JKClassType -> classReference!!.toKtType(symbolProvider) + is JKJavaPrimitiveType -> + kotlinTypeByName(jvmPrimitiveType.primitiveType.typeFqName.asString(), symbolProvider).toKtType(symbolProvider) else -> TODO(this::class.java.toString()) }