Comments (7)
that could be useful, the way I'd approach it would be to add tests to parser that has default value and then see whether sourcekitten feeds as those values, if not then you'd need to write manual parsing similar to how we are parsing annotations or typealiases
from sourcery.
I first wanted to suggest to support method parameters default values for the sake of the consistency, but than I thought, how exactly that can be used in templates?
Also default property values are not required to be simple literals, so it can be for example a method call or even a complex closure call, how that can be used in a template?
from sourcery.
yeah I'm not sure about the use-case here as well, @txaiwieser what were you thinking about?
from sourcery.
If we don't hear any reasonable use-case this week then we should probably close this
from sourcery.
My use case is related to the one I posted in issue #210. I start Sourcery on a certain class. For certain methods I find in that class I generate new classes. Each class has a property for every parameter of the orginal method. So, e.g., I find a method
func drawButton(showBorder: Bool = true, borderColor: UIColor = .red)
I generate
class MyButton : UIButton { showBorder : Bool, borderColor: UIColor ...}
and, naturally, I would like to reuse the original default parameter, e.g.,
class MyButton : UIButton { showBorder : Bool = true, borderColor: UIColor = .red ...}
from sourcery.
By now I created a workaround by reparsing Sourcery's Method.name
and grabbing the information from there. But that really feels like unnecessary overhead.
from sourcery.
To comment on ilyapuchka's comment above: I think my usecase would be just the same if the default values would be more complicated like complete closures. But my workaround mentioned above would stop to function. I know by construction of the code I scan with Sourcery that there will be no complex expressions. But in the general case you would have to expose the whole Expression class of the AST to do this, I realize from that comment. So, here are a few remarks with respect to that:
- you could just expose the default value as an unstructured string, as - I think - you do in other places as well
- if you expose the complete expression structure you could also greatly extend Sourcery in other places. E.g., you could give access to the method bodies as well. (Which would also provide what is needed for issue #210)
from sourcery.
Related Issues (20)
- Malformed generated mocks HOT 1
- Missing bin folder with 2.1.3 HOT 5
- Missing bin folder with 2.1.4 HOT 5
- Homebrew does not include latest version (2.1.4) HOT 3
- The platform of the target `MyApp` (iOS 16.0) is not compatible with `Sourcery (2.1.4)`, which does not support `iOS` HOT 18
- AutoMockable stencil does not support inout parameters HOT 3
- Generated Automockable compilation issue due to malformed generated variable name HOT 2
- Generated AutoMockable compilation issue due to variadic parameters HOT 11
- [BUG] Generated AutoMockable compilation issues HOT 1
- Windows Support
- Sourcery doesn't properly work when using protocols with primary associated types HOT 2
- Add whitespace trimming configuration for Stencil templates
- [QUESTION] Thread-Safe Mocks HOT 1
- [Bug] Failed to resolve dependencies (SPM issue) HOT 5
- Watch mode only watches sources from last configuration file when passing multiple paths to configuration files using `--config` command line options
- Getting generic requirements from methods HOT 1
- Possible to generate asset catalog constants? HOT 1
- Detecting if a variable is an Enum works if enum is declared in the file but doesn't otherwise. HOT 4
- AutoMockable does not generate valid Swift code during method generic requirement parsing HOT 2
- Swift macros and method bodies HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sourcery.