Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Filter from call Hierarchy #1730

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jannisCode
Copy link
Contributor

What it does

This PR is a refactoring of the code for the filters in the Call Hierarchy.
It makes the code more modifiable and versatile

Author checklist

@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 6f320a6 to b598a1b Compare October 22, 2024 10:43
@jannisCode jannisCode mentioned this pull request Oct 22, 2024
3 tasks
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from b598a1b to 138e939 Compare October 22, 2024 14:02
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 23, 2024
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 138e939 to 12a4eb0 Compare October 23, 2024 09:41
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 12a4eb0 to 1d16fb4 Compare October 25, 2024 07:54
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 1d16fb4 to 05762ad Compare October 25, 2024 11:18
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 05762ad to de3e1dc Compare October 25, 2024 12:21
@jannisCode
Copy link
Contributor Author

I used your feedback and used Enums istead of arrays in the latest commit! Everything else is still the same!

jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from de3e1dc to 381b6cd Compare October 25, 2024 12:23
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 381b6cd to 405eaa4 Compare October 25, 2024 12:26
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 405eaa4 to cc0b1e8 Compare October 25, 2024 12:27
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 25, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from cc0b1e8 to b89f05b Compare October 25, 2024 12:28
Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the formatting, check for unnecessary changes, check the naming of the parameters (use camelCase) and there is also unnecessary if-else blocks (you can inline the content of the if)

