Skip to content

Commit

Permalink
New Option in the preferences where one can change if one parameter
Browse files Browse the repository at this point in the history
should be displayed when using the code minings
  • Loading branch information
jannisCode committed Dec 15, 2024
1 parent cedc392 commit cd6b200
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,15 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List<?> arg
}

private boolean skipParameterNamesCodeMinings(IMethod method) {
return method.getNumberOfParameters() <= 1;
boolean showNamesOfSingleArguments= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG);
return !showNamesOfSingleArguments && method.getNumberOfParameters() == 1
|| method.getNumberOfParameters() == 0;
}

private boolean skipParameterNamesCodeMinings(IMethodBinding methodBinding) {
return methodBinding.getParameterNames().length <= 1;
boolean showNamesOfSingleArguments= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG);
return !showNamesOfSingleArguments && methodBinding.getParameterNames().length == 1
|| methodBinding.getParameterNames().length == 0;
}

private boolean skipParameterNamesCodeMinings(IMethod method, String[] parameterNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class JavaEditorCodeMiningConfigurationBlock extends OptionsConfiguration
private static final Key PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES= getJDTUIKey(
PreferenceConstants.EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES);

private static final Key PREF_SHOW_ONE_PARAMETER= getJDTUIKey(
PreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG);

private static final String SETTINGS_SECTION_NAME= "JavaEditorCodeMiningConfigurationBlock"; //$NON-NLS-1$

private static final String[] TRUE_FALSE= new String[] { "true", "false" }; //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -101,7 +104,7 @@ public JavaEditorCodeMiningConfigurationBlock(IStatusChangeListener context,
public static Key[] getAllKeys() {
return new Key[] { PREF_CODEMINING_ENABLED, PREF_SHOW_CODEMINING_AT_LEAST_ONE, PREF_SHOW_REFERENCES, PREF_SHOW_REFERENCES_ON_TYPES, PREF_SHOW_REFERENCES_ON_FIELDS,
PREF_SHOW_REFERENCES_ON_METHODS,
PREF_SHOW_IMPLEMENTATIONS, PREF_SHOW_PARAMETER_NAMES, PREF_IGNORE_INEXACT_MATCHES, PREF_FILTER_IMPLIED_PARAMETER_NAMES, PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES };
PREF_SHOW_IMPLEMENTATIONS, PREF_SHOW_PARAMETER_NAMES, PREF_IGNORE_INEXACT_MATCHES, PREF_FILTER_IMPLIED_PARAMETER_NAMES, PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES, PREF_SHOW_ONE_PARAMETER };
}

@Override
Expand Down Expand Up @@ -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,
PreferencesMessages.JavaEditorCodeMiningShowOneParameter_label,
PREF_SHOW_ONE_PARAMETER, TRUE_FALSE, extraIndent, section);
}

private void updateEnableStates() {
Expand All @@ -244,8 +250,11 @@ private void updateEnableStates() {
// Show implementations checkboxes
getCheckBox(PREF_SHOW_IMPLEMENTATIONS).getSelection();
boolean showParameterNames= getCheckBox(PREF_SHOW_PARAMETER_NAMES).getSelection();

getCheckBox(PREF_FILTER_IMPLIED_PARAMETER_NAMES).setEnabled(showParameterNames);
getCheckBox(PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES).setEnabled(showParameterNames);
getCheckBox(PREF_SHOW_ONE_PARAMETER).setEnabled(showParameterNames);

} else {
atLeastOneCheckBox.setEnabled(false);
ignoreInexactReferenceMatches.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ private PreferencesMessages() {
public static String JavaEditorCodeMiningConfigurationBlock_showParameterNames_label;
public static String JavaEditorCodeMiningConfigurationBlock_filterImpliedParameterNames_label;
public static String JavaEditorCodeMiningConfigurationBlock_defaultFilterForParameterNames_label;
public static String JavaEditorCodeMiningShowOneParameter_label;

public static String JavaLaunchingConfigurationBlock_application_name_fully_qualified_label;
public static String JavaLaunchingConfigurationBlock_applet_name_fully_qualified_label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ JavaEditorCodeMiningConfigurationBlock_showImplementations_label=Show &implement
JavaEditorCodeMiningConfigurationBlock_showParameterNames_label=Show method &parameter names
JavaEditorCodeMiningConfigurationBlock_defaultFilterForParameterNames_label=&Default filter for some specified methods and method parameter names (e.g. compare())
JavaEditorCodeMiningConfigurationBlock_filterImpliedParameterNames_label=Filter parameter &names that are implied by parameter
JavaEditorCodeMiningShowOneParameter_label=Show code minnigs when method has one parameter

#Launching preferences
JavaLaunchingConfigurationBlock_application_name_fully_qualified_label=Use fully qualified name for new Java Application
Expand Down
12 changes: 12 additions & 0 deletions org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3939,6 +3939,17 @@ private PreferenceConstants() {
*/
public static final String EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES = "java.codemining.defalt.filter.for.parameterNames"; //$NON-NLS-1$

/**
* A named preference that stores the value if a method with one parameter should be shown with code minings or if the code minings are
* only shown for 2+ parameters
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.34
*/
public static final String EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG = "java.codemining.show.one.parameter"; //$NON-NLS-1$

/**
* A named preference that stores the value for "Filter matching parameter names" when showing parameter names
* in codemining. This will filter out parameter names when the passed parameter name implies the parameter name.
Expand Down Expand Up @@ -4374,6 +4385,7 @@ public static void initializeDefaultValues(IPreferenceStore store) {
store.setDefault(EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAMES, false);
store.setDefault(EDITOR_JAVA_CODEMINING_FILTER_IMPLIED_PARAMETER_NAMES, true);
store.setDefault(EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES, true);
store.setDefault(EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAME_SINGLE_ARG, true);

// Javadoc hover & view
JavaElementLinks.initDefaultPreferences(store);
Expand Down

0 comments on commit cd6b200

Please sign in to comment.