mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Bug 327710 added support for C++ methods, fixed f.p for constructor, descr and special method such as operators, added preferences for checking for C++ methods
This commit is contained in:
parent
cf174d1afb
commit
108d5bdca2
1 changed files with 41 additions and 3 deletions
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
||||
/**
|
||||
* This is style checker for function name code style. Pattern parameter is
|
||||
|
@ -31,7 +32,9 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
|||
implements ICheckerWithPreferences {
|
||||
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$
|
||||
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
|
||||
|
||||
public static final String PARAM_METHODS = "macro"; //$NON-NLS-1$
|
||||
public static final String PARAM_EXCEPT_ARG_LIST = "exceptions"; //$NON-NLS-1$
|
||||
|
||||
public void processAst(IASTTranslationUnit ast) {
|
||||
final IProblem pt = getProblemById(ER_ID, getFile());
|
||||
try {
|
||||
|
@ -42,12 +45,30 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
|||
|
||||
public int visit(IASTDeclaration element) {
|
||||
if (element instanceof IASTFunctionDefinition) {
|
||||
String parameter = (String) getPreference(pt,PARAM_KEY);
|
||||
String parameter = (String) getPreference(pt, PARAM_KEY);
|
||||
Pattern pattern = Pattern.compile(parameter);
|
||||
IASTName astName = ((IASTFunctionDefinition) element)
|
||||
.getDeclarator().getName();
|
||||
String name = astName.toString();
|
||||
if (!pattern.matcher(name).find()) {
|
||||
if (astName instanceof ICPPASTQualifiedName) {
|
||||
if (!shouldReportCppMethods())
|
||||
return PROCESS_SKIP;
|
||||
ICPPASTQualifiedName cppAstName = (ICPPASTQualifiedName) astName;
|
||||
if (cppAstName.isConversionOrOperator())
|
||||
return PROCESS_SKIP;
|
||||
name = cppAstName.getLastName().toString();
|
||||
if (name.startsWith("~")) // destructor //$NON-NLS-1$
|
||||
return PROCESS_SKIP;
|
||||
|
||||
IASTName[] names = cppAstName.getNames();
|
||||
if (names.length>=2) {
|
||||
if (names[names.length-1].toString().equals(names[names.length-2].toString())) {
|
||||
// constructor
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pattern.matcher(name).find() && !isFilteredArg(name)) {
|
||||
reportProblem(ER_ID, astName, name, parameter);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +94,24 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
|||
PARAM_KEY,
|
||||
CheckersMessages.NamingConventionFunctionChecker_LabelNamePattern,
|
||||
"^[a-z]"); //$NON-NLS-1$
|
||||
addPreference(problem, PARAM_METHODS,
|
||||
"Also check C++ method names",
|
||||
Boolean.TRUE);
|
||||
addListPreference(
|
||||
problem,
|
||||
PARAM_EXCEPT_ARG_LIST,
|
||||
CheckersMessages.GenericParameter_ParameterExceptions,
|
||||
CheckersMessages.GenericParameter_ParameterExceptionsItem);
|
||||
}
|
||||
public boolean shouldReportCppMethods() {
|
||||
return (Boolean) getPreference(getProblemById(ER_ID, getFile()),
|
||||
PARAM_METHODS);
|
||||
}
|
||||
public boolean isFilteredArg(String arg) {
|
||||
return isFilteredArg(arg, getProblemById(ER_ID, getFile()),
|
||||
PARAM_EXCEPT_ARG_LIST);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean runInEditor() {
|
||||
|
|
Loading…
Add table
Reference in a new issue