mago_codex/metadata/
enum_case.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_atom::Atom;
5use mago_span::HasSpan;
6use mago_span::Span;
7
8use crate::metadata::attribute::AttributeMetadata;
9use crate::metadata::flags::MetadataFlags;
10use crate::ttype::atomic::TAtomic;
11
12/// Contains metadata associated with a specific `case` within a PHP `enum`.
13///
14/// Represents enum cases in both "pure" enums (e.g., `case Pending;` in `enum Status`)
15/// and "backed" enums (e.g., `case Ok = 200;` in `enum HttpStatus: int`),
16/// including associated attributes, values, and source locations.
17#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
18#[non_exhaustive]
19pub struct EnumCaseMetadata {
20    pub attributes: Vec<AttributeMetadata>,
21    pub name: Atom,
22    pub name_span: Span,
23    pub span: Span,
24    pub value_type: Option<TAtomic>,
25    pub flags: MetadataFlags,
26}
27
28impl EnumCaseMetadata {
29    /// Creates new `EnumCaseMetadata` for a case assumed initially to be non-backed (pure).
30    ///
31    /// Use modifier methods (`set_is_backed`, `with_is_backed`) later during analysis
32    /// if the enum is determined to be backed.
33    ///
34    /// # Arguments
35    /// * `name`: The identifier (name) of the enum case (e.g., `PENDING`).
36    /// * `name_span`: The source code location of the name identifier.
37    /// * `span`: The source code location of the entire case declaration.
38    #[inline]
39    #[must_use]
40    pub fn new(name: Atom, name_span: Span, span: Span, flags: MetadataFlags) -> Self {
41        Self { attributes: Vec::new(), name, name_span, span, flags, value_type: None }
42    }
43}
44
45impl HasSpan for EnumCaseMetadata {
46    fn span(&self) -> Span {
47        self.span
48    }
49}