Skip to content

命名规范

本文档定义 v4 版本三层库架构下的统一命名规范,确保通过类名即可识别其所在模块和职能。所有设计文档和代码实现必须遵循本规范。


1 三层模块命名

模块命名规则示例
:ime-engine公开 class 以 Ime 为前缀ImeEngine, ImeConfig, ImeOutput, ImeState, ImeIntent, ImeOutputBridge
:ime-ui不使用 Ime 前缀,贴近 UI 业务命名KeyboardPanel, EditTextBridge, GestureFeedbackPanel, CandidateListPanel
:app不使用 Ime 前缀,贴近应用业务命名IMEService, ConfigDataStore, InputConnectionBridge

1.1 engine 模块

所有对外的 class(包括 sealed class、data class、enum、interface)均以 Ime 作为前缀,作为引擎库的命名空间标识。内部实现类(如 KeyboardStateMachineInputListOperatorFeatureRegistry)不强制使用 Ime 前缀,因为它们不对外暴露。

1.2 ui 模块

组件命名贴近其 UI 职能,使用业务语义化的名称:

后缀含义示例
Panel容器 / 组合器(组合多个子组件)KeyboardPanel, GestureInputPanel, CandidateListPanel, InputListPanel, KeyGridPanel, GestureFeedbackPanel
Screen全屏界面(UI 库或应用层页面)KeyboardScreen, SettingsScreen, MainScreen, ExerciseScreen

注意KeyboardPanelKeyboardScreen 均为完整的输入法组件,包含候选栏、输入栏、工具栏和键盘区域,只是形式和交互不同(叠加 vs 全屏分离)。

主题系统使用 Keyboard 前缀(如 KeyboardColorsKeyboardTheme),与 Material3 的 MaterialTheme 等系统命名区分。

1.3 app 模块

Android 系统服务类沿用平台命名惯例(如 IMEService),配置类使用职能名称(如 ConfigDataStore),桥接类使用目标对象 + Bridge 后缀命名(如 InputConnectionBridge),实现 ImeOutputBridge 接口。页面以 Screen 为后缀(如 SettingsScreenMainScreen)。


2 KeyGridPanel 子类命名

KeyGridPanel 的子类以 KeyGridPanel后缀,前缀表达键盘变体类型:

类名说明
StandardKeyGridPanel标准键盘(拼音、拉丁、数字、符号、编辑器、数学)
EmojiKeyGridPanelEmoji 面板
CandidateKeyGridPanel候选键盘
CommitOptionKeyGridPanel提交选项键盘

3 引擎 API 命名

类型命名说明
IntentImeIntent.PerformEdit(EditorAction)不是 ImeIntent.EditorAction(EditorActionType)
OutputImeOutput.PerformEdit(EditorAction)PerformEdit 与 Output 对称使用同一 EditorAction 枚举
手势输入ImeEngine.handleGesture(InputGesture)不是 onKeyPress / handleKeyPress
意图处理ImeEngine.handleIntent(ImeIntent)直接发送意图

4 包命名

  • 格式:org.crazydan.studio.app.ime.kuaizi.<module>.<submodule>
  • :app 模块无子模块名,直接使用顶级包名
  • 全小写,不使用下划线
  • 模块划分与功能对应,不按技术层划分
org.crazydan.studio.app.ime.kuaizi.engine.core
org.crazydan.studio.app.ime.kuaizi.engine.domain
org.crazydan.studio.app.ime.kuaizi.engine.dict
org.crazydan.studio.app.ime.kuaizi.ui.theme
org.crazydan.studio.app.ime.kuaizi.ui.keyboard
org.crazydan.studio.app.ime.kuaizi.ui.integration
org.crazydan.studio.app.ime.kuaizi       ← :app 模块(无子模块名)

5 禁止使用的名称

以下名称已废弃,不得在设计文档和代码中使用:

  • KeyPanel(使用 KeyGridPanel
  • StandardKeyboard / StandardKeyPanel(使用 StandardKeyGridPanel
  • InputPanel(使用 GestureInputPanel
  • KeyboardView(使用 KeyboardPanel
  • CandidateBar / InputBar(使用 CandidateListPanel / InputListPanel
  • EditorActionType(使用 EditorAction
  • ImeEngineConfig(使用 ImeConfig
  • onKeyPress(使用 handleGesture / handleIntent
  • disable* / enable* 前缀配置字段(使用 *Enabled 后缀)
  • EditorField(使用 EditTextBridge
  • EditorHost(使用 Bridge 接入示例,见 030-三层模块划分
  • InputHostView(使用 Bridge 接入示例,见 030-三层模块划分
  • ImeEditText / ImeSupportEditText(使用 EditTextBridge
  • EditorState(撤销状态由 BaseImeOutputBridge 内部管理)
  • AppLog / AppLogger(使用 ImeLog / ImeLogger,详见 080-日志系统
  • LogExportActivity(使用 LogExportScreen
  • CandidateState(使用 CandidateList
  • FavoritesState(使用 FavoriteList
  • CandidatePanel(使用 CandidateListPanel
  • FavoritesPanel(使用 FavoriteListPanel
  • CandidatePager(使用 CandidateListPager
  • ImeOutput.EditAction(使用 ImeOutput.PerformEdit
  • InputScreen(使用 KeyboardPanel 叠加模式 / KeyboardScreen 全屏模式,两者均为完整输入法组件)
  • ThreeLayerKeyboardArea(使用 KeyboardPanel,其内部已包含三层面板叠加区域)
  • KeyboardArea(使用 KeyboardPanel,其内部已包含三层面板叠加区域)