mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Externalized strings
This commit is contained in:
parent
94cb067beb
commit
53845ca38e
6 changed files with 19 additions and 27 deletions
|
@ -13,6 +13,7 @@
|
||||||
defaultSeverity="Warning"
|
defaultSeverity="Warning"
|
||||||
description="Finds statements like 'if (a=b)'"
|
description="Finds statements like 'if (a=b)'"
|
||||||
id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem"
|
id="org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem"
|
||||||
|
messagePattern="Possible assignment in condition"
|
||||||
name="Assignment in condition">
|
name="Assignment in condition">
|
||||||
</problem>
|
</problem>
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
|
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
|
||||||
defaultSeverity="Warning"
|
defaultSeverity="Warning"
|
||||||
id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"
|
id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"
|
||||||
|
messagePattern="Class ''{0}'' has virtual method ''{1}'' but non-virtual destructor ''{2}''"
|
||||||
name="Class has a virtual method and non-virtual destructor">
|
name="Class has a virtual method and non-virtual destructor">
|
||||||
</problem>
|
</problem>
|
||||||
</checker>
|
</checker>
|
||||||
|
@ -63,8 +65,8 @@
|
||||||
<problem
|
<problem
|
||||||
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
|
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
|
||||||
defaultSeverity="Warning"
|
defaultSeverity="Warning"
|
||||||
description="This checker finds a problems that caused by lack of understanding operator precedence in C. Example (! x>0 && x<10). Parenthesis should be used to clarify programmer's intent."
|
|
||||||
id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem"
|
id="org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem"
|
||||||
|
messagePattern="Suggested parenthesis around expression"
|
||||||
name="Suggested parenthesis around expression">
|
name="Suggested parenthesis around expression">
|
||||||
</problem>
|
</problem>
|
||||||
</checker>
|
</checker>
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.osgi.framework.BundleContext;
|
||||||
*/
|
*/
|
||||||
public class CodanCheckersActivator extends Plugin {
|
public class CodanCheckersActivator extends Plugin {
|
||||||
// The plug-in ID
|
// The plug-in ID
|
||||||
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers";
|
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers"; //$NON-NLS-1$
|
||||||
// The shared instance
|
// The shared instance
|
||||||
private static CodanCheckersActivator plugin;
|
private static CodanCheckersActivator plugin;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
|
||||||
public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
|
public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem";
|
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem"; //$NON-NLS-1$
|
||||||
|
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
// traverse the ast using the visitor pattern.
|
// traverse the ast using the visitor pattern.
|
||||||
|
@ -35,7 +35,7 @@ public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
|
||||||
public int visit(IASTExpression expression) {
|
public int visit(IASTExpression expression) {
|
||||||
if (isAssignmentExpression(expression)
|
if (isAssignmentExpression(expression)
|
||||||
&& isUsedAsCondition(expression)) {
|
&& isUsedAsCondition(expression)) {
|
||||||
reportProblem(ER_ID, expression, "Possible assignment in condition");
|
reportProblem(ER_ID, expression);
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.checkers;
|
package org.eclipse.cdt.codan.internal.checkers;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
|
import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
@ -33,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem";
|
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$
|
||||||
|
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
// traverse the ast using the visitor pattern.
|
// traverse the ast using the visitor pattern.
|
||||||
|
@ -43,7 +41,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
class OnEachClass extends ASTVisitor {
|
class OnEachClass extends ASTVisitor {
|
||||||
private IASTName className;
|
private IASTName className;
|
||||||
private IBinding virMethodName;
|
private IBinding virMethodName;
|
||||||
private IBinding destName;
|
private IBinding destructorName;
|
||||||
|
|
||||||
OnEachClass() {
|
OnEachClass() {
|
||||||
// shouldVisitDeclarations = true;
|
// shouldVisitDeclarations = true;
|
||||||
|
@ -55,22 +53,17 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
try {
|
try {
|
||||||
boolean err = hasErrorCondition(decl);
|
boolean err = hasErrorCondition(decl);
|
||||||
if (err) {
|
if (err) {
|
||||||
String mess;
|
|
||||||
String clazz = className.toString();
|
String clazz = className.toString();
|
||||||
String method = virMethodName.getName();
|
String method = virMethodName.getName();
|
||||||
IASTNode ast = decl;
|
IASTNode ast = decl;
|
||||||
if (destName != null) {
|
if (destructorName != null) {
|
||||||
if (destName instanceof ICPPInternalBinding) {
|
if (destructorName instanceof ICPPInternalBinding) {
|
||||||
ICPPInternalBinding bin = (ICPPInternalBinding) destName;
|
ICPPInternalBinding bin = (ICPPInternalBinding) destructorName;
|
||||||
IASTNode[] decls = bin.getDeclarations();
|
IASTNode[] decls = bin.getDeclarations();
|
||||||
if (decls!=null && decls.length>0)
|
if (decls!=null && decls.length>0)
|
||||||
ast = decls[0];
|
ast = decls[0];
|
||||||
}
|
}
|
||||||
mess = MessageFormat
|
reportProblem(ER_ID, ast, clazz, method, destructorName.getName());
|
||||||
.format(
|
|
||||||
"Class ''{0}'' has virtual method ''{1}'' but non-virtual destructor ''{2}''",
|
|
||||||
clazz, method, destName.getName());
|
|
||||||
reportProblem(ER_ID, ast, mess);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
|
@ -98,7 +91,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
if (binding instanceof ICPPClassType) {
|
if (binding instanceof ICPPClassType) {
|
||||||
ICPPClassType type = (ICPPClassType) binding;
|
ICPPClassType type = (ICPPClassType) binding;
|
||||||
virMethodName = null;
|
virMethodName = null;
|
||||||
destName = null;
|
destructorName = null;
|
||||||
// check for the following conditions:
|
// check for the following conditions:
|
||||||
// class has own virtual method and own non-virtual destructor
|
// class has own virtual method and own non-virtual destructor
|
||||||
// class has own virtual method and base non-virtual destructor
|
// class has own virtual method and base non-virtual destructor
|
||||||
|
@ -118,7 +111,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
hasDestructor = true;
|
hasDestructor = true;
|
||||||
if (!icppMethod.isVirtual()) {
|
if (!icppMethod.isVirtual()) {
|
||||||
hasOwnNonVirDestructor = true;
|
hasOwnNonVirDestructor = true;
|
||||||
destName = icppMethod;
|
destructorName = icppMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,8 +140,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
if (icppMethod.isVirtual()) {
|
if (icppMethod.isVirtual()) {
|
||||||
hasVirDestructor = true;
|
hasVirDestructor = true;
|
||||||
} else {
|
} else {
|
||||||
if (destName == null)
|
if (destructorName == null)
|
||||||
destName = icppMethod;
|
destructorName = icppMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,6 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
* @param func
|
* @param func
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
protected boolean endsWithNoExitNode(IASTFunctionDefinition func) {
|
protected boolean endsWithNoExitNode(IASTFunctionDefinition func) {
|
||||||
IControlFlowGraph graph = CxxModelsCache.getInstance()
|
IControlFlowGraph graph = CxxModelsCache.getInstance()
|
||||||
.getControlFlowGraph(func);
|
.getControlFlowGraph(func);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SuggestedParenthesisChecker extends AbstractIndexAstChecker {
|
public class SuggestedParenthesisChecker extends AbstractIndexAstChecker {
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem";
|
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem"; //$NON-NLS-1$
|
||||||
|
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
// traverse the ast using the visitor pattern.
|
// traverse the ast using the visitor pattern.
|
||||||
|
@ -51,16 +51,14 @@ public class SuggestedParenthesisChecker extends AbstractIndexAstChecker {
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
if (precedence == 2) { // unary not
|
if (precedence == 2) { // unary not
|
||||||
if (isUsedAsOperand(expression)) {
|
if (isUsedAsOperand(expression)) {
|
||||||
reportProblem(ER_ID, expression,
|
reportProblem(ER_ID, expression);
|
||||||
"Suggested parenthesis around expression");
|
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
} else if (precedence >= 0) {
|
} else if (precedence >= 0) {
|
||||||
int pp = getPrecedence(parentExpr);
|
int pp = getPrecedence(parentExpr);
|
||||||
if (pp == -1 || pp == precedence)
|
if (pp == -1 || pp == precedence)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
reportProblem(ER_ID, expression,
|
reportProblem(ER_ID, expression);
|
||||||
"Suggested parenthesis around expression");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
|
|
Loading…
Add table
Reference in a new issue