From cd6b200c7e5511d69f649018521ae83e0f65856c Mon Sep 17 00:00:00 2001 From: jannisCode Date: Tue, 26 Nov 2024 15:04:19 +0100 Subject: [PATCH] New Option in the preferences where one can change if one parameter should be displayed when using the code minings --- .../codemining/CalleeJavaMethodParameterVisitor.java | 8 ++++++-- .../JavaEditorCodeMiningConfigurationBlock.java | 11 ++++++++++- .../internal/ui/preferences/PreferencesMessages.java | 1 + .../ui/preferences/PreferencesMessages.properties | 1 + .../ui/org/eclipse/jdt/ui/PreferenceConstants.java | 12 ++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/CalleeJavaMethodParameterVisitor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/CalleeJavaMethodParameterVisitor.java index 7f3adecb504..9a38f907b0f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/CalleeJavaMethodParameterVisitor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/CalleeJavaMethodParameterVisitor.java @@ -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) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorCodeMiningConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorCodeMiningConfigurationBlock.java index 06c4ebfd659..acd7b42ebac 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorCodeMiningConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorCodeMiningConfigurationBlock.java @@ -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$ @@ -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 @@ -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() { @@ -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); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java index d42a3534863..a1886d94f9c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java @@ -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; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties index 9964119d413..1b388603f34 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties @@ -1038,6 +1038,7 @@ JavaEditorCodeMiningConfigurationBlock_showImplementations_label=Show &implement JavaEditorCodeMiningConfigurationBlock_showParameterNames_label=Show method ¶meter 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 diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java index 5b2fd619e15..8c32e3d7bf7 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java @@ -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 + *

+ * Value is of type Boolean. + *

+ * + * @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. @@ -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);