Giter VIP home page Giter VIP logo

Comments (7)

krzysztofzablocki avatar krzysztofzablocki commented on May 22, 2024

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.

ilyapuchka avatar ilyapuchka commented on May 22, 2024

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.

krzysztofzablocki avatar krzysztofzablocki commented on May 22, 2024

yeah I'm not sure about the use-case here as well, @txaiwieser what were you thinking about?

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 22, 2024

If we don't hear any reasonable use-case this week then we should probably close this

from sourcery.

brassel avatar brassel commented on May 22, 2024

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.

brassel avatar brassel commented on May 22, 2024

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.

brassel avatar brassel commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.