Skip to content

Commit

Permalink
Updated the filter feature in the call hierarchy
Browse files Browse the repository at this point in the history
changed the feature from only one selectable option to three radio
buttons which are more understandable and provide more functionality.
  • Loading branch information
jannisCode authored and jukzi committed Oct 9, 2024
1 parent 260fa25 commit 3948ff8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@

public class CallHierarchyCore {

private static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$
private static final String PREF_USE_FILTERS= "PREF_USE_FILTERS"; //$NON-NLS-1$
private static final String PREF_FILTERS_LIST= "PREF_FILTERS_LIST"; //$NON-NLS-1$
private static final String PREF_FILTER_TESTCODE= "PREF_FILTER_TESTCODE"; //$NON-NLS-1$
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$

private static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$
private static final String PREF_USE_FILTERS= "PREF_USE_FILTERS"; //$NON-NLS-1$
private static final String PREF_FILTERS_LIST= "PREF_FILTERS_LIST"; //$NON-NLS-1$

private String defaultIgnoreFilters= "java.*,javax.*"; //$NON-NLS-1$

Expand All @@ -69,10 +72,18 @@ public boolean isSearchUsingImplementorsEnabled() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_USE_IMPLEMENTORS, null));
}

public boolean isFilterTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_FILTER_TESTCODE, null));
public boolean isShowTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_TEST_CODE_ONLY, null));
}

public boolean isShowAll() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_ALL_CODE, null));
}

public boolean isHideTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null));
}

