---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_with_doc_comments"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST)]
  pub struct Documented {
      /// This is a documented field
      field1: NodeId<crate::Type>,
      /// Multi-line documentation
      /// Second line
      field2: Option<NodeId<crate::Type>>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct Documented {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: crate::SyntaxId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) field1: crate::NodeId,
      pub(crate) field2: Option<crate::NodeId>,
  }
  impl Documented {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> crate::SyntaxId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod documented_field {}
  #[allow(unused)]
  impl Documented {
      ///Returns the `field1` field
      pub fn get_field1<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              let field1 = &self.field1;
              ast.node(*field1).and_then(|node| crate::Type::from_node(node))
          }
      }
      ///Returns the NodeId for the `field1` field
      pub fn get_field1_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let field1 = &self.field1;
              *field1
          }
      }
      ///Returns the `field2` field
      pub fn get_field2<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              if let Some(ref field2) = self.field2 {
                  ast.node(*field2).and_then(|node| crate::Type::from_node(node))
              } else {
                  None
              }
          }
      }
      ///Returns the NodeId for the `field2` field
      pub fn get_field2_id<'ast>(&self, ast: &'ast crate::AST) -> Option<crate::NodeId> {
          { if let Some(ref field2) = self.field2 { Some(*field2) } else { None } }
      }
  }
  #[allow(unused)]
  impl<'ast> Documented {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for Documented {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "Documented"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for Documented {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "Documented"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for Documented {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"Documented",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for Documented {
      fn node_with_state(
          &self,
          b: &mut bluegum::Builder,
          state: &crate::Printer<'tokens>,
      ) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"Documented",
              ),
          );
          if let Some(cst_node) = state.get_syntax(self.syntax) {
              let span = cst_node.span();
              if let Some(span_data) = span.data(state.get_span_cache()) {
                  b.debug(
                      "span",
                      format!("{}..{}", span_data.start, span_data.start + span_data.len),
                  );
              }
          }
          if let Some(meta) = self.meta {
              b.add_node_with_state(state, &"meta".blue().italic().to_string(), &meta);
          }
          {
              {
                  let field1 = &self.field1;
                  b.add_node_with_state(state, stringify!(field1), field1);
              };
              {
                  if let Some(ref field2) = self.field2 {
                      b.add_node_with_state(state, stringify!(field2), field2);
                  }
              };
          };
      }
  }
