🐛 fix(generator): 规范化非法 Java 标识符 - #96
Merged
Merged
Conversation
Owner
Author
|
问题复现: |
Owner
Author
|
实现实验:输入表名 |
Owner
Author
|
测试记录:核心模型、现代模板上下文、legacy 模板上下文和 AI 命名规则定向测试 143 passed;全量单测 638 passed,Ruff lint/format 均通过。此修复未建立前后运行时基准,性能未测量,不宣称性能提升。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
真实数据库允许连字符、空格、数字开头和保留字作为表名或列名。原有转换会把
order-item生成成非法的Order-item,把class直接作为 Java 字段,生成源码无法编译;核心模型、现代模板和 legacy 模板还各自维护命名逻辑。变更
core.java_identifiers,统一 PascalCase/camelCase、非法分隔符、数字开头、空名称和 Java 关键字处理。TableInfo、TemplateContextBuilder、legacyTemplateContext和 AI 命名规则统一调用该实现。tableName/columns.name仍保留数据库原始标识符,保证 SQL/ORM 映射不变。验证
PYTHONPATH=src python -m pytest -q tests/unit:638 passedruff check src tests scripts:通过ruff format --check:通过实验与结果
输入表名
order-item、列名class和123_display-name,输出分别为OrderItem、class_、generated123DisplayName,均通过 Java 标识符校验;原始名称仍完整保留在 context。性能未测量,本 PR 不宣称性能提升。风险与回滚
规范化可能改变此前对特殊名称生成的类名/字段名,但这是从非法源码到合法源码的必要行为;标准 snake_case 名称输出保持兼容。回滚可通过 revert 本次 squash commit 完成。
Closes #95