mirror of
https://github.com/openharmony/window_window_manager.git
synced 2026-08-24 07:47:52 -04:00
0f057d3106
2. add ai-agents files:AGENTS.md、CodeStyle.md、Testing.md, used to guide development and test. Signed-off-by: zhuxiaowen <zhuxiaowen4@huawei.com> Co-Authored-By: Agent
2.4 KiB
2.4 KiB
CodeStyle
Formatting
Use the project formatter.
Key rules:
- Column limit: 120 characters
- Indent width: 4 spaces (no tabs)
- Braces: Custom — opening brace on same line for classes/structs/control, new line for functions
- Pointer alignment: Left (
int* ptr) - Include sorting: Enabled; grouped by type
- C++ standard: C++11
Run formatter tool before committing.
Code Style Guidelines
Naming
| Element | Convention | Example |
|---|---|---|
| Classes / Structs | PascalCase | WindowManagerService |
| Methods | camelCase | GetWindowById() |
| Member variables | camelCase + trailing underscore | windowManagerMap_ |
| Constants / Enums | UPPER_SNAKE_CASE | DEFAULT_SPACING |
| Namespaces | PascalCase | OHOS::Rosen |
| File names | snake_case | window_manager.cpp |
| Test classes | PascalCase + Test suffix |
WindowManagerServiceTest |
| Macros | UPPER_SNAKE_CASE | WMSERVER_LOG_TAG |
Include Order
- Corresponding header (for
.cppfiles) - Standard library headers (e.g.
<algorithm>,<string>) - OpenHarmony framework headers (e.g.
<hilog.h>,<ipc_skeleton.h>) - Project headers from
interfaces/(e.g."wm_common.h") - Other project-internal headers
Use #pragma once or include guards (#ifndef OHOS_ROSEN_*_H) in headers.
Logging
Use HiLog wrapper macros:
TLOGD("message %d", value); // Debug
TLOGI("message"); // Info
TLOGW("warning"); // Warn
TLOGE("error: %s", err); // Error
Error Handling
- Return
WMErrororWmErrorCodeenum values from public APIs. - Use early-return pattern for error cases.
- Log errors with
WLOGFEbefore returning. - Use
EXPECT_*for non-fatal test checks;ASSERT_*for fatal.
Memory & Resource Management
- Use
sptr<T>for IPC objects and singletons. - Use
wptr<T>for weak references where cycles may occur. - Prefer RAII; avoid raw
new/delete.
License Header
Every source file must begin with the Apache 2.0 license header:
/*
* Copyright (c) xxxx-xxxx Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* ...
*/
Key Conventions
- Namespace: always
OHOS::Rosen - Feature flags controlled via
declare_args()inwindowmanager_aafwk.gni - ZIDL (IPC proxy/stub) code lives in
src/zidl/subdirectories - Use
constexprfor compile-time constants