use serde::Deserialize;
use serde::Serialize;
use mago_reporting::IssueCollection;
use mago_source::HasSource;
use mago_source::SourceIdentifier;
use mago_span::HasSpan;
use mago_span::Span;
use crate::Reflection;
use crate::attribute::AttributeReflection;
use crate::class_like::member::ClassLikeMemberVisibilityReflection;
use crate::function_like::parameter::FunctionLikeParameterReflection;
use crate::function_like::r#return::FunctionLikeReturnTypeReflection;
use crate::identifier::FunctionLikeName;
use crate::r#type::kind::Template;
pub mod parameter;
pub mod r#return;
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct FunctionLikeReflection {
pub attribute_reflections: Vec<AttributeReflection>,
pub visibility_reflection: Option<ClassLikeMemberVisibilityReflection>,
pub name: FunctionLikeName,
pub templates: Vec<Template>,
pub parameters: Vec<FunctionLikeParameterReflection>,
pub return_type_reflection: Option<FunctionLikeReturnTypeReflection>,
pub returns_by_reference: bool,
pub has_yield: bool,
pub has_throws: bool,
pub is_anonymous: bool,
pub is_static: bool,
pub is_final: bool,
pub is_abstract: bool,
pub is_pure: bool,
pub is_overriding: bool,
pub span: Span,
pub is_populated: bool,
pub issues: IssueCollection,
}
impl FunctionLikeReflection {
pub fn is_function(&self) -> bool {
matches!(self.name, FunctionLikeName::Function(_))
}
pub fn is_method(&self) -> bool {
matches!(self.name, FunctionLikeName::Method(_, _))
}
pub fn is_property_hook(&self) -> bool {
matches!(self.name, FunctionLikeName::PropertyHook(_, _, _))
}
pub fn is_closure(&self) -> bool {
matches!(self.name, FunctionLikeName::Closure(_))
}
pub fn is_arrow_function(&self) -> bool {
matches!(self.name, FunctionLikeName::ArrowFunction(_))
}
}
impl HasSpan for FunctionLikeReflection {
fn span(&self) -> Span {
self.span
}
}
impl HasSource for FunctionLikeReflection {
fn source(&self) -> SourceIdentifier {
self.span.source()
}
}
impl Reflection for FunctionLikeReflection {
fn get_category(&self) -> crate::SourceCategory {
self.source().category()
}
fn is_populated(&self) -> bool {
self.is_populated
}
fn take_issues(&mut self) -> IssueCollection {
std::mem::take(&mut self.issues)
}
}