use alloc::string::String;
use crate::query::adj_ast;
use crate::syntax::builders::method_declaration::{
build_method_declaration_node, MethodDirectChildren, MethodListChildren,
};
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let childs = adj_ast(graph, n_id, None, &[]);
let accessor_name = childs
.first()
.and_then(|c_id| graph.label_type(*c_id))
.map(String::from);
let block = childs.get(1).copied().filter(|c_id| {
matches!(
graph.label_type(*c_id),
Some("block" | "arrow_expression_clause")
)
});
let direct = MethodDirectChildren {
block_id: block,
..MethodDirectChildren::default()
};
build_method_declaration_node(
args,
n_id,
accessor_name,
&direct,
&MethodListChildren::default(),
None,
)
.map(Some)
}