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)]
18pub struct EnumCaseMetadata {
19 pub attributes: Vec<AttributeMetadata>,
20 pub name: Atom,
21 pub name_span: Span,
22 pub span: Span,
23 pub value_type: Option<TAtomic>,
24 pub flags: MetadataFlags,
25}
26
27impl EnumCaseMetadata {
28 /// Creates new `EnumCaseMetadata` for a case assumed initially to be non-backed (pure).
29 ///
30 /// Use modifier methods (`set_is_backed`, `with_is_backed`) later during analysis
31 /// if the enum is determined to be backed.
32 ///
33 /// # Arguments
34 /// * `name`: The identifier (name) of the enum case (e.g., `PENDING`).
35 /// * `name_span`: The source code location of the name identifier.
36 /// * `span`: The source code location of the entire case declaration.
37 #[inline]
38 pub fn new(name: Atom, name_span: Span, span: Span, flags: MetadataFlags) -> Self {
39 Self { attributes: Vec::new(), name, name_span, span, flags, value_type: None }
40 }
41}
42
43impl HasSpan for EnumCaseMetadata {
44 fn span(&self) -> Span {
45 self.span
46 }
47}