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

[jnigen] Use dollar signs for nested class name separator #1791

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

HosseinYousefi
Copy link
Member

The Bar class defined inside the Foo class in Java like class Foo { class Bar {} } used to be generated as Foo_Bar, but we can have a class named Foo_Bar, now we generate it as Foo$Bar.

We can (although very rare – rarer than using underscores) have a class named Foo$Bar that is not nested, this will be generated as Foo$$Bar as all dollar signs that are pre-existing in Java code will be replaced by 2 dollar signs. So we continue not to have any collisions.

I should mention that it's impossible to have both a nested Bar inside Foo and a class named Foo$Bar in the same package in Java because they will share the same binary name of com.package.Foo$Bar, so choosing $ is better than _ because of this as well.

Closes #1516.

@coveralls
Copy link

coveralls commented Dec 9, 2024

Coverage Status

coverage: 88.737% (+0.005%) from 88.732%
when pulling ab242d2 on nested-naming
into 8ea1a9d on main.

@HosseinYousefi HosseinYousefi merged commit d37df9c into main Dec 10, 2024
18 checks passed
@HosseinYousefi HosseinYousefi deleted the nested-naming branch December 10, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How should nested Java classes be named?
3 participants