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

proposal to update generated function names #265

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

davissuber
Copy link
Contributor

Note for reviewers: I have NOT tested this against Uber's apps at the time of this writing - this pull request is more of a "is this even a problem worth changing" type of deal - if this seems agreeable, I'll test out the code generation in buck/bazel.

The main behavioral change in this pull request is in the function name generation in Names.kt, one can run into the following problems:

  1. If one create a type named Null, it would break the keyword check since it's not in the keyword
    • Normally people probably won't do this - so this is probably not a real problem
    • We can also just add null to the keyword list as alternative
  2. A name that ends with 2 such as Function2 will pass through the uniqueness check and be converted as function22
    • This is not technically wrong or break anything, but feels like it reads worse than function2_2

This is quite a useful annotation for kotlin/java interop - and people
do use it with motif - so we'd like to add tests with this annotation
We no longer need to map the primitive names for tests - possibly due to
a room compiler processing version bump.

However, we do notice that there's still a space difference when generating
the java/kotlin string representation of generic classes
This commit updates the name generation to always add a trailing underscore for
the following reasons:

1. There are some missing keywords - for example, a custom type named `Null` will
   crash motif since it will try to name the function `null()`, it seems that adding
   to the list is not as safe as always append
2. Motif append a `2` (or `3` and so on) to a function name to avoid collision, so a
   type whose name ends with a `2` e.g. `Function2` will have its name `Function22`
   (or `Function23` and so on) - it's not wrong, but reads a bit funny
This commit adds a test that would fail without the changes in this
pull request, such as JvmSuppressWildcard, `Null` class name, and
kotlin/java generic name difference
@@ -31,7 +31,7 @@ import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
@OptIn(ExperimentalProcessingApi::class)
class XNamesTest(private val processorType: ProcessorType, private val srcLang: SourceLanguage) {
class NamesTest(private val processorType: ProcessorType, private val srcLang: SourceLanguage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Matching the file name


fun child(): ChildScope

fun myByte(): Byte
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to verify the name renderer change is not breaking stuff

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.

1 participant