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)]
18pub struct PropertyHookMetadata {
19 pub name: Atom,
21
22 pub span: Span,
24
25 pub flags: MetadataFlags,
27
28 pub parameter: Option<FunctionLikeParameterMetadata>,
31
32 pub returns_by_ref: bool,
34
35 pub is_abstract: bool,
37
38 pub attributes: Vec<AttributeMetadata>,
40
41 pub return_type_metadata: Option<TypeMetadata>,
43
44 pub has_docblock: bool,
46
47 pub issues: Vec<Issue>,
49}
50
51impl PropertyHookMetadata {
52 #[inline]
54 #[must_use]
55 pub fn new(name: Atom, span: Span) -> Self {
56 Self {
57 name,
58 span,
59 flags: MetadataFlags::empty(),
60 parameter: None,
61 returns_by_ref: false,
62 is_abstract: false,
63 attributes: Vec::new(),
64 return_type_metadata: None,
65 has_docblock: false,
66 issues: Vec::new(),
67 }
68 }
69
70 #[inline]
72 #[must_use]
73 pub fn is_get(&self) -> bool {
74 self.name.as_str() == "get"
75 }
76
77 #[inline]
79 #[must_use]
80 pub fn is_set(&self) -> bool {
81 self.name.as_str() == "set"
82 }
83
84 #[inline]
86 #[must_use]
87 pub fn with_flags(mut self, flags: MetadataFlags) -> Self {
88 self.flags = flags;
89 self
90 }
91
92 #[inline]
94 #[must_use]
95 pub fn with_parameter(mut self, parameter: Option<FunctionLikeParameterMetadata>) -> Self {
96 self.parameter = parameter;
97 self
98 }
99
100 #[inline]
102 #[must_use]
103 pub fn with_returns_by_ref(mut self, returns_by_ref: bool) -> Self {
104 self.returns_by_ref = returns_by_ref;
105 self
106 }
107
108 #[inline]
110 #[must_use]
111 pub fn with_is_abstract(mut self, is_abstract: bool) -> Self {
112 self.is_abstract = is_abstract;
113 self
114 }
115
116 #[inline]
118 #[must_use]
119 pub fn with_attributes(mut self, attributes: Vec<AttributeMetadata>) -> Self {
120 self.attributes = attributes;
121 self
122 }
123
124 #[inline]
126 #[must_use]
127 pub fn with_return_type_metadata(mut self, return_type_metadata: Option<TypeMetadata>) -> Self {
128 self.return_type_metadata = return_type_metadata;
129 self
130 }
131
132 #[inline]
134 #[must_use]
135 pub fn with_has_docblock(mut self, has_docblock: bool) -> Self {
136 self.has_docblock = has_docblock;
137 self
138 }
139
140 #[inline]
142 #[must_use]
143 pub fn with_issues(mut self, issues: Vec<Issue>) -> Self {
144 self.issues = issues;
145 self
146 }
147
148 #[inline]
150 pub fn take_issues(&mut self) -> Vec<Issue> {
151 std::mem::take(&mut self.issues)
152 }
153}