use crate::query::adj_ast;
use crate::syntax::builders::do_statement::build_do_statement_node;
use crate::syntax::fields::java::do_statement;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let mut body_id = args.required_field_alt(n_id, do_statement::BODY)?;
if args.ast_graph.label_type(body_id) == Some("expression_statement") {
body_id = adj_ast(args.ast_graph, body_id, None, &[])
.first()
.copied()
.ok_or(SyntaxGraphError::UnexpectedAstShape)?;
}
let condition_id = args.required_field_alt(n_id, do_statement::CONDITION)?;
build_do_statement_node(args, n_id, body_id, condition_id).map(Some)
}