diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java index c18151cc809..f6ab8262179 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java @@ -45,11 +45,6 @@ import org.eclipse.jdt.internal.ui.util.StringMatcher; public class CallHierarchyCore { - - public static final String PREF_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$ - public static final String PREF_HIDE_TEST_CODE = "PREF_HIDE_TEST_CODE"; //$NON-NLS-1$ - public static final String PREF_SHOW_TEST_CODE_ONLY = "PREF_SHOW_TEST_CODE_ONLY"; //$NON-NLS-1$ - public static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$ public static final String PREF_USE_FILTERS= "PREF_USE_FILTERS"; //$NON-NLS-1$ public static final String PREF_FILTERS_LIST= "PREF_FILTERS_LIST"; //$NON-NLS-1$ @@ -72,15 +67,23 @@ public boolean isSearchUsingImplementorsEnabled() { } public boolean isShowTestCode() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_TEST_CODE_ONLY, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.SHOW_TEST_CODE_ONLY.getId(), null)); } public boolean isShowAll() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_ALL_CODE, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.SHOW_ALL_CODE.getId(), null)); } public boolean isHideTestCode() { - return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null)); + return Boolean.parseBoolean(JavaManipulation.getPreference(CallHierarchyFilterOptions.HIDE_TEST_CODE.getId(), null)); + } + + public String getActiveFilter() { + for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { //must be one of the threee + if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) { + return option.getId(); + } + } return null; } public Collection getImplementingMethods(IMethod method) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java new file mode 100644 index 00000000000..1ae6528708e --- /dev/null +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyFilterOptions.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2024 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Vector Informatik GmbH - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.internal.corext.callhierarchy; + +/** + * These are the filter Options for the Call Hierarchy + * When adding one, modify the getFilterOptions Method in FilterOptions + */ +public enum CallHierarchyFilterOptions { + SHOW_ALL_CODE("PREF_SHOW_ALL_CODE", CallHierarchyMessages.FiltersDialog_ShowAllCode), //$NON-NLS-1$ + HIDE_TEST_CODE("PREF_HIDE_TEST_CODE", CallHierarchyMessages.FiltersDialog_HideTestCode), //$NON-NLS-1$ + SHOW_TEST_CODE_ONLY("PREF_SHOW_TEST_CODE_ONLY", CallHierarchyMessages.FiltersDialog_TestCodeOnly); //$NON-NLS-1$ + + private final String identifyString; + private final String text; + + CallHierarchyFilterOptions(String identifyString, String text) { + this.identifyString = identifyString; + this.text = text; + } + + public String getId() { + return identifyString; + } + + public String getText() { + return text; + } +} diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.java index 66630a36c23..51449fe4030 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.java @@ -25,6 +25,10 @@ private CallHierarchyMessages() { public static String CallerMethodWrapper_taskname; public static String CalleeMethodWrapper_taskname; + public static String FiltersDialog_ShowAllCode; + public static String FiltersDialog_HideTestCode; + public static String FiltersDialog_TestCodeOnly; + static { NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.properties b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.properties index 43db2612fcf..806f062e84f 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.properties +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyMessages.properties @@ -14,3 +14,7 @@ ############################################################################### CallerMethodWrapper_taskname=Finding callers... CalleeMethodWrapper_taskname=Finding callees... + +FiltersDialog_HideTestCode = Hide Test Code +FiltersDialog_ShowAllCode = Show All Code +FiltersDialog_TestCodeOnly = Test Code only diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java index e6ba4815373..2f50b5f7733 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchy.java @@ -18,9 +18,6 @@ package org.eclipse.jdt.internal.corext.callhierarchy; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_FILTERS_LIST; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_HIDE_TEST_CODE; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_ALL_CODE; -import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_FILTERS; import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_IMPLEMENTORS; @@ -36,6 +33,7 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.manipulation.JavaManipulation; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; @@ -60,20 +58,14 @@ public static CallHierarchy getDefault() { return fgInstance; } - public void setShowAll(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_SHOW_ALL_CODE, value); - } + public void setActiveFilter(CallHierarchyFilterOptions filter) { + IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - public void setHideTestCode(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_HIDE_TEST_CODE, value); + for(CallHierarchyFilterOptions option : CallHierarchyFilterOptions.values()) { + settings.setValue(option.getId(), option == filter); + } } - public void setShowTestCode(boolean value) { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - settings.setValue(PREF_SHOW_TEST_CODE_ONLY, value); - } public boolean isSearchUsingImplementorsEnabled() { IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); @@ -139,21 +131,14 @@ public boolean isFilterEnabled() { return settings.getBoolean(PREF_USE_FILTERS); } - public boolean isShowAll() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_SHOW_ALL_CODE); - } - - public boolean isHideTestCode() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_HIDE_TEST_CODE); - } - - public boolean isShowTestCode() { - IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); - return settings.getBoolean(PREF_SHOW_TEST_CODE_ONLY); - } - + public CallHierarchyFilterOptions getActiveFilter() { + for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { + if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) { + return option; + } + } + return null; + } public void setFilterEnabled(boolean filterEnabled) { IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore(); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.java index 882aec6efda..0e2c74d7350 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.java @@ -67,10 +67,6 @@ private CallHierarchyMessages() { public static String ShowFilterDialogAction_text; public static String FiltersDialog_filter; - public static String FiltersDialog_ShowAllCode; - public static String FiltersDialog_HideTestCode; - public static String FiltersDialog_TestCodeOnly; - public static String FiltersDialog_filterOnNames; public static String FiltersDialog_filterOnNamesSubCaption; public static String FiltersDialog_maxCallDepth; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties index d17c5a4adb0..8e12a8e779f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties @@ -63,10 +63,6 @@ SearchInDialog_title= Search In ShowExpandWithConstructorsDialogAction_text=E&xpand with Constructors... ShowFilterDialogAction_text= &Filters... -FiltersDialog_HideTestCode = Hide Test Code -FiltersDialog_ShowAllCode = Show All Code -FiltersDialog_TestCodeOnly = Test Code only - FiltersDialog_filter= Filter Calls FiltersDialog_filterOnNames= &Name filter patterns (matching names will be hidden): FiltersDialog_filterOnNamesSubCaption= Patterns are separated by commas (* = any string, ? = any character) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java index 5c7be2431bb..f832d1796d9 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.jdt.internal.ui.callhierarchy; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -31,6 +34,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy; +import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyFilterOptions; import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; @@ -38,11 +42,10 @@ class FiltersDialog extends StatusDialog { private Label fNamesHelpText; private Button fFilterOnNames; + private static final String KEY_CALL_HIERARCHY_FILTER_OPTION= "callHierarchyFilterOption"; //$NON-NLS-1$ private Text fNames; private Text fMaxCallDepth; - private Button fShowAll; - private Button fHideTest; - private Button fShowTest; + private List