diff --git a/rust/saturn/src/model/definitions.rs b/rust/saturn/src/model/definitions.rs index f26c7ce8..b5614842 100644 --- a/rust/saturn/src/model/definitions.rs +++ b/rust/saturn/src/model/definitions.rs @@ -156,38 +156,7 @@ pub struct ClassDefinition { mixins: Vec, } -/// A singleton class definition created from `class << X` syntax. -/// This is created only when `class << X` syntax is encountered, NOT for `def self.foo`. -/// Methods with receivers (like `def self.foo`) have their `receiver` field set instead. -/// -/// # Examples -/// ```ruby -/// class Foo -/// class << self # attached_target = NameId("Foo") -/// def bar; end -/// end -/// end -/// -/// class << Foo # attached_target = NameId("Foo") -/// def baz; end -/// end -/// ``` -#[derive(Debug)] -pub struct SingletonClassDefinition { - /// The name of this singleton class (e.g., `` for `class << self` inside `class Foo`) - name_id: NameId, - uri_id: UriId, - offset: Offset, - comments: Vec, - /// The definition where `class << X` was found (lexical owner) - lexical_nesting_id: Option, - /// Members defined directly in this singleton class - members: Vec, - /// Mixins declared in this singleton class - mixins: Vec, -} - -impl SingletonClassDefinition { +impl ClassDefinition { #[must_use] pub const fn new( name_id: NameId, @@ -195,6 +164,7 @@ impl SingletonClassDefinition { offset: Offset, comments: Vec, lexical_nesting_id: Option, + superclass_ref: Option, ) -> Self { Self { name_id, @@ -202,6 +172,7 @@ impl SingletonClassDefinition { offset, comments, lexical_nesting_id, + superclass_ref, members: Vec::new(), mixins: Vec::new(), } @@ -238,25 +209,61 @@ impl SingletonClassDefinition { } #[must_use] - pub fn members(&self) -> &[DefinitionId] { - &self.members + pub fn superclass_ref(&self) -> Option { + self.superclass_ref } #[must_use] - pub fn mixins(&self) -> &[Mixin] { - &self.mixins + pub fn members(&self) -> &[DefinitionId] { + &self.members } pub fn add_member(&mut self, member_id: DefinitionId) { self.members.push(member_id); } + #[must_use] + pub fn mixins(&self) -> &[Mixin] { + &self.mixins + } + pub fn add_mixin(&mut self, mixin: Mixin) { self.mixins.push(mixin); } } -impl ClassDefinition { +/// A singleton class definition created from `class << X` syntax. +/// This is created only when `class << X` syntax is encountered, NOT for `def self.foo`. +/// Methods with receivers (like `def self.foo`) have their `receiver` field set instead. +/// +/// # Examples +/// ```ruby +/// class Foo +/// class << self # attached_target = NameId("Foo") +/// def bar; end +/// end +/// end +/// +/// class << Foo # attached_target = NameId("Foo") +/// def baz; end +/// end +/// ``` +#[derive(Debug)] +pub struct SingletonClassDefinition { + /// The name of this singleton class (e.g., `` for `class << self` inside `class Foo`) + name_id: NameId, + uri_id: UriId, + offset: Offset, + comments: Vec, + /// The definition where `class << X` was found (lexical owner) + lexical_nesting_id: Option, + /// Members defined directly in this singleton class + members: Vec, + /// Mixins declared in this singleton class + mixins: Vec, +} + +impl SingletonClassDefinition { #[must_use] pub const fn new( name_id: NameId, @@ -264,7 +271,6 @@ impl ClassDefinition { offset: Offset, comments: Vec, lexical_nesting_id: Option, - superclass_ref: Option, ) -> Self { Self { name_id, @@ -272,7 +278,6 @@ impl ClassDefinition { offset, comments, lexical_nesting_id, - superclass_ref, members: Vec::new(), mixins: Vec::new(), } @@ -308,25 +313,20 @@ impl ClassDefinition { &self.lexical_nesting_id } - #[must_use] - pub fn superclass_ref(&self) -> Option { - self.superclass_ref - } - #[must_use] pub fn members(&self) -> &[DefinitionId] { &self.members } - pub fn add_member(&mut self, member_id: DefinitionId) { - self.members.push(member_id); - } - #[must_use] pub fn mixins(&self) -> &[Mixin] { &self.mixins } + pub fn add_member(&mut self, member_id: DefinitionId) { + self.members.push(member_id); + } + pub fn add_mixin(&mut self, mixin: Mixin) { self.mixins.push(mixin); }