@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from b89f05b to cc0b1e8 Compare October 29, 2024 13:43
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 29, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from cc0b1e8 to e002f0d Compare October 29, 2024 13:48
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 29, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from e002f0d to ac35cdf Compare October 29, 2024 13:50
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 29, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from ac35cdf to fcdbf21 Compare October 29, 2024 13:53
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Oct 29, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 60d5494 to 8f206b7 Compare October 29, 2024 14:08
@@ -43,6 +44,7 @@ class FiltersDialog extends StatusDialog {
private Button fShowAll;
private Button fHideTest;
private Button fShowTest;
private Button[] buttons = {fShowAll, fHideTest, fShowTest}; //important what comes when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make too much sense, here the buttons is initialized with 3 nulls, in a complicated way.

You can remove the fShowAll,fHideTest,fShowTest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the proper CallHierarchyMessages.FiltersDialog_ShowAllCode variables to return the labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Nov 4, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 8f206b7 to 323ece0 Compare November 4, 2024 08:43
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Nov 4, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 323ece0 to 1814d0a Compare November 4, 2024 09:51
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Nov 13, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 1814d0a to 5952983 Compare November 13, 2024 07:01
@jannisCode jannisCode marked this pull request as ready for review November 19, 2024 14:32
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Nov 25, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 5952983 to 4be571a Compare November 25, 2024 08:39
@eclipse-jdt-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF
org.eclipse.jdt.ui/META-INF/MANIFEST.MF
org.eclipse.jdt.ui/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From 869fc92358bb89b2bdb05604a43adc93e9dcf2bb Mon Sep 17 00:00:00 2001
From: Eclipse JDT Bot <[email protected]>
Date: Mon, 25 Nov 2024 08:42:39 +0000
Subject: [PATCH] Version bump(s) for 4.35 stream


diff --git a/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF
index cce3d0f53d..fc6299b123 100644
--- a/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.core.manipulation
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.core.manipulation; singleton:=true
-Bundle-Version: 1.21.300.qualifier
+Bundle-Version: 1.21.400.qualifier
 Bundle-Vendor: %providerName
 Bundle-Activator: org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin
 Bundle-Localization: plugin
diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
index 0a5b80724a..d1e2321293 100644
--- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true
-Bundle-Version: 3.33.200.qualifier
+Bundle-Version: 3.33.300.qualifier
 Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: %providerName
diff --git a/org.eclipse.jdt.ui/pom.xml b/org.eclipse.jdt.ui/pom.xml
index fffaedcc7e..3818bc298e 100644
--- a/org.eclipse.jdt.ui/pom.xml
+++ b/org.eclipse.jdt.ui/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.ui</artifactId>
-  <version>3.33.200-SNAPSHOT</version>
+  <version>3.33.300-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 	<build>
-- 
2.47.0

Further information are available in Common Build Issues - Missing version increments.

jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Dec 2, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 962d7f2 to d0d0eda Compare December 2, 2024 09:00
if(Boolean.parseBoolean(JavaManipulation.getPreference(option.getId(), null))) {
return option;
}
} return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} return null;
}
return null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_HIDE_TEST_CODE, value);
for(CallHierarchyFilterOptions option : CallHierarchyFilterOptions.values()) {
settings.setValue(option.getId(), option == filter ? true : false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settings.setValue(option.getId(), option == filter ? true : false);
settings.setValue(option.getId(), option == filter);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

public CallHierarchyFilterOptions getActiveFilter() {
for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { //must be one of the threee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) { //must be one of the threee
for (CallHierarchyFilterOptions option: CallHierarchyFilterOptions.values()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

updateEnabledState();
}

private CallHierarchyFilterOptions getFilterOptions(Button B) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private CallHierarchyFilterOptions getFilterOptions(Button B) {
private CallHierarchyFilterOptions getFilterOptions(Button b) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private Button fShowAll;
private Button fHideTest;
private Button fShowTest;
private Button[] buttons = new Button[CallHierarchyFilterOptions.values().length]; //important what comes when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Button[] buttons = new Button[CallHierarchyFilterOptions.values().length]; //important what comes when
private List<Button> buttons = new ArrayList<>(CallHierarchyFilterOptions.values().length); //important what comes when

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 120 to 129
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(radioGroup, SWT.RADIO);
buttons[i].setText(getFilterOptions(buttons[i]).getText());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is odd that you end up calling getFilterOptions to know what should go into the text. Also, if you add a new value to CallHierarchyFilterOptions then you need to adapt the method getFilterOptions. How about you:
a) Get the text by querying the current CallHierarchyFilterOptions and
b) Put the corresponding option into the data of the button so you can query it later in the getFilterOptions

Suggested change
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(radioGroup, SWT.RADIO);
buttons[i].setText(getFilterOptions(buttons[i]).getText());
}
for (CallHierarchyFilterOptions op : CallHierarchyFilterOptions.values()) {
Button b = new Button(radioGroup, SWT.RADIO);
b.setText(op.getText());
b.setData(KEY_CALL_HIERARCHY_FILTER_OPTION, op);
buttons.add(b);
}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the help! I implemented it the way you suggestend!

Comment on lines 212 to 224
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have the corresponding option in the data then you can simply query it.

Suggested change
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;
}
return (CallHierarchyFilterOptions) b.getData(KEY_CALL_HIERARCHY_FILTER_OPTION);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -40,9 +41,7 @@ class FiltersDialog extends StatusDialog {
private Button fFilterOnNames;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need this one if you follow my advice below:

Suggested change
private Button fFilterOnNames;
private static final String KEY_CALL_HIERARCHY_FILTER_OPTION= "callHierarchyFilterOption"; //$NON-NLS-1$
private Button fFilterOnNames;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Dec 3, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from d0d0eda to 5737c4c Compare December 3, 2024 08:31
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Dec 3, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 5737c4c to 4664372 Compare December 3, 2024 08:48
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_HIDE_TEST_CODE, value);
for(CallHierarchyFilterOptions option : CallHierarchyFilterOptions.values()) {
settings.setValue(option.getId(), option == filter); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settings.setValue(option.getId(), option == filter); }
settings.setValue(option.getId(), option == filter);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Dec 3, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from 4664372 to cf7200f Compare December 3, 2024 09:49
jannisCode added a commit to jannisCode/eclipse.jdt.ui that referenced this pull request Dec 6, 2024
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from cf7200f to e66345f Compare December 6, 2024 08:20
Now it works with an enum rather than an array which is much nicer

eclipse-jdt#1730
@jannisCode jannisCode force-pushed the Refactoring_CallHierarchy branch from e66345f to b48d2c4 Compare December 9, 2024 09:55
@fedejeanne
Copy link
Contributor

@gzsombor is this PR good to go?

Maybe some committer would like to (review and) merge?


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite this function to this:

Suggested change
}
private void createTestCodeArea(Composite parent) {
Composite radioGroup= new Composite(parent, SWT.NONE);
radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout layout= new GridLayout();
layout.numColumns= 1;
radioGroup.setLayout(layout);
GridData gridData= new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalIndent= 0;
for (CallHierarchyFilterOptions op : CallHierarchyFilterOptions.values()) {
Button b= new Button(radioGroup, SWT.RADIO);
b.setText(op.getText());
b.setData(KEY_CALL_HIERARCHY_FILTER_OPTION, op);
b.setLayoutData(gridData);
buttons.add(b);
}
setSelection();
}

That would fix the trimming of the labels too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a refactoring, it adds/changes the following lines:

  • radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  • GridData gridData= new GridData(GridData.FILL_HORIZONTAL);
  • b.setLayoutData(gridData);

This should be done in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants