mago_reflection/function_like/parameter.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
use serde::Deserialize;
use serde::Serialize;
use mago_interner::StringIdentifier;
use mago_source::HasSource;
use mago_source::SourceIdentifier;
use mago_span::HasSpan;
use mago_span::Span;
use crate::attribute::AttributeReflection;
use crate::r#type::TypeReflection;
/// Represents a parameter in a function-like entity (such as a function or method),
/// including its type, attributes, and various properties.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub struct FunctionLikeParameterReflection {
/// Attributes associated with the parameter, such as annotations or metadata.
pub attribute_reflections: Vec<AttributeReflection>,
/// The type of the parameter, if specified.
pub type_reflection: Option<TypeReflection>,
/// The name identifier of the parameter.
pub name: StringIdentifier,
/// Indicates whether the parameter accepts a variable number of arguments.
pub is_variadic: bool,
/// Indicates whether the parameter is passed by reference.
pub is_passed_by_reference: bool,
/// Indicates whether the parameter promotes a property in a constructor, typically used in PHP class constructors.
pub is_promoted_property: bool,
/// The default value of the parameter, if any, including its type and span in the source code.
pub default: Option<FunctionLikeParameterDefaultValueReflection>,
/// The span of the parameter in the source code.
pub span: Span,
}
impl HasSpan for FunctionLikeParameterReflection {
/// Returns the combined span of the parameter in the source code.
fn span(&self) -> Span {
self.span
}
}
impl HasSource for FunctionLikeParameterReflection {
/// Returns the source identifier of the file containing this parameter.
fn source(&self) -> SourceIdentifier {
self.span().source()
}
}
/// Represents the default value of a function-like parameter, including its inferred type
/// and the source code span where it is defined.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub struct FunctionLikeParameterDefaultValueReflection {
/// The inferred type of the default value.
/// This type is determined based on the default value itself.
pub type_reflection: TypeReflection,
/// The span in the source code where the default value is located.
pub span: Span,
}
impl HasSpan for FunctionLikeParameterDefaultValueReflection {
/// Returns the span of the default value in the source code.
///
/// This span indicates where the default value is defined within the parameter declaration.
fn span(&self) -> Span {
self.span
}
}
impl HasSource for FunctionLikeParameterDefaultValueReflection {
/// Returns the source identifier of the file containing this default value.
fn source(&self) -> SourceIdentifier {
self.span.source()
}
}