---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_with_field_types"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST)]
  pub struct Complex {
      simple_field: NodeId<crate::Type>,
      optional_field: Option<NodeId<crate::Type>>,
      vec_field: Vec<crate::Item>,
      field_field: Field<bool>,
      enum_field: Field<Enum<crate::Visibility>>,
      enum_node: EnumNodeId<crate::Expression>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct Complex {
      /// 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) simple_field: crate::NodeId,
      pub(crate) optional_field: Option<crate::NodeId>,
      pub(crate) vec_field: Vec<crate::Item>,
      pub(crate) field_field: bool,
      pub(crate) enum_field: crate::Visibility,
      pub(crate) enum_node: crate::NodeId,
  }
  impl Complex {
      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 complex_field {}
  #[allow(unused)]
  impl Complex {
      ///Returns the `simple_field` field
      pub fn get_simple_field<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<&'ast crate::Type> {
          {
              let simple_field = &self.simple_field;
              ast.node(*simple_field).and_then(|node| crate::Type::from_node(node))
          }
      }
      ///Returns the NodeId for the `simple_field` field
      pub fn get_simple_field_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let simple_field = &self.simple_field;
              *simple_field
          }
      }
      ///Returns the `optional_field` field
      pub fn get_optional_field<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<&'ast crate::Type> {
          {
              if let Some(ref optional_field) = self.optional_field {
                  ast.node(*optional_field).and_then(|node| crate::Type::from_node(node))
              } else {
                  None
              }
          }
      }
      ///Returns the NodeId for the `optional_field` field
      pub fn get_optional_field_id<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<crate::NodeId> {
          {
              if let Some(ref optional_field) = self.optional_field {
                  Some(*optional_field)
              } else {
                  None
              }
          }
      }
      ///Returns the `vec_field` field
      pub fn get_vec_field<'ast>(&self, ast: &'ast crate::AST) -> Vec<crate::Item> {
          {
              let vec_field = &self.vec_field;
              ast.node(*vec_field)
          }
      }
      ///Returns the NodeIds for the `vec_field` field
      pub fn get_vec_field_ids<'ast>(&self, ast: &'ast crate::AST) -> Vec<crate::NodeId> {
          {
              let vec_field = &self.vec_field;
              vec_field.clone()
          }
      }
      ///Returns the `field_field` field
      pub fn get_field_field<'ast>(&self, ast: &'ast crate::AST) -> bool {
          {
              let field_field = &self.field_field;
              *field_field
          }
      }
      ///Returns the `enum_field` field
      pub fn get_enum_field<'ast>(&self, ast: &'ast crate::AST) -> &crate::Visibility {
          {
              let enum_field = &self.enum_field;
              enum_field
          }
      }
      ///Returns the `enum_node` field
      pub fn get_enum_node<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<crate::Expression<'ast>> {
          {
              let enum_node = &self.enum_node;
              ast.node(*enum_node).and_then(|node| crate::Expression::from_node(node))
          }
      }
      ///Returns the NodeId for the `enum_node` field
      pub fn get_enum_node_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let enum_node = &self.enum_node;
              *enum_node
          }
      }
  }
  #[allow(unused)]
  impl<'ast> Complex {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          self.get_enum_node(ast).unwrap().validate(ast).unwrap();
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for Complex {
      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) }, "Complex"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for Complex {
      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) }, "Complex"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for Complex {
      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)
                  },
                  &"Complex",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for Complex {
      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)
                  },
                  &"Complex",
              ),
          );
          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 simple_field = &self.simple_field;
                  b.add_node_with_state(state, stringify!(simple_field), simple_field);
              };
              {
                  if let Some(ref optional_field) = self.optional_field {
                      b.add_node_with_state(
                          state,
                          stringify!(optional_field),
                          optional_field,
                      );
                  }
              };
              {
                  let vec_field = &self.vec_field;
                  b.add_nodes_of_builders(
                      stringify!(vec_field),
                      vec_field
                          .iter()
                          .map(|child| bluegum::Builder::render_with_state(child, state))
                          .collect::<Vec<bluegum::Builder>>(),
                  );
              };
              {
                  let field_field = &self.field_field;
                  use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
                  b.field(
                      stringify!(field_field),
                      format!("{:?}", field_field).purple().italic().to_string(),
                  );
              };
              {
                  let enum_field = &self.enum_field;
                  use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
                  b.field(
                      stringify!(enum_field),
                      format!("{:?}", enum_field).purple().italic().to_string(),
                  );
              };
              {
                  let enum_node = &self.enum_node;
                  match state.get(*enum_node) {
                      Some(node) => {
                          b.add_node_with_state(
                              state,
                              stringify!(enum_node),
                              &crate::Expression::from(node),
                          );
                      }
                      None => {
                          b.field(&format!("Node not found: {self}"), "None");
                      }
                  }
              };
          };
      }
  }
