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

Bug 352221

Summary: Quick Fix for "case break" checker
Product: [Tools] CDT Reporter: Gil Barash <scobido1984>
Component: cdt-codanAssignee: Elena Laskavaia <elaskavaia.cdt>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: enhancement    
Priority: P3 CC: cdtdoug, malaperle, scobido1984
Version: 8.0   
Target Milestone: 8.1.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
path for QuickFix_for_case_break_checker cdtdoug: iplog+

Description Gil Barash CLA 2011-07-15 10:42:53 EDT
Created attachment 199750 [details]
path for QuickFix_for_case_break_checker

The supplied patch contains two quick fixes:
1) "add break" which adds the missing break
2) "add comment" which adds a comment (such as "no break") to suppress the warning

In order to implement item 2, I had to modify the CaseBreak checker. In the patch the possible suppressing comment is not a regular expression (which didn't work anyway, see bug 350144). It is now a string of possible comment prefixes (separated by "|").
The comment used in item 2, is the first comment in the string.
(so this patch also fixes bug 350144)

Another thing regarding item 2 - I didn't find out how to insert a comment, with the correct indentation, into the code. So my patch does it in two stages - first, it inserts a call to a dummy function, and then replaces the call with the comment.
Comment 1 Elena Laskavaia CLA 2011-08-20 15:08:03 EDT
I reviewed the patch:
- Lets not use special expression for comment, I am working on common framework for comments and I don't want confuse people with diffrent way of entering comment, current one would be just case insensive string containing in comment,
so no |
- Ast locations should not be stored in extra problem arguments, you should extract same location in quick fix itself from the node of the problem itself (problems are persistent markers, they also can move with line number changes)
- There is no point storing comment in the problem marker either - it can be extracted from problem type parameter
- Inserting function instead of comment is very ugly, I would ignore the indentation issues - just inset the comment and remove the other ugliness
- Need protection from exceptions everywhere, for example old codan problems would not have paramters, so it should not throw exceptions, just work based on some default values
Comment 2 Elena Laskavaia CLA 2011-08-22 22:51:03 EDT
fixed in Next cdt, I pretty much rewrote all the code of the patch, but thanks
for the inspiration

- I made checker report error on last statement before the break instead of case, which is better anyway
- I remove parameters for error, because quick fix can figure it out itself
- I make comment quick fix use document API directly to insert the comment, instead of dealing with ast rewrite since it is an overkill
- I made break fix figure out position by itself
Comment 3 CDT Genie CLA 2011-08-22 23:23:01 EDT
*** cdt git genie on behalf of Alena Laskavaia ***

    Bug 352221 - Quick Fix for &quot;case break&quot; checker

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=6f2671b1eeccb5ede9328c1aa89db3e2bf232f8f
Comment 4 CDT Genie CLA 2011-08-23 20:23:01 EDT
*** cdt git genie on behalf of Alena Laskavaia ***

    Bug 352221 - Quick Fix for &quot;case break&quot; checker

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=d70aae3b111e208bb0540c688b4d6d6b7732ad6a
Comment 5 Gil Barash CLA 2011-08-24 07:58:42 EDT
Wow, thanks Alena, I was really going to fix it according to what you suggested, on the weekend... You've beat me to the punch :-)