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

Handle Invalid Java Identifiers #1169

Open
2 tasks
scottschreckengaust opened this issue Jul 10, 2024 · 0 comments
Open
2 tasks

Handle Invalid Java Identifiers #1169

scottschreckengaust opened this issue Jul 10, 2024 · 0 comments
Labels
enhancement New feature or request p2

Comments

@scottschreckengaust
Copy link

Describe the feature

How might invalid java identifiers, https://docs.oracle.com/javase/specs/jls/se12/html/jls-3.html#jls-3.8, be handled?

Here is a reference for "Package Names and Module Names" https://docs.oracle.com/javase/specs/jls/se12/html/jls-6.html#jls-6.1

  • If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.
  • If any of the resulting package name components are keywords (§3.9), append an underscore to them.
  • If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

Use Case

Here is a snippet I used to correct the issue within Projen because hyphens, -, aren't legal characters for java packages:

  publishToMaven: {
  ...
    javaPackage: `io.github.${"no-hyphens".replace(/-/g, '_')}`,
  ...
  },

Proposed Solution

Two options:

  1. A ERROR/FAIL message stating invalid java identifiers detected
  2. A WARN message stating invalid java identifiers converted

Other Information

When using hypens, -, for example, there are tons of compilation errors and somewhat difficult to trace:

error: '(' or '[' expected
error: ';' expected
error: '{' expected
error: <identifier> expected
...
private final io.github.no-hypens.Builder props;
...

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.148.0

Environment details (OS name and version, etc.)

macOS Sonoma 14.5

@mrgrain mrgrain transferred this issue from aws/jsii Jul 11, 2024
@mrgrain mrgrain added enhancement New feature or request p2 labels Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2
Projects
None yet
Development

No branches or pull requests

2 participants