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 committed Oct 7, 2024
1 parent 6be9114 commit 4ae21fa
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 187 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_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$
private static final String PREF_HIDE_TEST_CODE = "PREF_HIDE_TEST_CODE"; //$NON-NLS-1$
private 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 static final String PREF_FILTER_TESTCODE= "PREF_FILTER_TESTCODE"; //$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,14 @@
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_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$
private static final String PREF_HIDE_TEST_CODE = "PREF_HIDE_TEST_CODE"; //$NON-NLS-1$
private 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 static final String PREF_FILTER_TESTCODE= "PREF_FILTER_TESTCODE"; //$NON-NLS-1$

private static CallHierarchy fgInstance;
private CallHierarchyCore fgCallHierarchyCore;
Expand All @@ -53,35 +57,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(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(PREF_HIDE_TEST_CODE, value);
}

public boolean isFilterTestCode() {
public void setShowTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_HIDE_TEST_CODE, 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 +139,22 @@ 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 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
Loading

0 comments on commit 4ae21fa

Please sign in to comment.