Skip to main content

rajac_types/
method_signature.rs

1use crate::TypeId;
2use rajac_base::shared_string::SharedString;
3
4/// Method modifiers used during type checking and overload resolution.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct MethodModifiers(pub u32);
7
8impl MethodModifiers {
9    /// Method is visible to all.
10    pub const PUBLIC: u32 = 0x0001;
11    /// Method is only visible within the declaring class.
12    pub const PRIVATE: u32 = 0x0002;
13    /// Method is visible to subclasses and same-package types.
14    pub const PROTECTED: u32 = 0x0004;
15    /// Method is declared as static.
16    pub const STATIC: u32 = 0x0008;
17    /// Method is declared as final.
18    pub const FINAL: u32 = 0x0010;
19    /// Method is declared as abstract.
20    pub const ABSTRACT: u32 = 0x0400;
21    /// Method is declared as native.
22    pub const NATIVE: u32 = 0x0100;
23    /// Method is declared as synchronized.
24    pub const SYNCHRONIZED: u32 = 0x0020;
25    /// Method is declared as strictfp.
26    pub const STRICTFP: u32 = 0x0800;
27
28    /// Returns true when the method is marked as `static`.
29    pub fn is_static(&self) -> bool {
30        self.0 & Self::STATIC != 0
31    }
32}
33
34/// Type-level method signature for overload resolution.
35#[derive(Debug, Clone, PartialEq)]
36pub struct MethodSignature {
37    /// Method name (constructors use the class name).
38    pub name: SharedString,
39    /// Parameter types in declaration order.
40    pub params: Vec<TypeId>,
41    /// Return type for the method.
42    pub return_type: TypeId,
43    /// Declared checked exceptions.
44    pub throws: Vec<TypeId>,
45    /// Visibility and behavior modifiers.
46    pub modifiers: MethodModifiers,
47}
48
49impl MethodSignature {
50    pub fn new(
51        name: SharedString,
52        params: Vec<TypeId>,
53        return_type: TypeId,
54        modifiers: MethodModifiers,
55    ) -> Self {
56        Self {
57            name,
58            params,
59            return_type,
60            throws: Vec::new(),
61            modifiers,
62        }
63    }
64
65    pub fn with_throws(mut self, throws: Vec<TypeId>) -> Self {
66        self.throws = throws;
67        self
68    }
69}