Skip to content

Commit

Permalink
Refactoring Filter from Call Hierarchy #1730
Browse files Browse the repository at this point in the history
Now it works with an enum rather than an array which is much nicer

#1730
  • Loading branch information
jannisCode committed Oct 25, 2024
1 parent c2ceaa2 commit cc0b1e8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -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<IJavaElement> getImplementingMethods(IMethod method) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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
*/
public enum CallHierarchyFilterOptions {
SHOW_ALL_CODE("PREF_SHOW_ALL_CODE", "Show All Code"), //$NON-NLS-1$ //$NON-NLS-2$
HIDE_TEST_CODE("PREF_HIDE_TEST_CODE", "Hide Test Code"), //$NON-NLS-1$ //$NON-NLS-2$
SHOW_TEST_CODE_ONLY("PREF_SHOW_TEST_CODE_ONLY", "Test Code only"); //$NON-NLS-1$ //$NON-NLS-2$

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -60,19 +58,16 @@ 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 setHideTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_HIDE_TEST_CODE, value);
}
public void setActiveFilter(CallHierarchyFilterOptions filter) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();

public void setShowTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_SHOW_TEST_CODE_ONLY, value);
for(CallHierarchyFilterOptions option : CallHierarchyFilterOptions.values()) {
if(option == filter) {
settings.setValue(option.getId(), true);
} else {
settings.setValue(option.getId(), false);
}
}
}

public boolean isSearchUsingImplementorsEnabled() {
Expand Down Expand Up @@ -139,21 +134,13 @@ 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()) { //must be one of the threee
if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) {
return option;
}
} return null;
}

public void setFilterEnabled(boolean filterEnabled) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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;
Expand All @@ -43,9 +44,11 @@ class FiltersDialog extends StatusDialog {
private Button fShowAll;
private Button fHideTest;
private Button fShowTest;
private Button[] buttons = {fShowAll, fHideTest, fShowTest}; //important what comes when

protected FiltersDialog(Shell parentShell) {
super(parentShell);

}

@Override
Expand Down Expand Up @@ -118,30 +121,28 @@ private void createTestCodeArea(Composite parent) {
layout.numColumns= 1;
radioGroup.setLayout(layout);

fShowAll= new Button(radioGroup, SWT.RADIO);
fShowAll.setText(CallHierarchyMessages.FiltersDialog_ShowAllCode);

fHideTest= new Button(radioGroup, SWT.RADIO);
fHideTest.setText(CallHierarchyMessages.FiltersDialog_HideTestCode);
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(radioGroup, SWT.RADIO);
buttons[i].setText(getFilterOptions(buttons[i]).getText());
}

fShowTest= new Button(radioGroup, SWT.RADIO);
fShowTest.setText(CallHierarchyMessages.FiltersDialog_TestCodeOnly);
setSelection();

GridData gridData= new GridData();
gridData.horizontalIndent= 0;
fShowAll.setLayoutData(gridData);
fHideTest.setLayoutData(gridData);
fShowTest.setLayoutData(gridData);

for (Button button : buttons) {
button.setLayoutData(gridData);
}
}

private void setSelection() {
fShowAll.setSelection(CallHierarchy.getDefault().isShowAll());
fHideTest.setSelection(CallHierarchy.getDefault().isHideTestCode());
fShowTest.setSelection(CallHierarchy.getDefault().isShowTestCode());

for (Button button : buttons) {
button.setSelection(CallHierarchy.getDefault().getActiveFilter() == getFilterOptions(button));
}
}


/**
* Creates a check box button with the given parent and text.
*
Expand Down Expand Up @@ -191,9 +192,14 @@ private void updateFilterFromUI() {
CallHierarchy.getDefault().setFilters(fNames.getText());
CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection());

CallHierarchy.getDefault().setShowAll(fShowAll.getSelection());
CallHierarchy.getDefault().setHideTestCode(fHideTest.getSelection());
CallHierarchy.getDefault().setShowTestCode(fShowTest.getSelection());
CallHierarchyFilterOptions activeFilter = null;
for (Button button : buttons) {
if(button.getSelection()) {
activeFilter = getFilterOptions(button);
}
}

CallHierarchy.getDefault().setActiveFilter(activeFilter);
}

/**
Expand All @@ -205,10 +211,19 @@ private void updateUIFromFilter() {
fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled());

setSelection();

updateEnabledState();
}

private CallHierarchyFilterOptions getFilterOptions(Button B) {
if(B == buttons[0]) {
return CallHierarchyFilterOptions.SHOW_ALL_CODE;
} else if (B == buttons[1]) {
return CallHierarchyFilterOptions.HIDE_TEST_CODE;
} else {
return CallHierarchyFilterOptions.SHOW_TEST_CODE_ONLY;
}
}

/**
* Updates the filter from the UI state.
Expand Down

0 comments on commit cc0b1e8

Please sign in to comment.