mago_codex/identifier/
method.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_interner::StringIdentifier;
5use mago_interner::ThreadedInterner;
6
7/// Represents a unique identifier for a method within a class-like structure.
8/// Combines the fully qualified class name (FQCN) and the method name.
9#[derive(Clone, Debug, PartialEq, Eq, Copy, Serialize, Deserialize, Hash, PartialOrd, Ord)]
10pub struct MethodIdentifier {
11    /// The fully qualified name of the class, interface, trait, or enum containing the method.
12    class_name: StringIdentifier,
13    /// The name of the method itself.
14    method_name: StringIdentifier,
15}
16
17impl MethodIdentifier {
18    /// Creates a new `MethodIdentifier`.
19    ///
20    /// # Arguments
21    ///
22    /// * `class_name`: The `StringIdentifier` for the fully qualified class name.
23    /// * `method_name`: The `StringIdentifier` for the method name.
24    #[inline]
25    pub const fn new(class_name: StringIdentifier, method_name: StringIdentifier) -> Self {
26        Self { class_name, method_name }
27    }
28
29    /// Returns the `StringIdentifier` for the class name.
30    #[inline]
31    pub const fn get_class_name(&self) -> &StringIdentifier {
32        &self.class_name
33    }
34
35    /// Returns the `StringIdentifier` for the method name.
36    #[inline]
37    pub const fn get_method_name(&self) -> &StringIdentifier {
38        &self.method_name
39    }
40
41    /// Converts the identifier to a human-readable string "ClassName::methodName" using the provided interner.
42    ///
43    /// # Arguments
44    ///
45    /// * `interner` - A reference to the `ThreadedInterner` used to resolve `StringIdentifier`s.
46    #[inline]
47    pub fn as_string(&self, interner: &ThreadedInterner) -> String {
48        format!("{}::{}", interner.lookup(&self.class_name), interner.lookup(&self.method_name))
49    }
50
51    /// Converts the identifier to a tuple of `StringIdentifier`s representing the class name and method name.
52    #[inline]
53    pub fn get_key(&self) -> (StringIdentifier, StringIdentifier) {
54        (self.class_name, self.method_name)
55    }
56}