SwiftKit / CuckooGenerator

Generator of Mocks for Cuckoo
MIT License
20 stars 4 forks source link

Initializer should not have `func` keyword #6

Closed a-voronov closed 8 years ago

a-voronov commented 8 years ago

I actually thought of declaring isInitializer like

let isInitializer = ["init", "init?"].contains(rawName)

But this is kind of different issue. Failable initializer looses question mark when generated as a class method name. So this code init?(a: Int) { return nil } will result with token.name like this init(a:) Not yet sure if this is an issue though.

TadeasKriz commented 8 years ago

Looks good to me. Thanks! 👍

I'll look into the optional init myself. If there is no information from the SourceKitten output, we'll have to do forward peek in the source itself. We already do this for throws and rethrows because these are not mentioned in the SourceKitten output as well.

TadeasKriz commented 8 years ago

I've tried this and it is a step forward, but not yet a solution. We need a better one, because we have our own initializers in the mock class and we need to figure out how to call super initializers properly. That might be a PITA.

TadeasKriz commented 8 years ago

We won't be really able to mock initializers AFAIK. We need to parse designated initializers from the super class, override them and ask users for the parameters and pass them into the super init. Also the mock class should be final so we don't have to care about required keyword.