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

Migrate NameAllocator from JVM to common #2024

Merged
merged 4 commits into from
Nov 29, 2024

Conversation

ForteScarlet
Copy link
Contributor

Part of #304, #1959

Migrate NameAllocator from JVM to common and added a new internal type CodePoint .

The effects of CodePoint related functions are not guaranteed on non-JVM platforms.

@@ -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
Copy link
Collaborator

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.

Copy link
Contributor Author

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…

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Comment on lines +29 to +33
internal actual fun CodePoint.isJavaIdentifierStart(): Boolean =
Character.isJavaIdentifierStart(code)

internal actual fun CodePoint.isJavaIdentifierPart(): Boolean =
Character.isJavaIdentifierPart(code)
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@Egorand Egorand left a 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)")
Copy link
Collaborator

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()?

Copy link
Contributor Author

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() .

@Egorand Egorand merged commit ae64198 into square:main Nov 29, 2024
4 checks passed
@ForteScarlet ForteScarlet deleted the migrate-NameAllocator branch December 16, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants