Skip to content

Sometimes use canonical names and simple names instead of binary names for classes. #1515

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

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

copybara-service[bot]
Copy link
Contributor

Sometimes use canonical names and simple names instead of binary names for classes.

Terminology refresher:

  • binary name name: com.google.Foo$BarException (though I seem to recall learning from the prospective reviewer of this CL that there's a second kind of "binary name," probably using / instead of .?)
  • canonical name: com.google.Foo.BarException
  • simple name: BarException

Specifically, we use simple names only for a set of well-known classes (as opposed to using them everywhere), and then we try canonical names, falling back to binary names when we have no other option (e.g., anonymous and local classes).

Advantages:

  • Binary names are annoying to read, especially when multiple appear on the same line (as can happen in IterableSubject failure messages, for example).
    • Array binary names are particularly bad: [Ljava.lang.Long; (in contrast to java.lang.Long[] or just Long[]).
  • A search for a binary name in Code Search doesn't find it.
  • Java and Kotlin disagree on how to spell types like Long: Is it java.lang.Long or kotlin.Long?
    • We can't fully dodge this with Integer/Int and Character/Char, but we can at least avoid mentioning "Java" and "Kotlin" for users who might not think of themselves as using one of those things.
  • We can output simple names even when we lack class metadata under J2CL.
  • This is arguably consistent with how we already have special code to output "Map.Entry" in SubjectUtils.

This CL requires that I change SubjectUtils.java to actually use its own longName method in one place. I had missed this in cl/773872316.

…s for classes.

Terminology refresher:
- binary name name: `com.google.Foo$BarException` (though I seem to recall learning from the prospective reviewer of this CL that there's a second kind of "binary name," probably using `/` instead of `.`?)
- canonical name: `com.google.Foo.BarException`
- simple name: `BarException`

Specifically, we use simple names only for a set of well-known classes (as opposed to using them [everywhere](https://youtrack.jetbrains.com/issue/KT-25197/Improve-diagnostic-Show-qualified-name-for-Function-type-in-error-messages)), and then we try canonical names, falling back to binary names when we have no other option (e.g., anonymous and local classes).

Advantages:
- Binary names are annoying to read, especially when multiple appear on the same line (as can happen in `IterableSubject` failure messages, for example).
   - Array binary names are particularly bad: `[Ljava.lang.Long;` (in contrast to `java.lang.Long[]` or just `Long[]`).
- A search for a binary name in Code Search doesn't find it.
- Java and Kotlin disagree on how to spell types like `Long`: Is it `java.lang.Long` or `kotlin.Long`?
   - We can't fully dodge this with `Integer`/`Int` and `Character`/`Char`, but we can at least avoid mentioning "Java" and "Kotlin" for users who might not think of themselves as using one of those things.
- We can output simple names even when we lack class metadata under J2CL.
- This is arguably consistent with how we already have special code to output "`Map.Entry`" in `SubjectUtils`.

This CL requires that I change `SubjectUtils.java` to actually use its own `longName` method in one place. I had missed this in cl/773872316.

PiperOrigin-RevId: 776128140
@copybara-service copybara-service bot merged commit 0ba72d6 into master Jun 26, 2025
@copybara-service copybara-service bot deleted the test_773818405 branch June 26, 2025 14:24
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