public Collection<IJavaElement> getImplementingMethods(IMethod method) {
if (isSearchUsingImplementorsEnabled()) {
IJavaElement[] result= Implementors.getInstance().searchForImplementors(new IJavaElement[] {
Expand Down Expand Up @@ -196,10 +207,8 @@ public boolean isIgnored(String fullyQualifiedName) {
}
}
}

return false;
}

public boolean isFilterEnabled() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_USE_FILTERS, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ protected Map<String, MethodCall> createCalledMethodsData() {
* Method isIgnored.
* @return boolean
*/
private boolean isIgnored(IMember enclosingElement) {
String fullyQualifiedName = getTypeOfElement(enclosingElement)
.getFullyQualifiedName();

if (CallHierarchyCore.getDefault().isFilterTestCode()) {
IClasspathEntry classpathEntry= determineClassPathEntry(enclosingElement);
if (classpathEntry != null && classpathEntry.isTest()) {
return true;
}
private boolean isIgnored(IMember enclosingElement) {
String fullyQualifiedName= getTypeOfElement(enclosingElement).getFullyQualifiedName();

if (CallHierarchyCore.getDefault().isShowAll()) {
return false;
}
IClasspathEntry classpathEntry= determineClassPathEntry(enclosingElement);

return CallHierarchyCore.getDefault().isIgnored(fullyQualifiedName);
}
if (classpathEntry != null) {
boolean isTest= classpathEntry.isTest();
return CallHierarchyCore.getDefault().isHideTestCode() && isTest
|| CallHierarchyCore.getDefault().isShowTestCode() && !isTest;
}
return CallHierarchyCore.getDefault().isIgnored(fullyQualifiedName);
}

private static IClasspathEntry determineClassPathEntry(Object element) {
if (element instanceof IJavaElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.eclipse.jdt.internal.ui.util.StringMatcher;

public class CallHierarchy {
private static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$

private static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$
private static final String PREF_USE_FILTERS = "PREF_USE_FILTERS"; //$NON-NLS-1$
private static final String PREF_FILTERS_LIST = "PREF_FILTERS_LIST"; //$NON-NLS-1$
private static final String PREF_FILTER_TESTCODE= "PREF_FILTER_TESTCODE"; //$NON-NLS-1$

private static CallHierarchy fgInstance;
private CallHierarchyCore fgCallHierarchyCore;
Expand All @@ -53,35 +53,35 @@ public static CallHierarchy getDefault() {
if (fgInstance == null) {
fgInstance = new CallHierarchy();
}

return fgInstance;
}

public boolean isSearchUsingImplementorsEnabled() {
public void setShowAll(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();

return settings.getBoolean(PREF_USE_IMPLEMENTORS);
settings.setValue(CallHierarchyCore.PREF_SHOW_ALL_CODE, value);
}

public static void setSearchUsingImplementorsEnabled(boolean enabled) {
public void setHideTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();

settings.setValue(PREF_USE_IMPLEMENTORS, enabled);
settings.setValue(CallHierarchyCore.PREF_HIDE_TEST_CODE, value);
}

public boolean isFilterTestCode() {
public void setShowTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY, value);
}

return settings.getBoolean(PREF_FILTER_TESTCODE);
public boolean isSearchUsingImplementorsEnabled() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(PREF_USE_IMPLEMENTORS);
}

public void setFilterTestCode(boolean enabled) {
public static void setSearchUsingImplementorsEnabled(boolean enabled) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();

settings.setValue(PREF_FILTER_TESTCODE, enabled);
settings.setValue(PREF_USE_IMPLEMENTORS, enabled);
}


public Collection<IJavaElement> getImplementingMethods(IMethod method) {
return fgCallHierarchyCore.getImplementingMethods(method);
}
Expand Down Expand Up @@ -135,6 +135,22 @@ public boolean isFilterEnabled() {
return settings.getBoolean(PREF_USE_FILTERS);
}

public boolean isShowAll() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(CallHierarchyCore.PREF_SHOW_ALL_CODE);
}

public boolean isHideTestCode() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(CallHierarchyCore.PREF_HIDE_TEST_CODE);
}

public boolean isShowTestCode() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY);
}


public void setFilterEnabled(boolean filterEnabled) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_USE_FILTERS, filterEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private CallHierarchyMessages() {
public static String ShowExpandWithConstructorsDialogAction_text;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ ShowSearchInDialogAction_text= Search &In...
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class FiltersDialog extends StatusDialog {
private Button fFilterOnNames;
private Text fNames;
private Text fMaxCallDepth;
private Button fFilterTestCode;

private Button fShowAll;
private Button fHideTest;
private Button fShowTest;

protected FiltersDialog(Shell parentShell) {
super(parentShell);
Expand Down Expand Up @@ -112,10 +113,34 @@ private void createNamesArea(Composite parent) {
}

private void createTestCodeArea(Composite parent) {
fFilterTestCode = createCheckbox(parent,
CallHierarchyMessages.FiltersDialog_filterTestCode, true);
}
Composite radioGroup= new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout();
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);

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);
}

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

}

/**
* Creates a check box button with the given parent and text.
Expand Down Expand Up @@ -157,27 +182,33 @@ private void updateEnabledState() {
}

/**
* Updates the given filter from the UI state.
*/
private void updateFilterFromUI() {
int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText());
* Updates the given filter from the UI state.
*/
private void updateFilterFromUI() {
int maxCallDepth= Integer.parseInt(this.fMaxCallDepth.getText());

CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth);
CallHierarchy.getDefault().setFilters(fNames.getText());
CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection());
CallHierarchy.getDefault().setFilterTestCode(fFilterTestCode.getSelection());
}
CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth);
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());
}

/**
* Updates the UI state from the given filter.
*/
private void updateUIFromFilter() {
fMaxCallDepth.setText(String.valueOf(CallHierarchyUI.getDefault().getMaxCallDepth()));
fNames.setText(CallHierarchy.getDefault().getFilters());
fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled());

setSelection();

updateEnabledState();
}

/**
* Updates the UI state from the given filter.
*/
private void updateUIFromFilter() {
fMaxCallDepth.setText(String.valueOf(CallHierarchyUI.getDefault().getMaxCallDepth()));
fNames.setText(CallHierarchy.getDefault().getFilters());
fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled());
fFilterTestCode.setSelection(CallHierarchy.getDefault().isFilterTestCode());
updateEnabledState();
}

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

0 comments on commit 3948ff8

Please sign in to comment.