mago_reflection/type/
mod.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_source::HasSource;
5use mago_source::SourceIdentifier;
6use mago_span::HasSpan;
7use mago_span::Span;
8
9use crate::r#type::kind::TypeKind;
10
11pub mod kind;
12
13/// Represents a reflection of a type in the codebase.
14///
15/// This structure provides metadata about a type, including its kind (e.g., string, integer),
16/// whether it was inferred, and its location in the source code.
17#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
18pub struct TypeReflection {
19    /// The kind of the type (e.g., string, integer).
20    pub kind: TypeKind,
21
22    /// Whether the type was inferred or explicitly declared.
23    pub inferred: bool,
24
25    /// The span of the type in the source code.
26    pub span: Span,
27}
28
29impl HasSpan for TypeReflection {
30    /// Returns the span of the type in the source code.
31    ///
32    /// The span identifies the precise location of the type definition or usage
33    /// within the source file.
34    fn span(&self) -> Span {
35        self.span
36    }
37}
38
39impl HasSource for TypeReflection {
40    /// Returns the source identifier of the file containing this type.
41    ///
42    /// The source identifier provides metadata about the origin of the file,
43    /// such as whether it is user-defined, vendor-provided, or built-in.
44    fn source(&self) -> SourceIdentifier {
45        self.span.source()
46    }
47}