Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods reflection #24

Closed
ilyapuchka opened this issue Dec 15, 2016 · 2 comments
Closed

Add methods reflection #24

ilyapuchka opened this issue Dec 15, 2016 · 2 comments
Assignees

Comments

@ilyapuchka
Copy link
Collaborator

ilyapuchka commented Dec 15, 2016

To be able to use Sourcery to generate code for such things like test doubles or dependency injection container it's vital to be able to access information about methods defined in class (or even on a protocol?).

To start method can be modeled like this:

class Method: NSObject {
  class Parameter: NSObject {
     var argumentLabel: String
     var parameterName: String
     var type: String
  }
  var parameters: [Parameter]
  var shortName: String //does not include external parameters names
  var fullName: String
  var returnType: String
  var accessLevel: AccessLevel
  var isStatic: Bool
  var isClass: Bool
}

Then in template it might be used something like this (taking Dobby as an example):

{% for type in types.classes %}
  class {{ type.name }}Mock: {{ type.name }} {
    {% for method in type.methods %}
    override func {{ method.shortName }}({% for parameter in method.parameters %}{% if parameter.argumentLabel %}{{ parameter. argumentLabel }} {% endif %}{{ parameter.parameterName}}: {{ parameter.type }}{% endfor %}) -> {{ method.returnType }} {
      /* record a method call */
    }
  }
{% endfor %}
@krzysztofzablocki
Copy link
Owner

Another good idea, we should avoid using tuple as that might not be accessible via reflection. We'll just create an inner type for the MethodParameter.

I wonder if I should add something to readme/contributing doc about why the code here is more of an objective-c rather than how you'd write real swift code, due to the fact it's using it allows us to leverage the runtime in templates.

@ilyapuchka ilyapuchka self-assigned this Dec 17, 2016
@ilyapuchka ilyapuchka added this to the must-haves for 1.0 milestone Dec 19, 2016
@krzysztofzablocki
Copy link
Owner

#72 closes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants