mago_codex/metadata/enum_case.rs
1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_interner::StringIdentifier;
5use mago_span::HasSpan;
6use mago_span::Span;
7
8use crate::metadata::attribute::AttributeMetadata;
9use crate::ttype::atomic::TAtomic;
10
11/// Contains metadata associated with a specific `case` within a PHP `enum`.
12///
13/// Represents enum cases in both "pure" enums (e.g., `case Pending;` in `enum Status`)
14/// and "backed" enums (e.g., `case Ok = 200;` in `enum HttpStatus: int`),
15/// including associated attributes, values, and source locations.
16#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
17pub struct EnumCaseMetadata {
18 pub attributes: Vec<AttributeMetadata>,
19 pub name: StringIdentifier,
20 pub name_span: Span,
21 pub span: Span,
22 pub value_type: Option<TAtomic>,
23 pub is_backed: bool,
24 pub is_deprecated: bool,
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: StringIdentifier, name_span: Span, span: Span) -> Self {
39 Self {
40 attributes: Vec::new(),
41 name,
42 name_span,
43 span,
44 value_type: None,
45 is_backed: false, // Assume pure initially
46 is_deprecated: false,
47 }
48 }
49}
50
51impl HasSpan for EnumCaseMetadata {
52 fn span(&self) -> Span {
53 self.span
54 }
55}