Flip Setter Call Intention Action in Maia

Konstantin Bulenkov

Two-way synchronization between different data models is a common routine task and often developers are stuck with manual copying of data from one model to another for many reasons: model complexity, impossibility to create a simple binding, etc. For example, we have a settings model and an UI to configure it. Traditional approach suggests implementing two methods:

  • Initializing UI from settings
  • Persisting changes from UI to settings

Next, we need to implement a method (say, saveSettings), similar to initUI where UI changes are persisted to the ProxySetting object — quite boring, isn’t it?

How to do it quicker than just writing from scratch? In Maia we’ll do it twice as easy: copy the body of initUI method to saveSettings, select the just pasted code and press Alt+Enter.
Then, select Flip Setter Call intention action and enjoy.

Comments below can no longer be edited.

4 Responses to Flip Setter Call Intention Action in Maia

  1. Jesper Thuun-Petersen says:

    June 2, 2009

    In what build is this supposed to be implemented? I’m using 10322, and I’m not getting this intention.

  2. Stephen Friedrich says:

    June 3, 2009

    Is there a way to invoke the intention on a bunch of setters/getters at once?
    Maybe select some statements, then press alt-enter.

    Or “Fix all for current method” which may work for the “saveSettings” scenario – but then again maybe not: There’s always a chance of there being some additional accessor calls in the method that are unrelated to the settings per se.

  3. Konstantin Bulenkov says:

    June 3, 2009

    Sure. You can select a huge code block and call “Flip Setter Call”. It will look for method calls like:
    after that it checks that object1 and object2 have appropriate getter and setter with the same types, and finally swaps method calls

    And, of course, it works on single method call (without any selection)

  4. Konstantin Bulenkov says:

    June 3, 2009

    Jesper, this intention is available in build 10332.


Subscribe for updates