mago_reflection

Struct CodebaseReflection

Source
pub struct CodebaseReflection {
    pub constant_reflections: HashMap<Name, ConstantReflection>,
    pub constant_identifiers: HashMap<StringIdentifier, Name>,
    pub function_like_reflections: HashMap<FunctionLikeName, FunctionLikeReflection>,
    pub function_identifiers: HashMap<StringIdentifier, FunctionLikeName>,
    pub class_like_reflections: HashMap<ClassLikeName, ClassLikeReflection>,
    pub class_like_names: HashMap<StringIdentifier, ClassLikeName>,
    pub direct_classlike_descendants: HashMap<StringIdentifier, HashSet<StringIdentifier>>,
    pub all_classlike_descendants: HashMap<StringIdentifier, HashSet<StringIdentifier>>,
    pub populated: bool,
}

Fields§

§constant_reflections: HashMap<Name, ConstantReflection>§constant_identifiers: HashMap<StringIdentifier, Name>§function_like_reflections: HashMap<FunctionLikeName, FunctionLikeReflection>§function_identifiers: HashMap<StringIdentifier, FunctionLikeName>§class_like_reflections: HashMap<ClassLikeName, ClassLikeReflection>§class_like_names: HashMap<StringIdentifier, ClassLikeName>§direct_classlike_descendants: HashMap<StringIdentifier, HashSet<StringIdentifier>>§all_classlike_descendants: HashMap<StringIdentifier, HashSet<StringIdentifier>>§populated: bool

Implementations§

Source§

impl CodebaseReflection

Source

pub fn new() -> Self

Creates a new, empty CodebaseReflection.

Source

pub fn register_constant(&mut self, constant: ConstantReflection) -> bool

Registers a new constant in the codebase.

If the constant already exists, it will not be added again.

Returns false if the constant already exists.

Source

pub fn register_function_like( &mut self, function_like: FunctionLikeReflection, ) -> bool

Registers a new function-like entity in the codebase.

If the function-like entity already exists, it will not be added again.

Returns false if the function-like entity already exists.

Source

pub fn register_class_like(&mut self, class_like: ClassLikeReflection) -> bool

Registers a new class-like entity (class, enum, interface, or trait) in the codebase.

If the class-like entity already exists, it will not be added again.

Returns false if the class-like entity already exists.

Source

pub fn constant_exists(&self, name: &StringIdentifier) -> bool

Checks if a constant with the given name exists.

Source

pub fn function_exists(&self, name: &StringIdentifier) -> bool

Checks if a function with the given name exists.

Source

pub fn class_exists(&self, name: &StringIdentifier) -> bool

Checks if a class with the given name exists.

Source

pub fn enum_exists(&self, name: &StringIdentifier) -> bool

Checks if an enum with the given name exists.

Source

pub fn interface_exists(&self, name: &StringIdentifier) -> bool

Checks if an interface with the given name exists.

Source

pub fn trait_exists(&self, name: &StringIdentifier) -> bool

Checks if a trait with the given name exists.

Source

pub fn get_constant( &self, name: &StringIdentifier, ) -> Option<&ConstantReflection>

Retrieves a constant by name, if it exists.

Source

pub fn get_function_like( &self, identifier: FunctionLikeName, ) -> Option<&FunctionLikeReflection>

Retrieves a function-like by its identifier, if it exists.

Source

pub fn get_function( &self, name: &StringIdentifier, ) -> Option<&FunctionLikeReflection>

Retrieves a function by name, if it exists.

Source

pub fn get_closure( &self, position: &impl HasPosition, ) -> Option<&FunctionLikeReflection>

Retrieves a closure by its position, if it exists.

Source

pub fn get_arrow_function( &self, position: &impl HasPosition, ) -> Option<&FunctionLikeReflection>

Retrieves an arrow function by its position, if it exists.

Source

pub fn get_class_like( &self, identifier: ClassLikeName, ) -> Option<&ClassLikeReflection>

Retrieves a class-like entity by its identifier, if it exists.

Source

pub fn get_named_class_like( &self, name: &StringIdentifier, ) -> Option<&ClassLikeReflection>

Retrieves a class-like entity by its name, if it exists.

Source

pub fn get_class(&self, name: &StringIdentifier) -> Option<&ClassLikeReflection>

Retrieves a class by name, if it exists.

Source

pub fn get_enum(&self, name: &StringIdentifier) -> Option<&ClassLikeReflection>

Retrieves an enum by name, if it exists.

Source

pub fn get_interface( &self, name: &StringIdentifier, ) -> Option<&ClassLikeReflection>

Retrieves an interface by name, if it exists.

Source

pub fn get_trait(&self, name: &StringIdentifier) -> Option<&ClassLikeReflection>

Retrieves a trait by name, if it exists.

Source

pub fn get_enclosing_function_like( &self, has_position: &impl HasPosition, ) -> Option<&FunctionLikeReflection>

Returns the function-like reflection (function, closure, etc.) that encloses the given offset.

This method iterates through the reflections in the codebase, filtering for function-like reflections that contain the given offset in their definition range. It returns the reflection with the largest starting offset, effectively finding the innermost function-like reflection containing the offset.

§Arguments
  • has_position - The position to search for.
§Returns
  • Option<&FunctionLikeReflection> - The enclosing function-like reflection, if found.
Source

pub fn get_enclosing_class_like( &self, has_position: &impl HasPosition, ) -> Option<&ClassLikeReflection>

Returns the class-like reflection (class, trait, etc.) that encloses the given offset.

This method iterates through the reflections in the codebase, filtering for class-like reflections that contain the given offset in their definition range. It returns the reflection with the largest starting offset, effectively finding the innermost class-like reflection containing the offset.

§Arguments
  • has_position - The position to search for.
§Returns
  • Option<&ClassLikeReflection> - The enclosing class-like reflection, if found.

Trait Implementations§

Source§

impl Clone for CodebaseReflection

Source§

fn clone(&self) -> CodebaseReflection

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodebaseReflection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodebaseReflection

Source§

fn default() -> CodebaseReflection

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CodebaseReflection

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for CodebaseReflection

Source§

fn eq(&self, other: &CodebaseReflection) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CodebaseReflection

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for CodebaseReflection

Source§

impl StructuralPartialEq for CodebaseReflection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,