Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gvozdev2011-04-29 07:17:42 -0400
committerAndrew Gvozdev2011-04-29 07:17:42 -0400
commitfe52e11b255ef0e09fc928b69adba8104492375e (patch)
tree31213481789c89deb435028ac4013c1690e745f2 /codan/org.eclipse.cdt.codan.checkers
parentbfab63bae94a5717cbe644927f52afda8cddac1c (diff)
downloadorg.eclipse.cdt-fe52e11b255ef0e09fc928b69adba8104492375e.tar.gz
org.eclipse.cdt-fe52e11b255ef0e09fc928b69adba8104492375e.tar.xz
org.eclipse.cdt-fe52e11b255ef0e09fc928b69adba8104492375e.zip
bug 343429: [checker] Checker to pinpoint unused static functions in a filev201104290807
Added exception for CVS ident
Diffstat (limited to 'codan/org.eclipse.cdt.codan.checkers')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java3
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.properties4
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java52
3 files changed, 48 insertions, 11 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java
index 255aaf2d0d..32397ef13c 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.java
@@ -30,6 +30,9 @@ public class CheckersMessages extends NLS {
public static String SuspiciousSemicolonChecker_ParamElse;
public static String ProblemBindingChecker_Candidates;
+ public static String UnusedSymbolInFileScopeChecker_CharacterSequence;
+ public static String UnusedSymbolInFileScopeChecker_Exceptions;
+
static {
NLS.initializeMessages(CheckersMessages.class.getName(), CheckersMessages.class);
}
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.properties b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.properties
index 74fc7c6647..3296e70fa2 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.properties
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CheckersMessages.properties
@@ -21,4 +21,6 @@ StatementHasNoEffectChecker_ParameterMacro=Report problem in statements that com
SuggestedParenthesisChecker_SuggestParanthesesAroundNot=Suggest parenthesis around not operator
SuspiciousSemicolonChecker_ParamElse=Do not report an error if 'else' exists
-ProblemBindingChecker_Candidates=Candidates are: \ No newline at end of file
+ProblemBindingChecker_Candidates=Candidates are:
+UnusedSymbolInFileScopeChecker_CharacterSequence=Ident character sequence:
+UnusedSymbolInFileScopeChecker_Exceptions=Exceptions (ident character sequence)
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
index 841b8d45b0..6759b2631b 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
@@ -17,13 +17,19 @@ import java.util.Map;
import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
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.codan.core.param.ListProblemPreference;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@@ -44,23 +50,31 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
public static final String ER_UNUSED_VARIABLE_DECLARATION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem"; //$NON-NLS-1$
public static final String ER_UNUSED_FUNCTION_DECLARATION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem"; //$NON-NLS-1$
public static final String ER_UNUSED_STATIC_FUNCTION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem"; //$NON-NLS-1$
+ public static final String PARAM_EXCEPT_ARG_LIST = "exceptions"; //$NON-NLS-1$
private Map<IBinding, IASTDeclarator> externFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>();
private Map<IBinding, IASTDeclarator> staticFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>();
private Map<IBinding, IASTDeclarator> staticFunctionDefinitions = new HashMap<IBinding, IASTDeclarator>();
private Map<IBinding, IASTDeclarator> externVariableDeclarations = new HashMap<IBinding, IASTDeclarator>();
private Map<IBinding, IASTDeclarator> staticVariableDeclarations = new HashMap<IBinding, IASTDeclarator>();
+ private IProblemWorkingCopy unusedVariableProblem = null;
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.cdt.codan.core.model.ICheckerWithPreferences#initParameters
- * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
- */
+ @Override
+ public boolean runInEditor() {
+ return true;
+ }
+
@Override
public void initPreferences(IProblemWorkingCopy problem) {
super.initPreferences(problem);
+ if (problem.getId().equals(ER_UNUSED_VARIABLE_DECLARATION_ID)) {
+ unusedVariableProblem = problem;
+ ListProblemPreference pref = addListPreference(problem, PARAM_EXCEPT_ARG_LIST,
+ CheckersMessages.UnusedSymbolInFileScopeChecker_Exceptions,
+ CheckersMessages.UnusedSymbolInFileScopeChecker_CharacterSequence);
+ pref.addChildValue("@(#)"); //$NON-NLS-1$
+ pref.addChildValue("$Id"); //$NON-NLS-1$
+ }
}
private void clearCandidates() {
@@ -125,6 +139,18 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
IType type = ((IVariable) binding).getType();
// account for class constructor and avoid possible false positive
if (!(type instanceof ICPPClassType) && !(type instanceof IProblemType)) {
+ IASTInitializer initializer = decl.getInitializer();
+ if (initializer instanceof IASTEqualsInitializer) {
+ IASTEqualsInitializer equalsInitializer = (IASTEqualsInitializer) initializer;
+ IASTInitializerClause clause = equalsInitializer.getInitializerClause();
+ if (clause instanceof IASTLiteralExpression) {
+ IASTLiteralExpression literalExpression = (IASTLiteralExpression) clause;
+ String literal = literalExpression.toString();
+ if (isFilteredOut(literal, unusedVariableProblem, PARAM_EXCEPT_ARG_LIST))
+ continue;
+ }
+ }
+
staticVariableDeclarations.put(binding, decl);
}
}
@@ -248,8 +274,14 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
clearCandidates(); // release memory
}
- @Override
- public boolean runInEditor() {
- return true;
+ public boolean isFilteredOut(String arg, IProblem problem, String exceptionListParamId) {
+ Object[] arr = (Object[]) getPreference(problem, exceptionListParamId);
+ for (int i = 0; i < arr.length; i++) {
+ String str = (String) arr[i];
+ if (arg.contains(str))
+ return true;
+ }
+ return false;
}
+
}

Back to the top