Community
Participate
Working Groups
HEAD The "Return the allocated Object" quick fix hides the more interesting "Assign statement to local variable" quick assist. Have a line like this: new StringBuffer(); With the warning for unused objects enabled and the caret at the end of the line, Ctrl+1 jumps to the warning and only offers "Return the allocated object" and "Remove", but does not show the "Assign statement to local variable/field" quick assists. The quick assists should also be shown in this situation, and they should have precedence over the quick fixes.
Isn't this a general problem/feature ? Whenever Ctrl+1 jumps to a warning or error only the quick fixes are shown (see JavaCorrectionProcessor.computeQuickAssistProposals(..) line 242) You can always press Ctrl+1 again to jump back to the original location and use the quick assists. In this case "Assign statement to local variable/field" is available when you press Ctrl+1 again.
(In reply to comment #1) > Isn't this a general problem/feature ? Yes.
Created attachment 187984 [details] Fix In general, it's good that we don't show quick assists after jumping to the error location. But in this case, "Assign to local variable" can just as well be considered as a quick fix (since it indeed fixes the problem). I've implemented it that way, which has the additional advantage, that it also shows up in the quick fix hover. Finally, I've tweaked the relevance to prefer assigning to a local variable if the type of the allocated object is not assignable to the return type.
Created attachment 187985 [details] Fix Second try, just for bug 294650 :-(
Fixed in HEAD.
(In reply to comment #3) > But in this case, "Assign to local variable" can just as well > be considered as a quick fix (since it indeed fixes the problem). Fair enough, the fix looks good.
(In reply to comment #3) > Created attachment 187984 [details] [diff] > Fix > > In general, it's good that we don't show quick assists after jumping to the > error location. But in this case, "Assign to local variable" can just as well > be considered as a quick fix (since it indeed fixes the problem). > > I've implemented it that way, which has the additional advantage, that it also > shows up in the quick fix hover. Finally, I've tweaked the relevance to prefer > assigning to a local variable if the type of the allocated object is not > assignable to the return type. I see the order gets swapped depending on the return type, but the "Return the allocated Object" comes in between "Assign statement to local variable" and "Assign statement to new field". Don't we always show the similar quick fixes/assists together (like Rename, Extract...)? Plus both the assign assists solve the warning/error. public class A { int foo(){ new StringBuffer(); return 1; } } => I would expect that the 'Return the allocated Object' quick fix comes before or after both the Assign quick assists.
(In reply to comment #7) Pls see bug 339056
Verified for 3.6 M6 with I20110307-2110.