-
Notifications
You must be signed in to change notification settings - Fork 147
Do not enable Link Prototypes if there are no prototypes #2216
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
base: master
Are you sure you want to change the base?
Conversation
Test Results1 320 files - 657 1 320 suites - 657 1h 4m 10s ⏱️ - 28m 29s Results for commit f94a02f. ± Comparison against base commit b7ae22a. This pull request skips 1 test.♻️ This comment has been updated with latest results. |
2f03f42 to
afe71e5
Compare
afe71e5 to
300deac
Compare
|
Hi @vogella, could you please check this PR when you get some time ? |
300deac to
5a4fc73
Compare
5a4fc73 to
79493a8
Compare
d3ffd15 to
724f90e
Compare
|
Hi @merks, could you please merge this small change when you get a moment ? |
| if (launchConfigurationTypes.size() == 1) { | ||
| return launchConfigurationTypes.iterator().next().supportsPrototypes(); | ||
|
|
||
| if (launchConfigurationTypes.size() == 1 && type != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not possible for type == null if launchConfigurationTypes.size()== 1 because you only add non-null types this list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid unnecessary iterations for getting the type, I went with this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get another opinion. @akurtakov @laeubi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the compiler is confused by the hard to understand logic here.
From the description I think you actually not need the set here at all and I would not premature optimize this, we can expect this is not containing millions of elements so splitting up the logic into different steps would help e.g. you can early exit if the selection is empty.
Then the if/else is unnecessarily nested (as you immediately return from the method in the case).
Next your check for null can become
if (type == null || type == launchConfig.getType()) {
type = launchConfig.getType();
} else {
return false;
}
(and a core exception should probably be rethrown or also return false..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this patch (applied on master):
diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java
index e8d2a66..7f1a9d2 100644
--- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java
+++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java
@@ -15,5 +15,2 @@
-import java.util.Collection;
-import java.util.HashSet;
-
import org.eclipse.core.runtime.CoreException;
@@ -108,11 +105,12 @@
// is(are) selected and the launch configuration type allows prototypes
- Collection<ILaunchConfigurationType> launchConfigurationTypes = new HashSet<>();
- for (Object object : selection.toList()) {
- if (object instanceof ILaunchConfiguration) {
- if (((ILaunchConfiguration) object).isPrototype()) {
+ for (Object object : selection) {
+ if (object instanceof ILaunchConfiguration config) {
+ if (config.isPrototype()) {
return false;
} else {
- ILaunchConfigurationType type = null;
try {
- type = ((ILaunchConfiguration) object).getType();
+ ILaunchConfigurationType type = config.getType();
+ if (type != null) {
+ return type.supportsPrototypes() && type.getPrototypes().length > 0;
+ }
} catch (CoreException e) {
@@ -120,7 +118,2 @@
}
- if (type != null) {
- launchConfigurationTypes.add(type);
- } else {
- return false;
- }
}
@@ -130,5 +123,2 @@
}
- if (launchConfigurationTypes.size() == 1) {
- return launchConfigurationTypes.iterator().next().supportsPrototypes();
- }
return false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a comment about all the selection being of the same type so I think this maybe misses that point by returning early. Or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iloveeclipse with your patch, one of the launch config will be removed if different launch configs are selected accidently by the user - and do a prototype selection
bug.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option should show only if its a same launch config type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have optimised the code bit more
724f90e to
d3b7b4f
Compare
| return launchConfigurationTypes.iterator().next().supportsPrototypes(); | ||
|
|
||
| try { | ||
| return type != null && type.getPrototypes().length > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to pick things to death, but if this test were done after line 116, you could return early at that point, there would be one less try/catch block, and if you then get to the end of the loop, you can return true (because line 125 will return false when all the types are not the same). Or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to pick things to death, but if this test were done after line 116, you could return early at that point, there would be one less try/catch block
currentType = launchConfig.getType();
return currentType != null && currentType.getPrototypes().length > 0;
I tried this but got the same issue as #2216 (comment) :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is to test if currentType.getPrototypes().length == 0 and return false early in that case, not to return true early for any other reason. We of course must get through the whole loop before we can know to return true ever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Updated 👍
d3b7b4f to
c64afd9
Compare
merks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this looks more comprehensible. (I believe this would even perform better than previous "optimized" versions without sacrificing clarity.)
This commit disables Link Prototypes from launch configurations context if there are no prototypes defined launch type.
c64afd9 to
f94a02f
Compare

This PR disables the
Link Prototypescontext menu in launch configurations when no prototypes are defined for the selected launch type.Previously, selecting this option displayed an empty list when no prototypes were available.

With this change, the context menu option will only be enabled if at least one prototype is defined for the selected launch type, preventing users from seeing an empty list.