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

Keyword sanitization for Lens code generation (#2924) #2925

Merged
merged 6 commits into from
Feb 9, 2023
Merged

Keyword sanitization for Lens code generation (#2924) #2925

merged 6 commits into from
Feb 9, 2023

Conversation

hrafnthor
Copy link
Contributor

Kotlin keyword sanitization added to class path fields used during Lens code generation.

Only keywords matching potential TLDs are observed.

@hrafnthor hrafnthor marked this pull request as ready for review February 9, 2023 08:49
@serras
Copy link
Member

serras commented Feb 9, 2023

Thanks for your contribution, @hrafnthor! May I suggest to use the entire set of keywords instead of a few? You can copy the list from here.

* Set moved out of function to avoid its creation on each invocation.
* Mock test package header now has keywords from each category.
Copy link
Member

@serras serras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few style comments

fun String.sanitizeDelimited(delimiter: String = ".", separator: String = delimiter) =
if (isNotBlank() && contains(delimiter)) {
splitToSequence(delimiter).joinToString(separator) { if (kotlinKeywords.contains(it)) "`$it`" else it }
} else this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to consider empty and not containing delimiter as special cases, splitToSequence + joinToString should do the right thing

if (isMarkedNullable) "$n?" else n
}
else -> when (val qname = declaration.qualifiedName?.asString()) {
else -> when (val qname = declaration.qualifiedName?.asString()?.sanitizeDelimited()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might read better if asStringSanitized was an extension of Name (but if you prefer this way, it's also fine)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it would be more readable as well as limit the scope of the function to relevant parts i.e KSName rather than any String. Will change the extension signature and apply it where applicable.

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hrafnthor for being so quick to fix your own bug report 🙏 👏 Really awesome!
And congrats on your first contribution to Arrow 🙌

* Extension function applied to KSName rather than String
* Function signature modified to match its function better
* Unnecessary function checks removed based on feedback
@hrafnthor
Copy link
Contributor Author

Thank you both @nomisRev and @serras for the quick feedback!

I've made slight modifications based on it, which does make the changes more focused and readable.

@nomisRev nomisRev merged commit f9cda5b into arrow-kt:main Feb 9, 2023
@hrafnthor hrafnthor deleted the fix-optics-package-keywords branch February 10, 2023 09:00
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