mago_codex/metadata/
property_hook.rs1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_atom::Atom;
5use mago_reporting::Issue;
6use mago_span::Span;
7
8use crate::metadata::attribute::AttributeMetadata;
9use crate::metadata::flags::MetadataFlags;
10use crate::metadata::parameter::FunctionLikeParameterMetadata;
11use crate::metadata::ttype::TypeMetadata;
12
13#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
18#[non_exhaustive]
19pub struct PropertyHookMetadata {
20 pub name: Atom,
22
23 pub span: Span,
25
26 pub flags: MetadataFlags,
28
29 pub parameter: Option<FunctionLikeParameterMetadata>,
32
33 pub returns_by_ref: bool,
35
36 pub is_abstract: bool,
38
39 pub attributes: Vec<AttributeMetadata>,
41
42 pub return_type_metadata: Option<TypeMetadata>,
44
45 pub has_docblock: bool,
47
48 pub issues: Vec<Issue>,
50}
51
52impl PropertyHookMetadata {
53 #[inline]
55 #[must_use]
56 pub fn new(name: Atom, span: Span) -> Self {
57 Self {
58 name,
59 span,
60 flags: MetadataFlags::empty(),
61 parameter: None,
62 returns_by_ref: false,
63 is_abstract: false,
64 attributes: Vec::new(),
65 return_type_metadata: None,
66 has_docblock: false,
67 issues: Vec::new(),
68 }
69 }
70
71 #[inline]
73 #[must_use]
74 pub fn is_get(&self) -> bool {
75 self.name.as_str() == "get"
76 }
77
78 #[inline]
80 #[must_use]
81 pub fn is_set(&self) -> bool {
82 self.name.as_str() == "set"
83 }
84
85 #[inline]
87 #[must_use]
88 pub fn with_flags(mut self, flags: MetadataFlags) -> Self {
89 self.flags = flags;
90 self
91 }
92
93 #[inline]
95 #[must_use]
96 pub fn with_parameter(mut self, parameter: Option<FunctionLikeParameterMetadata>) -> Self {
97 self.parameter = parameter;
98 self
99 }
100
101 #[inline]
103 #[must_use]
104 pub fn with_returns_by_ref(mut self, returns_by_ref: bool) -> Self {
105 self.returns_by_ref = returns_by_ref;
106 self
107 }
108
109 #[inline]
111 #[must_use]
112 pub fn with_is_abstract(mut self, is_abstract: bool) -> Self {
113 self.is_abstract = is_abstract;
114 self
115 }
116
117 #[inline]
119 #[must_use]
120 pub fn with_attributes(mut self, attributes: Vec<AttributeMetadata>) -> Self {
121 self.attributes = attributes;
122 self
123 }
124
125 #[inline]
127 #[must_use]
128 pub fn with_return_type_metadata(mut self, return_type_metadata: Option<TypeMetadata>) -> Self {
129 self.return_type_metadata = return_type_metadata;
130 self
131 }
132
133 #[inline]
135 #[must_use]
136 pub fn with_has_docblock(mut self, has_docblock: bool) -> Self {
137 self.has_docblock = has_docblock;
138 self
139 }
140
141 #[inline]
143 #[must_use]
144 pub fn with_issues(mut self, issues: Vec<Issue>) -> Self {
145 self.issues = issues;
146 self
147 }
148
149 #[inline]
151 pub fn take_issues(&mut self) -> Vec<Issue> {
152 std::mem::take(&mut self.issues)
153 }
154}