Uploaded image for project: 'Swift'
  1. Swift
  2. SR-7292

Swift local refactoring: adding field-wise initializers automatically

    XMLWordPrintable

    Details

      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
        }
      }

        Attachments

          Activity

            People

            Assignee:
            mohit.athwani Mohit Athwani
            Reporter:
            nkcsgexi Xi Ge
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: