Skip to content

Enforce explicit accessor pattern across core APIs (remove macro/inline accessors)#20

Open
Copilot wants to merge 15 commits into
mainfrom
copilot/refactor-getter-edit-methods
Open

Enforce explicit accessor pattern across core APIs (remove macro/inline accessors)#20
Copilot wants to merge 15 commits into
mainfrom
copilot/refactor-getter-edit-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

This change aligns the codebase with the requested accessor pattern: getters and edit_* methods are now explicit class methods implemented in .cc files, avoiding macro-generated and inline accessor bodies.
A full audit found one remaining non-conforming class, which is now refactored to match the same convention used in DocraftDocument, DocraftDocumentContext, and the parser API.

  • Pattern consolidation

    • Removed accessor macro definitions from docraft_lib.h.
    • Kept APIs explicit and type-specific (including const/mutable variants) instead of generic macro expansion.
  • Core API alignment

    • DocraftDocument, DocraftDocumentContext, and DocraftCraftLanguageParser now expose explicit accessor declarations in headers with implementations in corresponding .cc files.
  • Codebase-wide completion

    • Refactored DocraftDocumentMetadata to remove inline accessor/setter/clear bodies from the header.
    • Added docraft_document_metadata.cc and moved all method implementations there.
    • Updated CMake source list to compile the new translation unit.

Example of the applied pattern:

// header (.h)
[[nodiscard]] const std::optional<std::string>& author() const;
void set_author(const std::string& author);

// source (.cc)
const std::optional<std::string>& DocraftDocumentMetadata::author() const { return author_; }
void DocraftDocumentMetadata::set_author(const std::string& author) { author_ = author; }

Copilot AI linked an issue May 25, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Refactor getter and edit methods for read-only and editable access Refactor pointer accessors into readonly/edit API pairs May 25, 2026
Copilot finished work on behalf of Cadons May 25, 2026 21:03
Copilot AI requested a review from Cadons May 25, 2026 21:03
Copilot AI changed the title Refactor pointer accessors into readonly/edit API pairs Standardize inline accessor macros and rename mutable query APIs to take_* May 25, 2026
Copilot finished work on behalf of Cadons May 25, 2026 21:19
Copy link
Copy Markdown
Owner

@Cadons Cadons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply comments, rember edit_ and get_ must always created using the macro, no mixture except if there is an exception, but in these cases I don't see exceptions

Comment thread docraft/include/docraft/craft/docraft_craft_language_parser.h Outdated
Comment thread docraft/include/docraft/templating/docraft_template_engine.h Outdated
Comment thread docraft/include/docraft/docraft_document.h Outdated
Comment thread docraft/include/docraft/docraft_document.h Outdated
Comment thread docraft/src/docraft/craft/docraft_craft_language_parser.cc Outdated
Comment thread docraft/src/docraft/docraft_document.cc Outdated
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 25, 2026

@copilot apply comments, rember edit_ and get_ must always created using the macro, no mixture except if there is an exception, but in these cases I don't see exceptions

Applied in ac081d2 and refined in 281ea8d: remaining getter/edit accessor pairs in the touched areas are now macro-generated (no manual mix).

Copilot AI changed the title Standardize inline accessor macros and rename mutable query APIs to take_* Standardize inline accessor macros and align query API naming (take_*/find_*) May 25, 2026
Copilot finished work on behalf of Cadons May 25, 2026 21:39
Copilot AI requested a review from Cadons May 25, 2026 21:39
@Cadons Cadons marked this pull request as ready for review May 25, 2026 21:44
Copilot AI changed the title Standardize inline accessor macros and align query API naming (take_*/find_*) Unify accessor generation into a single macro and fix API doc parser breakage May 25, 2026
Copilot finished work on behalf of Cadons May 25, 2026 22:02
Copilot AI changed the title Unify accessor generation into a single macro and fix API doc parser breakage Refactor accessor API: replace macro-generated getters/editors with explicit cpp methods May 26, 2026
Copilot finished work on behalf of Cadons May 26, 2026 05:55
Copilot AI changed the title Refactor accessor API: replace macro-generated getters/editors with explicit cpp methods Enforce explicit accessor pattern across core APIs (remove macro/inline accessors) May 26, 2026
Copilot finished work on behalf of Cadons May 26, 2026 06:06
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
25.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getter and edit methods

2 participants