|
Lines 11-16
Link Here
|
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.cdt.codan.internal.checkers; |
12 |
package org.eclipse.cdt.codan.internal.checkers; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.regex.Pattern; |
| 15 |
|
| 14 |
import org.eclipse.cdt.codan.core.cxx.CxxAstUtils; |
16 |
import org.eclipse.cdt.codan.core.cxx.CxxAstUtils; |
| 15 |
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; |
17 |
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; |
| 16 |
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences; |
18 |
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences; |
|
Lines 40-46
public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
Link Here
|
| 40 |
public static final String DEFAULT_NO_BREAK_COMMENT = "no break"; //$NON-NLS-1$ |
42 |
public static final String DEFAULT_NO_BREAK_COMMENT = "no break"; //$NON-NLS-1$ |
| 41 |
private Boolean _checkLastCase; // Should we check the last case in the switch? |
43 |
private Boolean _checkLastCase; // Should we check the last case in the switch? |
| 42 |
private Boolean _checkEmptyCase; // Should we check an empty case (a case without any statements within it) |
44 |
private Boolean _checkEmptyCase; // Should we check an empty case (a case without any statements within it) |
| 43 |
private String _noBreakComment; // The comment suppressing this warning |
45 |
private Pattern _noBreakRegex; |
|
|
46 |
private static final int NO_BREAK_REGEX_FLAGS = Pattern.CASE_INSENSITIVE; |
| 44 |
|
47 |
|
| 45 |
/** |
48 |
/** |
| 46 |
* This visitor looks for "switch" statements and invokes "SwitchVisitor" on |
49 |
* This visitor looks for "switch" statements and invokes "SwitchVisitor" on |
|
Lines 110-117
public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
Link Here
|
| 110 |
} |
113 |
} |
| 111 |
if (comment != null) { |
114 |
if (comment != null) { |
| 112 |
String str = getTrimmedComment(comment); |
115 |
String str = getTrimmedComment(comment); |
| 113 |
if (str.equalsIgnoreCase(_noBreakComment)) |
116 |
if (_noBreakRegex.matcher(str).find()) { |
| 114 |
continue; |
117 |
continue; |
|
|
118 |
} |
| 115 |
} |
119 |
} |
| 116 |
reportProblem(ER_ID, prevCase, (Object) null); |
120 |
reportProblem(ER_ID, prevCase, (Object) null); |
| 117 |
} |
121 |
} |
|
Lines 213-219
public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
Link Here
|
| 213 |
public void processAst(IASTTranslationUnit ast) { |
217 |
public void processAst(IASTTranslationUnit ast) { |
| 214 |
_checkLastCase = (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_LAST_CASE); |
218 |
_checkLastCase = (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_LAST_CASE); |
| 215 |
_checkEmptyCase = (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_EMPTY_CASE); |
219 |
_checkEmptyCase = (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_EMPTY_CASE); |
| 216 |
_noBreakComment = (String) getPreference(getProblemById(ER_ID, getFile()), PARAM_NO_BREAK_COMMENT); |
220 |
String noBreakRegexStr = (String) getPreference(getProblemById(ER_ID, getFile()), PARAM_NO_BREAK_COMMENT); |
|
|
221 |
_noBreakRegex = Pattern.compile(noBreakRegexStr, NO_BREAK_REGEX_FLAGS); |
| 217 |
SwitchFindingVisitor visitor = new SwitchFindingVisitor(); |
222 |
SwitchFindingVisitor visitor = new SwitchFindingVisitor(); |
| 218 |
ast.accept(visitor); |
223 |
ast.accept(visitor); |
| 219 |
} |
224 |
} |