diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF index 896f597d2eb..4672a97a4c8 100644 --- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true -Bundle-Version: 3.32.200.qualifier +Bundle-Version: 3.33.0.qualifier Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName diff --git a/org.eclipse.jdt.ui/pom.xml b/org.eclipse.jdt.ui/pom.xml index 9f0d94e24da..251ed3163cc 100644 --- a/org.eclipse.jdt.ui/pom.xml +++ b/org.eclipse.jdt.ui/pom.xml @@ -18,7 +18,7 @@ org.eclipse.jdt org.eclipse.jdt.ui - 3.32.200-SNAPSHOT + 3.33.0-SNAPSHOT eclipse-plugin 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 db3b400c353..11f14a89ef0 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2023 Angelo Zerr and others. + * Copyright (c) 2017, 2024 Angelo Zerr and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,11 @@ import java.util.List; +import org.eclipse.jface.preference.IPreferenceStore; + +import org.eclipse.jface.text.codemining.ICodeMining; +import org.eclipse.jface.text.codemining.ICodeMiningProvider; + import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -25,10 +30,12 @@ import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.SuperConstructorInvocation; + import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor; + +import org.eclipse.jdt.ui.PreferenceConstants; + import org.eclipse.jdt.internal.ui.JavaPlugin; -import org.eclipse.jface.text.codemining.ICodeMining; -import org.eclipse.jface.text.codemining.ICodeMiningProvider; public class CalleeJavaMethodParameterVisitor extends HierarchicalASTVisitor { @@ -147,9 +154,14 @@ private boolean skipParameterNameCodeMining(String[] parameterNames, List> arg if (parameterNames.length < parameterIndex) { return true; } + IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); + boolean filter= store.getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_FILTER_IMPLIED_PARAMETER_NAMES); + if (!filter) { + return false; + } String parameterName= parameterNames[parameterIndex].toLowerCase(); String expression= arguments.get(parameterIndex).toString().toLowerCase(); - return expression.contains(parameterName); + return parameterName.length() > 3 && expression.contains(parameterName) || parameterName.equals(expression); } private boolean skipParameterNamesCodeMinings(IMethod method) { @@ -157,6 +169,11 @@ private boolean skipParameterNamesCodeMinings(IMethod method) { } private boolean skipParameterNamesCodeMinings(IMethod method, String[] parameterNames) { + IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); + boolean filter= store.getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES); + if (!filter) { + return false; + } // add default filtering to skip parameter names (based on original plug-in defaults) String typeName= method.getDeclaringType().getTypeQualifiedName(); if (typeName.equals("Math")) { //$NON-NLS-1$ 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 03a9351e240..06c4ebfd659 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 @@ -75,6 +75,12 @@ public class JavaEditorCodeMiningConfigurationBlock extends OptionsConfiguration private static final Key PREF_SHOW_PARAMETER_NAMES= getJDTUIKey( PreferenceConstants.EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAMES); + private static final Key PREF_FILTER_IMPLIED_PARAMETER_NAMES= getJDTUIKey( + PreferenceConstants.EDITOR_JAVA_CODEMINING_FILTER_IMPLIED_PARAMETER_NAMES); + + private static final Key PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES= getJDTUIKey( + PreferenceConstants.EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES); + 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$ @@ -95,7 +101,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_SHOW_IMPLEMENTATIONS, PREF_SHOW_PARAMETER_NAMES, PREF_IGNORE_INEXACT_MATCHES, PREF_FILTER_IMPLIED_PARAMETER_NAMES, PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES }; } @Override @@ -183,6 +189,7 @@ private void createGeneralSection(int nColumns, Composite parent) { Composite inner= createInnerComposite(excomposite, nColumns, parent.getFont()); + // - Show references PreferenceTreeNode showReferences= fFilteredPrefTree.addCheckBox(inner, PreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showReferences_label, PREF_SHOW_REFERENCES, @@ -210,6 +217,16 @@ private void createGeneralSection(int nColumns, Composite parent) { PreferencesMessages.JavaEditorCodeMiningConfigurationBlock_showParameterNames_label, PREF_SHOW_PARAMETER_NAMES, TRUE_FALSE, defaultIndent, section); + // - Filter implied parameter names + fFilteredPrefTree.addCheckBox(inner, + PreferencesMessages.JavaEditorCodeMiningConfigurationBlock_filterImpliedParameterNames_label, + PREF_FILTER_IMPLIED_PARAMETER_NAMES, TRUE_FALSE, extraIndent, section); + + // - Filter known method parameter names + fFilteredPrefTree.addCheckBox(inner, + PreferencesMessages.JavaEditorCodeMiningConfigurationBlock_defaultFilterForParameterNames_label, + PREF_DEFAULT_FILTER_FOR_PARAMETER_NAMES, TRUE_FALSE, extraIndent, section); + } private void updateEnableStates() { @@ -226,7 +243,9 @@ private void updateEnableStates() { getCheckBox(PREF_SHOW_REFERENCES_ON_METHODS).setEnabled(showReferences); // Show implementations checkboxes getCheckBox(PREF_SHOW_IMPLEMENTATIONS).getSelection(); - getCheckBox(PREF_SHOW_PARAMETER_NAMES).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); } else { atLeastOneCheckBox.setEnabled(false); ignoreInexactReferenceMatches.setEnabled(false); @@ -248,7 +267,8 @@ protected void validateSettings(Key changedKey, String oldValue, String newValue return; } if (changedKey != null) { - if (PREF_CODEMINING_ENABLED.equals(changedKey) || PREF_SHOW_REFERENCES.equals(changedKey) || PREF_SHOW_IMPLEMENTATIONS.equals(changedKey)) { + if (PREF_CODEMINING_ENABLED.equals(changedKey) || PREF_SHOW_REFERENCES.equals(changedKey) || PREF_SHOW_IMPLEMENTATIONS.equals(changedKey) + || PREF_SHOW_PARAMETER_NAMES.equals(changedKey)) { updateEnableStates(); } } else { 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 c8d1cfe0c78..4e9f8a1d863 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 @@ -934,6 +934,8 @@ private PreferencesMessages() { public static String JavaEditorCodeMiningConfigurationBlock_showReferences_onMethods_label; public static String JavaEditorCodeMiningConfigurationBlock_showImplementations_label; public static String JavaEditorCodeMiningConfigurationBlock_showParameterNames_label; + public static String JavaEditorCodeMiningConfigurationBlock_filterImpliedParameterNames_label; + public static String JavaEditorCodeMiningConfigurationBlock_defaultFilterForParameterNames_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 3ba3c5805cd..89b533e38ab 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 @@ -1060,6 +1060,8 @@ JavaEditorCodeMiningConfigurationBlock_showReferences_onFields_label=&Fields JavaEditorCodeMiningConfigurationBlock_showReferences_onMethods_label=&Methods JavaEditorCodeMiningConfigurationBlock_showImplementations_label=Show &implementations 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 #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 171d6868e83..5b2fd619e15 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 @@ -3926,6 +3926,31 @@ private PreferenceConstants() { */ public static final String EDITOR_JAVA_CODEMINING_SHOW_PARAMETER_NAMES = "java.codemining.parameterNames"; //$NON-NLS-1$ + /** + * A named preference that stores the value for "Default Filter for code mining parameter names" when showing parameter names + * in codemining. This will filter out parameter names for methods in java.lang.Math, org.slf4j.Logging, + * Immutable*.of() methods, Arrays.asList(), and various standard methods such as set() methods, setProperties() + * methods, compare() methods, parameter names that start with "begin", "end", "first", "last", to name a few. + * + * Value is of type Boolean. + * + * + * @since 3.33 + */ + 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 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. + * For example, if the parameter name is "format" and the parameter passed is "stringFormat". + * + * Value is of type Boolean. + * + * + * @since 3.33 + */ + public static final String EDITOR_JAVA_CODEMINING_FILTER_IMPLIED_PARAMETER_NAMES = "java.codemining.filter.implied.parameterNames"; //$NON-NLS-1$ + /** * A named preference that stores the maximum number of chain completions * to be proposed at one time. @@ -4347,6 +4372,8 @@ public static void initializeDefaultValues(IPreferenceStore store) { store.setDefault(EDITOR_JAVA_CODEMINING_SHOW_REFERENCES_ON_METHODS, false); store.setDefault(EDITOR_JAVA_CODEMINING_SHOW_IMPLEMENTATIONS, false); 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); // Javadoc hover & view JavaElementLinks.initDefaultPreferences(store);
+ * Value is of type Boolean. + *
Boolean