-
Notifications
You must be signed in to change notification settings - Fork 292
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
Migrate NameAllocator from JVM to common #2024
Conversation
@@ -118,7 +120,7 @@ public class NameAllocator private constructor( | |||
*/ | |||
@JvmOverloads public fun newName( | |||
suggestion: String, | |||
tag: Any = UUID.randomUUID().toString(), | |||
tag: Any = Random.nextULong().toString(), // TODO Since Kotlin 2.0.20, it's possible to use kotlin.uuid.Uuid |
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.
Unfortunately the API is experimental and can't yet be used by libraries.
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.
Indeed, it seems like switching to kotlin.uuid.Uuid
will require some additional waiting time…
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.
Maybe do toString(16).padStart(16, '0')
so we get a sixteen-digit hexidecimal number?
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.
🤔Sounds good! I will modify it later.
internal actual fun CodePoint.isJavaIdentifierStart(): Boolean = | ||
Character.isJavaIdentifierStart(code) | ||
|
||
internal actual fun CodePoint.isJavaIdentifierPart(): Boolean = | ||
Character.isJavaIdentifierPart(code) |
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'm not sure we even need these anymore. It's retained from JavaPoet. We should probably write our own rules for the Kotlin language, as it is probably similar but not exactly the same.
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.
We can do this in a follow-up.
kotlinpoet/src/nonJvmMain/kotlin/com/squareup/kotlinpoet/CodePoint.nonJvm.kt
Outdated
Show resolved
Hide resolved
kotlinpoet/src/nonJvmMain/kotlin/com/squareup/kotlinpoet/CodePoint.nonJvm.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jake Wharton <[email protected]>
Co-authored-by: Jake Wharton <[email protected]>
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.
Nice, thanks!
|
||
@Suppress("UNUSED_PARAMETER") | ||
private fun jsCodePointAt(str: String, index: Int): Int = | ||
js("str.codePointAt(index)") |
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.
Interesting that values returned by js()
in wasmJs
don't require casting same as in js
, does WASM have its own flavour of js()
?
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.
Yes, Kotlin/JS's js()
seems to be different from Wasm's js()
.
Part of #304, #1959
Migrate
NameAllocator
from JVM to common and added a new internal typeCodePoint
.