-
Notifications
You must be signed in to change notification settings - Fork 93
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
Provide name for parameters in 1-arg methods when using code minings #1813
base: master
Are you sure you want to change the base?
Conversation
cba8100
to
22a305c
Compare
This pull request changes some projects for the first time in this development cycle.
An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patch
Further information are available in Common Build Issues - Missing version increments. |
Back then when I developed this, I found those names useless for single-arg methods. Parameter names are convenient to identify what an argument is intended too; when there is a single arg, the method name is most often sufficient to sort out what's going to happen with the given arg. |
Not always, think of constructors I find having the names for methods with 1 argument is useful and also more consistent with the rest of the behavior. Thank you @jannisCode for this suggestion! |
@@ -165,7 +165,7 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg | |||
} | |||
|
|||
private boolean skipParameterNamesCodeMinings(IMethod method) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this method altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated: agreed on adding a parameter which makes this method necessary.
The relevant case to check is when you read code. Even if there are several possible constructors, it's not likely to me that having the parameter name will help readability, eg
Consistency is less important that being useful and lean ;) I would strongly hate having the parameter names in 1 method args, it would just add noise to me in the very vast majority of use cases, and useless noise hurts readability more than it helps. |
a4a86ae
to
7bc4aef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also provide an option in preferences to skip those.
Consistency is important so that users don't end up reporting "bugs" that are not bugs and simply some "other arbitrary behavior". What I meant by that is not that the 1-arg methods don't show the name of the argument but that this behavior is not the same across the board: records don't exhibit this behavior.
I'd rather not have such an option, I think the configuration is complex enough. But there are maybe some other opinions on that. Does anyone else (other than Mickael and me) reading this PR care to vote? |
That is more a bug to me, to fix separately.
Please make sure you actually try to work with this proposal on various classes before considering it for a merge. My arbitrary choice was based on actual usage of the feature while it was being implemented. My impression based on that experience is that in the vast majority of cases, single arg name is noise and hurts readability. |
7bc4aef
to
3462610
Compare
@@ -165,7 +165,7 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg | |||
} | |||
|
|||
private boolean skipParameterNamesCodeMinings(IMethod method) { | |||
return method.getNumberOfParameters() <= 1; | |||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a preference here
return false; | |
return PreferenceConstants.getPreferenceStore().getBoolean(PreferencesConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG) && method.getNumberOfParameters() == 1) || method.getNumberOfParameters() == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather the opposite:
boolean showNamesOfSingleArguments= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG);
return !showNamesOfSingleArguments && method.getNumberOfParameters() == 1
|| method.getNumberOfParameters() == 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're into renaming with opposite meanings, I suggest renaming (and reversing conditions) from skipParameterNamesCodeMinings
to showParameterNamesCodeMinings() { return number > 1 || PreferenceConstants.getPreferenceStore().getBoolean(PreferencesConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG))
. That should make things simpler to understand and maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3462610
to
49f2c2d
Compare
Thanks. That proposal is good to me! |
@@ -165,7 +165,13 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg | |||
} | |||
|
|||
private boolean skipParameterNamesCodeMinings(IMethod method) { | |||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | |||
boolean showFromOneParameter = store.getBoolean(PreferenceConstants.EDITOR_JAVA_SHOW_ONE_PARAMETER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really want to read from the store for each method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in line 179 another preference store access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be ok to leave that to another PR so that this one doesn't blow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure.
9472b4d
to
8dab19f
Compare
should be displayed when using the code minings
8dab19f
to
e301be1
Compare
@@ -227,6 +230,9 @@ private void createGeneralSection(int nColumns, Composite parent) { | |||
PreferencesMessages.JavaEditorCodeMiningConfigurationBlock_defaultFilterForParameterNames_label, | |||
PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES, TRUE_FALSE, extraIndent, section); | |||
|
|||
fFilteredPrefTree.addCheckBox(inner, | |||
"Show one Parameter", //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest something more descriptive, like:
"Show one Parameter", //$NON-NLS-1$ | |
"Show parameter names in methods with only 1 parameter", //$NON-NLS-1$ |
@@ -165,7 +165,7 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg | |||
} | |||
|
|||
private boolean skipParameterNamesCodeMinings(IMethod method) { | |||
return method.getNumberOfParameters() <= 1; | |||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -165,7 +165,13 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg | |||
} | |||
|
|||
private boolean skipParameterNamesCodeMinings(IMethod method) { | |||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | |||
boolean showFromOneParameter = store.getBoolean(PreferenceConstants.EDITOR_JAVA_SHOW_ONE_PARAMETER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be ok to leave that to another PR so that this one doesn't blow up?
Yes, sure. |
What it does
This PR will enable the possability to show code minings in all Methods, also those who expect just one argument.
Before:
When a method only had one parameter, it was eligible for code minings, except if it was from a record class. As you can see in the screenshot and snippet, the code minings are shown for car but not for Cat.
@mickaelistria Is there a reason, why it always checks if there are more than one parameter? Because if not, I think it would be beneficial if the code minings are always shown.
After this change
Code minings are always shown no matter how many Parameters there are.
Author checklist