From cd89d3dd6758a33b2d321a4b06ce0dbb08ea7df7 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 30 Nov 2023 08:39:35 +0100 Subject: [PATCH] Minor cleanups --- .../kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt | 6 +++--- .../org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt | 7 ++++--- .../java/org/openrewrite/kotlin/KotlinTypeMappingTest.java | 1 - .../org/openrewrite/kotlin/tree/MethodReferenceTest.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt index 041bd4b7b..a3f1bfba6 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt @@ -48,6 +48,7 @@ import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.impl.classFiles.* import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource +import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.Variance import org.openrewrite.java.JavaTypeMapping @@ -56,7 +57,6 @@ import org.openrewrite.java.tree.JavaType import org.openrewrite.java.tree.JavaType.* import org.openrewrite.java.tree.TypeUtils import org.openrewrite.kotlin.KotlinTypeSignatureBuilder.Companion.convertClassIdToFqn -import org.openrewrite.kotlin.KotlinTypeSignatureBuilder.Companion.convertKotlinFqToJavaFq import kotlin.collections.ArrayList @Suppress("DuplicatedCode") @@ -706,9 +706,9 @@ class KotlinTypeMapping( val source: JvmPackagePartSource? = resolvedSymbol.fir.containerSource as JvmPackagePartSource? if (source != null) { declaringType = if (source.facadeClassName != null) { - createShallowClass(convertKotlinFqToJavaFq(source.facadeClassName.toString())) + createShallowClass((source.facadeClassName as JvmClassName).fqNameForTopLevelClassMaybeWithDollars.asString()) } else { - createShallowClass(convertKotlinFqToJavaFq(source.className.toString())) + createShallowClass(source.className.fqNameForTopLevelClassMaybeWithDollars.asString()) } } } diff --git a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt index e551bca22..6de2b56c8 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/KotlinTypeSignatureBuilder.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaTypePa import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.types.Variance import org.openrewrite.java.JavaTypeSignatureBuilder import org.openrewrite.java.tree.JavaType @@ -369,9 +370,9 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession, private val val source: JvmPackagePartSource? = resolvedSymbol.fir.containerSource as JvmPackagePartSource? if (source != null) { declaringSig = if (source.facadeClassName != null) { - convertKotlinFqToJavaFq(source.facadeClassName.toString()) + (source.facadeClassName as JvmClassName).fqNameForTopLevelClassMaybeWithDollars.asString() } else { - convertKotlinFqToJavaFq(source.className.toString()) + source.className.fqNameForTopLevelClassMaybeWithDollars.asString() } } } @@ -684,7 +685,7 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession, private val .replace(".", "$") .replace("/", ".") .replace("?", "") - return if (cleanedFqn.startsWith(".")) cleanedFqn.replaceFirst(".".toRegex(), "") else cleanedFqn + return if (cleanedFqn.startsWith(".")) cleanedFqn.substring(1) else cleanedFqn } } } diff --git a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java index df0142e06..100bd9145 100644 --- a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java +++ b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java @@ -40,7 +40,6 @@ import static java.util.Collections.singletonList; import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.in; import static org.openrewrite.ExecutionContext.REQUIRE_PRINT_EQUALS_INPUT; import static org.openrewrite.java.tree.JavaType.GenericTypeVariable.Variance.*; import static org.openrewrite.kotlin.Assertions.kotlin; diff --git a/src/test/java/org/openrewrite/kotlin/tree/MethodReferenceTest.java b/src/test/java/org/openrewrite/kotlin/tree/MethodReferenceTest.java index a6ea77782..ef9347c04 100644 --- a/src/test/java/org/openrewrite/kotlin/tree/MethodReferenceTest.java +++ b/src/test/java/org/openrewrite/kotlin/tree/MethodReferenceTest.java @@ -63,7 +63,7 @@ void methodReference() { @Test void getJavaClass() { rewriteRun( - kotlin("val a = Integer :: class . java ") + kotlin("val a = Int :: class . java ") ); }