Skip to content

Commit

Permalink
better code maybe??
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisCode committed Oct 22, 2024
1 parent 373e4db commit 9b7d854
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@

public class CallHierarchyCore {

//to add a new one just add here and change the isIgnored Method

public static final String PREF_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$
public static final String[] A_SHOW_ALL_CODE = {PREF_SHOW_ALL_CODE, "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[] A_HIDE_TEST_CODE = {PREF_HIDE_TEST_CODE, "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_FILTERS = {PREF_SHOW_ALL_CODE, PREF_HIDE_TEST_CODE, PREF_SHOW_TEST_CODE_ONLY};
public static final String[] A_SHOW_TEST_CODE = {PREF_SHOW_TEST_CODE_ONLY, "Test Code only"}; //$NON-NLS-1$

public static final String[][] PREF_FILTERS = {A_SHOW_ALL_CODE, A_HIDE_TEST_CODE, A_SHOW_TEST_CODE};

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$
Expand Down Expand Up @@ -85,9 +93,9 @@ public boolean isHideTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null));
}
public String getActiveFilter() {
for (String string : PREF_FILTERS) { //must be one of the threee
if(Boolean.parseBoolean(JavaManipulation.getPreference(string, null))) {
return string;
for (String[] string : PREF_FILTERS) { //must be one of the threee
if(Boolean.parseBoolean(JavaManipulation.getPreference(string[0], null))) {
return string[0];
}
} return null;
}
Expand Down
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 Down Expand Up @@ -60,28 +57,13 @@ 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 setShowTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_SHOW_TEST_CODE_ONLY, value);
}

public void setActiveFilter (String string) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
for (String s : CallHierarchyCore.PREF_FILTERS) {
if(s == string) {
settings.setValue(s, true);
for (String[] s : CallHierarchyCore.PREF_FILTERS) {
if(s[0] == string) {
settings.setValue(s[0], true);
} else {
settings.setValue(s, false);
settings.setValue(s[0], false);
}
}

Expand Down Expand Up @@ -151,22 +133,15 @@ 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() {
public String getActiveFilter() {
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);
}

for (String[] string : CallHierarchyCore.PREF_FILTERS) { //must be one of the threee
if(settings.getBoolean(string[0])) {
return string[0];
}
} 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 @@ -44,9 +44,11 @@ class FiltersDialog extends StatusDialog {
private Button fShowAll;
private Button fHideTest;
private Button fShowTest;
private Button[] buttons = {fShowAll, fHideTest, fShowTest};
private Button[] buttons = {fShowAll, fHideTest, fShowTest}; //important what comes when

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

}

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

for (Button button : buttons) {
button = new Button(radioGroup, SWT.RADIO);
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(radioGroup, SWT.RADIO);
buttons[i].setText(getStrings(buttons[i])[1]);
}

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

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(int i = 0; i < buttons.length; i++) {
buttons[i].setSelection(CallHierarchy.getDefault().getActiveFilter()
== CallHierarchyCore.PREF_FILTERS[i][0]);

}
}

/**
Expand Down Expand Up @@ -196,16 +193,13 @@ 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());
String activeFilter;

String activeFilter =""; //$NON-NLS-1$
for (Button button : buttons) {
if(button.getSelection()) {
activeFilter = getString(button);
activeFilter = (getStrings(button))[0];
}
}
activeFilter = ""; //$NON-NLS-1$

CallHierarchy.getDefault().setActiveFilter(activeFilter);
}
Expand All @@ -222,13 +216,14 @@ private void updateUIFromFilter() {

updateEnabledState();
}
private String getString(Button B) {
if(B == fShowAll) {
return CallHierarchyCore.PREF_SHOW_ALL_CODE;
} else if (B == fHideTest) {
return CallHierarchyCore.PREF_HIDE_TEST_CODE;

private String[] getStrings(Button B) {
if(B == buttons[0]) {
return CallHierarchyCore.PREF_FILTERS[0];
} else if (B == buttons[1]) {
return CallHierarchyCore.PREF_FILTERS[1];
} else {
return CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY;
return CallHierarchyCore.PREF_FILTERS[2];
}
}

Expand Down

0 comments on commit 9b7d854

Please sign in to comment.