Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanups #486

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/kotlin/org/openrewrite/kotlin/KotlinTypeMapping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void methodReference() {
@Test
void getJavaClass() {
rewriteRun(
kotlin("val a = Integer :: class . java ")
kotlin("val a = Int :: class . java ")
);
}

Expand Down
Loading