Skip to main content

Module r_class_formatter

Module r_class_formatter 

Source
Expand description

Shared utilities for R class wrapper generation.

This module provides abstractions to reduce duplication across the 5 class system generators (Env, R6, S3, S4, S7). Each class system has different R idioms but shares common patterns:

  • Class-level roxygen documentation
  • Constructor generation
  • Instance method iteration with .Call() building
  • Static method handling
  • Return strategy application

§Architecture

ParsedImpl
    │
    ├─▶ ClassDocBuilder  → roxygen header lines (#' @title, @name, etc.)
    │
    └─▶ MethodContext[]  → pre-computed method data for each method
            │
            └─▶ ClassFormatter::format_constructor()
            └─▶ ClassFormatter::format_instance_method()
            └─▶ ClassFormatter::format_static_method()

Structs§

ClassDocBuilder
Builder for class-level roxygen documentation header.
MethodContext
Pre-computed context for a method, holding all data needed for R wrapper generation.
MethodDocBuilder
Builder for method-level roxygen documentation.

Traits§

ParsedImplExt
Extension trait for ParsedImpl to iterate over methods as MethodContext.

Functions§

build_match_arg_prelude 🔒
Build R prelude lines that validate match_arg / choices / several_ok parameters before the .Call().
build_method_precondition_checks 🔒
Build the R-side precondition guard lines for a parameter list, given its per-param map (match_arg/choices skips, inherits / not_inherits / no_na checks, each parameter’s own preconditions decision), whether coerce is active for the whole method, and the method’s and impl block’s preconditions / no_preconditions (method_level, impl_level). Each parameter keeps its type-derived checks as crate::r_preconditions::resolve_type_checks decides, under the crate default and the no-preconditions-default feature; the named checks stay either way.
choice_param_doc_map 🔒
Build the R-formal → auto-generated @param text map for a method’s choice params: the write-time placeholder for a match_arg param (the wrapper writer renders it from the enum’s MatchArg::CHOICES, #210), the literal One of "a", "b". line for a choices(...) param (ParamAttrs::literal_choices_doc, the same text a standalone function gets). Pass to MethodDocBuilder::with_choice_param_docs in each class generator.
class_ref_or_verbatim 🔒
Return a .__MX_CLASS_REF_<name>__ placeholder (for bare identifiers) so the resolver can look up the actual R class name at wrapper write time, or name verbatim (for namespaced / non-identifier strings).
describe_params_lines 🔒
The documentation body of a method block that has no \usage (env methods): the author tags forward accepts, verbatim, then one \describe{} list with the author’s @param items followed by the choice items of generated_params. A formal without choice text gets no item (nothing in \usage asks for one), and no @param line is emitted: with no usage entry to match, roxygen2 would write an \arguments entry that R CMD check reports as “Documented arguments not in \usage”.
effective_r_defaults 🔒
Effective R-formal defaults for a method.
emit_s3_generic_guard 🔒
Emit the conditional S3 generic guard for a given generic name.
generated_params 🔒
The formals of r_params that doc_tags leaves undocumented, each with its choice text from choice_docs (the write-time placeholder of a match_arg parameter, the literal line of a choices(...) one), or None for a formal that has none. Skips .mx_self, .ptr and ..., and yields nothing when the tags take the arguments from another topic (roxygen::params_documented_elsewhere against page, #1590). The class page default a builder appends is not in doc_tags, and an author @rdname naming page is the same page, so neither suppresses them.
instance_formals 🔒
Prefix an instance receiver and append only missing dispatch dots. Shared by inherent and trait wrapper contexts; explicit Dots keeps its place.
is_bare_identifier 🔒
Check whether s is a bare R identifier (only [A-Za-z_][A-Za-z0-9_]*).
match_arg_skip_set 🔒
The R formals of the parameters that are validated by R’s match.arg() and therefore don’t need type-check preconditions generated for them. Shared by MethodContext and TraitMethodContext.
push_param_filler 🔒
Push one #' @param name text line per generated_params entry: the choice text for a choice parameter, (undocumented) otherwise (so R CMD check codoc sees every formal in \usage documented).
should_export_from_tags 🔒
Determine whether a class or method should be @export-ed.