Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions rust/saturn/src/model/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,52 +156,23 @@ pub struct ClassDefinition {
mixins: Vec<Mixin>,
}

/// 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., `<Foo>` for `class << self` inside `class Foo`)
name_id: NameId,
uri_id: UriId,
offset: Offset,
comments: Vec<Comment>,
/// The definition where `class << X` was found (lexical owner)
lexical_nesting_id: Option<DefinitionId>,
/// Members defined directly in this singleton class
members: Vec<DefinitionId>,
/// Mixins declared in this singleton class
mixins: Vec<Mixin>,
}

impl SingletonClassDefinition {
impl ClassDefinition {
#[must_use]
pub const fn new(
name_id: NameId,
uri_id: UriId,
offset: Offset,
comments: Vec<Comment>,
lexical_nesting_id: Option<DefinitionId>,
superclass_ref: Option<NameId>,
) -> Self {
Self {
name_id,
uri_id,
offset,
comments,
lexical_nesting_id,
superclass_ref,
members: Vec::new(),
mixins: Vec::new(),
}
Expand Down Expand Up @@ -238,41 +209,75 @@ impl SingletonClassDefinition {
}

#[must_use]
pub fn members(&self) -> &[DefinitionId] {
&self.members
pub fn superclass_ref(&self) -> Option<NameId> {
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., `<Foo>` for `class << self` inside `class Foo`)
name_id: NameId,
uri_id: UriId,
offset: Offset,
comments: Vec<Comment>,
/// The definition where `class << X` was found (lexical owner)
lexical_nesting_id: Option<DefinitionId>,
/// Members defined directly in this singleton class
members: Vec<DefinitionId>,
/// Mixins declared in this singleton class
mixins: Vec<Mixin>,
}

impl SingletonClassDefinition {
#[must_use]
pub const fn new(
name_id: NameId,
uri_id: UriId,
offset: Offset,
comments: Vec<Comment>,
lexical_nesting_id: Option<DefinitionId>,
superclass_ref: Option<NameId>,
) -> Self {
Self {
name_id,
uri_id,
offset,
comments,
lexical_nesting_id,
superclass_ref,
members: Vec::new(),
mixins: Vec::new(),
}
Expand Down Expand Up @@ -308,25 +313,20 @@ impl ClassDefinition {
&self.lexical_nesting_id
}

#[must_use]
pub fn superclass_ref(&self) -> Option<NameId> {
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);
}

Comment on lines -321 to +329
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we preserve the order so add_member comes right after members?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I didn't know auto-merge was enabled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_member does come after members. The diff on GitHub is weird, all I did was move the entire impl block as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in SingletonClass: #434

pub fn add_mixin(&mut self, mixin: Mixin) {
self.mixins.push(mixin);
}
Expand Down
Loading