+ # Factorize annotations visit for all APropdef.
+ #
+ # Return true if annotations were inlined.
+ fun visit_annotations(v: PrettyPrinterVisitor, n_annotations: nullable AAnnotations): Bool do
+ var res = v.can_inline(n_annotations)
+ if n_annotations != null then v.visit n_annotations
+ return res
+ end
+
+ # Factorize block visit for APropdefs.
+ #
+ # Were annotations printed inline? If so, we need to print the block differently.
+ fun visit_block(v: PrettyPrinterVisitor, n_block: nullable AExpr, annot_inline: Bool) do
+ # var can_inline = v.can_inline(n_block)
+ if n_block == null then return
+ if n_annotations != null and not annot_inline then
+ v.forcen
+ v.addt
+ end
+ if v.inline_do then
+ while not v.current_token isa TKwdo do v.skip
+ end
+ var token = v.current_token
+ var do_inline = true
+ loop
+ if token isa TEol then
+ v.skip
+ if not v.can_inline(n_block) then
+ v.forcen
+ v.addt
+ do_inline = false
+ end
+ end
+ token = v.current_token
+ if token isa TKwdo then break
+ end
+ if annot_inline and do_inline then v.adds
+ v.consume "do"
+
+ if v.can_inline(n_block) and do_inline then
+ v.adds
+
+ if n_block isa ABlockExpr then
+ if n_block.n_expr.is_empty then
+ v.visit n_block.n_kwend
+ else
+ v.visit n_block.n_expr.first
+ v.current_token = n_block.n_kwend
+ v.skip
+ end
+ else
+ v.visit n_block
+ if v.current_token isa TKwend then v.skip
+ end
+ else
+ v.finish_line
+ if was_inline then
+ v.forcen
+ else
+ v.addn
+ end
+ v.indent += 1
+
+ if n_block isa ABlockExpr then
+ n_block.force_block = true
+ v.visit n_block
+ v.catch_up n_block.n_kwend
+ else
+ v.addt
+ v.visit n_block
+ v.forcen
+ end
+
+ v.indent -= 1
+ v.addt
+ if n_block isa ABlockExpr then
+ v.visit n_block.n_kwend
+ else
+ v.add "end"
+ end
+ end
+ v.finish_line
+ end
+