fluidattacks-blends-domain 0.23.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::{
    query::match_ast_d,
    syntax::{
        builders::method_declaration::{
            build_method_declaration_node, MethodDirectChildren, MethodListChildren,
        },
        readers::kotlin::class_declaration::extract_modifiers,
        SyntaxGraphArgs, SyntaxGraphError,
    },
    utilities::text_nodes::node_to_str,
    NodeId,
};
use alloc::borrow::ToOwned;

pub fn reader(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
    let graph = args.ast_graph;

    let name = match_ast_d(graph, n_id, "type_identifier", Some(1))
        .map_or_else(|| "CompanionObject".to_owned(), |id| node_to_str(graph, id));

    let block_id = match_ast_d(graph, n_id, "class_body", Some(1));

    let (modifiers_id, access_modifiers) = extract_modifiers(graph, n_id);
    let effective_modifiers_id =
        modifiers_id.or_else(|| match_ast_d(graph, n_id, "modifiers", Some(1)));

    let direct_children = MethodDirectChildren {
        block_id,
        ..MethodDirectChildren::default()
    };
    let list_children = MethodListChildren {
        modifiers_ids: effective_modifiers_id.into_iter().collect(),
        ..MethodListChildren::default()
    };

    build_method_declaration_node(
        args,
        n_id,
        Some(name),
        &direct_children,
        &list_children,
        access_modifiers,
    )
    .map(Some)
}