-
Notifications
You must be signed in to change notification settings - Fork 288
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
Migrating the Util.kt
and KModifier
from JVM to common
#2006
base: main
Are you sure you want to change the base?
Conversation
kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/Util.jvm.kt
Outdated
Show resolved
Hide resolved
kotlinpoet/src/nonJvmMain/kotlin/com/squareup/kotlinpoet/Util.nonJvm.kt
Outdated
Show resolved
Hide resolved
kotlinpoet/src/nonJvmMain/kotlin/com/squareup/kotlinpoet/Util.nonJvm.kt
Outdated
Show resolved
Hide resolved
internal actual fun <K, V> Map<K, V>.toImmutableMap(): Map<K, V> = | ||
toMap() | ||
|
||
internal actual fun <T> Collection<T>.toImmutableList(): List<T> = | ||
toList() | ||
|
||
internal actual fun <T> Collection<T>.toImmutableSet(): Set<T> = | ||
toSet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not going to put these in an unmodifiable wrapper on other targets, do we still need to do it on JVM? Are we really worried about Java callers mutating things? I don't think I am.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original implementation was copied when we forked from JavaPoet, for what it's worth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you have a point. If we no longer care about calls that mutate things on the JVM, do we keep toImmutable*
in common and have its result just return a to*
(like toSet
), or do we simply remove them and use to*
instead where appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's defending against something that is not a real problem in practice, and I would eliminate the concept entirely and use Kotlin's collection APIs directly everywhere. This should probably be done in its own PR rather than cluttering this one.
|
||
internal actual fun Char.isJavaIdentifierPart(): Boolean { | ||
// TODO | ||
// A character may be part of a Java identifier if any of the following conditions are true: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe extract these checks into common to have consistent implementations on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done in later PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I am dividing them because I am unsure if the current implementation of non-JVM is the same as the one in JVM.
It would be wonderful to merge them if we can confirm that they have the same effects!
@JakeWharton please merge if everything looks good to you. |
Part of #304, #1959
Migrating
Util.kt
andKModifier
from JVM to common.Regex
in WasmJS.On the JVM, however, the effect is the same before and after migration.
Let me know if there's anything I need to do, thanks.
If these changes are not reviewed until after 2.0, you can always tell me, convert it to draft, or close it~