Skip to content

[SR-7292] Swift local refactoring: adding field-wise initializers automatically #49840

@nkcsgexi

Description

@nkcsgexi
Previous ID SR-7292
Radar None
Original Reporter @nkcsgexi
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels New Feature, Refactoring, StarterBug
Assignee mohit.athwani (JIRA)
Priority Medium

md5: 717c1a5493eaa3054e6b1fecb975394a

Issue Description:

Some initializers' implementation is quite expectable, e.g. a field-wise naive initializer. Thus, we can implement an automated refactoring to help developers adding such initializer, e.g.

// Right click on Animal and apply "add field-wise init" refactoring
class Animal {
  var age: Int
  var kind: AnimalKind
  var gender: Gender
}

An available refactoring "add field-wise init" shows up when the user right clicks the declared name Animal. After applying the local refactoring, the code snippet transforms to:

// code placeholder
class Animal {
  var age: Int
  var kind: AnimalKind
  var gender: Gender

  // Auto-generated initializer
  init(age: Int, kind: AnimalKind, gender: Gender) {
    self.age = age
    self.kind = kind
    self.gender = gender
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersmemberwise initFeature: Memberwise structure initializersrefactoringArea → source tooling: refactoringsource toolingArea: IDE support, SourceKit, and other source tooling
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions