Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355229

Summary: Allow one quick fix to be reported with several variants
Product: [Tools] CDT Reporter: Tomasz Wesolowski <kosashi>
Component: cdt-codanAssignee: CDT Codan Inbox <cdt-codan-inbox>
Status: NEW --- QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on: 355402    
Bug Blocks:    
Attachments:
Description Flags
[w.i.p.] Working prototype and example quick fix none

Description Tomasz Wesolowski CLA 2011-08-19 11:00:05 EDT
A single Quick Fix class should be able to report more than one Quick Fix, each with different labels.

Example:
For the `invalid arguments` C++ problem, the description contains the list of candidate overloads. It makes sense for a single quick fix which would report as many variants as there are candidate overloads. Each variant should have its own name.

Also "change to use reference" and "change to use const reference" (and similar cases where two or more fixes are very similar) could be easily introduced as only one class, not two.


About the implementation, this looks a bit non-trivial since each Quick Fix class is now a subclass of IMarkerResolution. This could use a redesign.

The point is that Codan quick fixes are registered as MarkerResolutions, not QuickFixes. Compare the interfaces for the obvious difference:

org.eclipse.ui.IMarkerResolution
org.eclipse.cdt.ui.text.IQuickFixProcessor

I think JDT uses the latter for code analysis (I'm not sure though).

This may be the way to go (and I somehow expect this approach to be related to bug 349590).
Comment 1 Elena Laskavaia CLA 2011-08-20 13:30:58 EDT
Do you have a redesign proposal in mind?
Comment 2 Tomasz Wesolowski CLA 2011-08-21 09:24:13 EDT
We're currently extending the point:
org.eclipse.ui.ide.markerResolution

I'd suggest to drop that and instead extend:
org.eclipse.cdt.ui.quickFixProcessors

and let the little dwarfs inside org.eclipse.cdt.ui create IMarkerResolutions from the ICCompletionProposals that we'd create. I think this way is more correct (it solves this problem and might also solve bug 349590, additionally allows for different icons for fixes, etc).
Comment 3 Tomasz Wesolowski CLA 2011-08-21 18:08:54 EDT
I've done some initial prototyping. I can now confirm that submitting quick fixes via a quickFixProcessor solves bug 349590. Finally quick fixes in hovers for Codan, yay!
Comment 4 Tomasz Wesolowski CLA 2011-08-22 15:19:44 EDT
Created attachment 201947 [details]
[w.i.p.] Working prototype and example quick fix

This is a working prototype for the new extension point.

There's also a new-style quick fix for catch by reference (just as a demonstration for now).

If you apply the proposed patch from bug 349590, you'll see the new fixes proposed on problem hover! Finally.

The fixes aren't proposed on Ctrl+1 due to bug 355402, you can work that around for now by editing CCorrectionProcessor.getProblemLocation(..) to disregard the value of problemId until we get a better solution.

I've been using terminology along the lines of CodanProblemFix*, not QuickFix*, to avoid confusion between our new extension point and the CDT's.

If we're going to stay with this solution (I hope we are!), then some more features from the old extension point must be rewritten to the new extension point, like specifying problems via a message pattern and the quick fix base classes. After that, we can port the quick fixes to the new infrastructure and deprecate the old extension point.