[Rearranger 2.1] bug with Setters/Getters

First, excellent Plugin Dave. JetBrains should pull this functionality into
the base product. Including the live rearranger functionality, which really
belongs in the Structure view. I imagine a plugin just can't do that.

Now the bug:

From the WiKi:
Keep Getters/Setters Together - Setting this option will cause setters to
appear immediately below getters, wherever the rearrangement may place them.
If sorted by name, the property name will be used (not the getter method
name).

This does not happen in the current release (2.1).

My Default Getter/Setter Definitions are set as follows:
Getter definition
Method body: Ignore body
Method name: Has "get/is/has" prefix
Setter definition
Method body: Ignore body
Method name: Has "set" prefix

Thanks,
Tim


4 comments

Thanks, Tim -- glad it is of use to you.

Yes, I don't think a plugin can hook their Structure view and add functionality; but one could be written to replace it, and map ctrl-F12 keystroke to the plugin -- so it could be made to look like it.

One thing that would be helpful is to turn on "confirm before rearranging" on the General options pane, then run the rearrangement. A dialog pops up, containing a tree which shows the proposed rearrangement. Turn on "Show Rules" and see where your setter method appears. If it was determined to be a setter, it should appear with the getter. If for some reason the "setter determination" logic is wrong, the method will appear elsewhere, perhaps under a rule like "all methods."

If this doesn't help figure out the problem, there are a few more steps to take:

1) make sure that the actual rule's definition of G/S is the same as the default definition. The way it works now is lame. When a rule is created I copy the default definition into the rule. If you change the default afterwards, the rule definition does not change; it keeps the former settings. What really should happen is that rules should always use the default unless explicitly overridden.

2) send me your source and configuration and I'll put them in the test suite. I have tests for "Keep G/S together" now, so it definitely works under some circumstances. (Just not yours! :)

You can email sources to davek ]]> wrq.com.

-Dave

0

Thanks for the tips.

After looking at the confirmation window, I found that I had a bit of a
misconception. Order matters. I had a rule for all "Other" methods that
was in the list prior to my rule for setters and getters. So, by the time
the setter/getter rule was reached, the methods had already been handled by
a previous rule, so it didn't find any. I simply filtered out
setters/getters from the "Other" methods rule and it now works. Thanks!

However, I found a new bug. I have three methods one of which is most
likely poorly named: setProductOther(String), String getProductOther(), and
boolean isProductOther(). With "keep setters/getters together" selected, it
duplicates the setProductOther(String) method, once after each getter. This
is obviously not correct. Perhaps there needs to be a check to ensure that
the parameter type in the setter matches the return type of the getter when
pairing them up.

Thanks again,

Tim

"Dave Kriewall" <no_mail@jetbrains.com> wrote in message
news:25913726.1078733012315.JavaMail.itn@is.intellij.net...

Thanks, Tim -- glad it is of use to you.

>

Yes, I don't think a plugin can hook their Structure view and add

functionality; but one could be written to replace it, and map ctrl-F12
keystroke to the plugin -- so it could be made to look like it.
>

One thing that would be helpful is to turn on "confirm before rearranging"

on the General options pane, then run the rearrangement. A dialog pops up,
containing a tree which shows the proposed rearrangement. Turn on "Show
Rules" and see where your setter method appears. If it was determined to be
a setter, it should appear with the getter. If for some reason the "setter
determination" logic is wrong, the method will appear elsewhere, perhaps
under a rule like "all methods."
>

If this doesn't help figure out the problem, there are a few more steps to

take:
>

1) make sure that the actual rule's definition of G/S is the same as the

default definition. The way it works now is lame. When a rule is created I
copy the default definition into the rule. If you change the default
afterwards, the rule definition does not change; it keeps the former
settings. What really should happen is that rules should always use the
default unless explicitly overridden.
>

2) send me your source and configuration and I'll put them in the test

suite. I have tests for "Keep G/S together" now, so it definitely works
under some circumstances. (Just not yours! :)
>

You can email sources to davek <at> wrq.com.

>

-Dave



0

Good find! Not good to duplicate methods... :)

I'll fix that right away.

0

Tim,

Give version 2.7 a try. Your "get/is/set" methods should be together and the setter not duplicated.

Sorry it took so long.

-Dave

0

Please sign in to leave a comment.