mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
Bug 328532 - added parameter to suppress the error in case if has else
This commit is contained in:
parent
dc5d147ab5
commit
7e83139fba
3 changed files with 21 additions and 1 deletions
|
@ -24,6 +24,7 @@ public class CheckersMessages extends NLS {
|
|||
public static String GenericParameter_ParameterExceptionsItem;
|
||||
public static String StatementHasNoEffectChecker_ParameterMacro;
|
||||
public static String SuggestedParenthesisChecker_SuggestParanthesesAroundNot;
|
||||
public static String SuspiciousSemicolonChecker_ParamElse;
|
||||
|
||||
public static String ProblemBindingChecker_Candidates;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
package org.eclipse.cdt.codan.internal.checkers;
|
||||
|
||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
|
@ -21,7 +23,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
||||
public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
|
||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem"; //$NON-NLS-1$
|
||||
public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem"; //$NON-NLS-1$
|
||||
public static final String PARAM_ELSE = "else"; //$NON-NLS-1$
|
||||
|
||||
public void processAst(IASTTranslationUnit ast) {
|
||||
ast.accept(new ASTVisitor() {
|
||||
|
@ -34,6 +37,10 @@ public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
|
|||
if (statement instanceof IASTIfStatement) {
|
||||
IASTStatement thenStmt = ((IASTIfStatement) statement)
|
||||
.getThenClause();
|
||||
IASTStatement elseStmt = ((IASTIfStatement) statement)
|
||||
.getElseClause();
|
||||
if (elseStmt != null && doNotReportIfElse() == true)
|
||||
return PROCESS_CONTINUE;
|
||||
if (thenStmt instanceof IASTNullStatement
|
||||
&& noMacroInvolved(thenStmt)) {
|
||||
reportProblem(ER_ID, thenStmt, (Object) null);
|
||||
|
@ -44,6 +51,10 @@ public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
|
|||
});
|
||||
}
|
||||
|
||||
protected boolean doNotReportIfElse() {
|
||||
final IProblem pt = getProblemById(ER_ID, getFile());
|
||||
return (Boolean) getPreference(pt, PARAM_ELSE);
|
||||
}
|
||||
|
||||
protected boolean noMacroInvolved(IASTStatement node) {
|
||||
IASTNodeSelector nodeSelector = node.getTranslationUnit()
|
||||
|
@ -54,4 +65,11 @@ public class SuspiciousSemicolonChecker extends AbstractIndexAstChecker {
|
|||
1);
|
||||
return macro == null;
|
||||
}
|
||||
|
||||
public void initPreferences(IProblemWorkingCopy problem) {
|
||||
super.initPreferences(problem);
|
||||
addPreference(problem, PARAM_ELSE,
|
||||
CheckersMessages.SuspiciousSemicolonChecker_ParamElse,
|
||||
Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@ GenericParameter_ParameterExceptions=Exceptions (value of the problem argument)
|
|||
GenericParameter_ParameterExceptionsItem=Value of the argument
|
||||
StatementHasNoEffectChecker_ParameterMacro=Report problem in statements that comes from macro expansion
|
||||
SuggestedParenthesisChecker_SuggestParanthesesAroundNot=Suggest parenthesis around not operator
|
||||
SuspiciousSemicolonChecker_ParamElse=Do not report an error if 'else' exists
|
||||
|
||||
ProblemBindingChecker_Candidates=Candidates are:
|
Loading…
Add table
Reference in a new issue