1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

make CIndex checker extened AbtractCheckerWithParamters because it should

This commit is contained in:
Alena Laskavaia 2011-02-22 02:57:11 +00:00
parent d71dfb3b20
commit 353b63daf9
2 changed files with 9 additions and 9 deletions

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.codan.core.cxx.model; package org.eclipse.cdt.codan.core.cxx.model;
import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.model.AbstractChecker; import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException;
* *
* Clients may extend this class. * Clients may extend this class.
*/ */
public abstract class AbstractCIndexChecker extends AbstractChecker implements ICIndexChecker { public abstract class AbstractCIndexChecker extends AbstractCheckerWithProblemPreferences implements ICIndexChecker {
private IFile file; private IFile file;
protected IIndex index; protected IIndex index;

View file

@ -21,9 +21,10 @@ import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementVisitor; import org.eclipse.cdt.core.model.ICElementVisitor;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.runtime.CoreException;
/** /**
* Example demonstrate how to write checked using "C Model"
*
* @author Alena * @author Alena
* *
*/ */
@ -44,16 +45,15 @@ public class NamingConventionFunctionIIndexChecker extends
final IProblem pt = getProblemById(ER_ID, getFile()); final IProblem pt = getProblemById(ER_ID, getFile());
try { try {
unit.accept(new ICElementVisitor() { unit.accept(new ICElementVisitor() {
public boolean visit(ICElement element) throws CoreException { public boolean visit(ICElement element) {
if (element.getElementType() == ICElement.C_FUNCTION) { if (element.getElementType() == ICElement.C_FUNCTION) {
String parameter = (String) pt.getPreference() String parameter = (String) pt.getPreference()
.getValue(); .getValue();
Pattern pattern = Pattern.compile(parameter); Pattern pattern = Pattern.compile(parameter);
String name = element.getElementName(); String name = element.getElementName();
if (!pattern.matcher(name).find()) { if (!pattern.matcher(name).find()) {
reportProblem(ER_ID, getFile(), 1, // TODO: line // TODO: line number
// number reportProblem(ER_ID, getFile(), 1, name, parameter);
name, parameter);
} }
return false; return false;
} }
@ -73,10 +73,10 @@ public class NamingConventionFunctionIIndexChecker extends
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
*/ */
public void initPreferences(IProblemWorkingCopy problem) { public void initPreferences(IProblemWorkingCopy problem) {
super.initPreferences(problem);
IProblemPreference info = new BasicProblemPreference(PARAM_KEY, IProblemPreference info = new BasicProblemPreference(PARAM_KEY,
"Name Pattern"); "Name Pattern");
info.setValue(DEFAULT_PATTERN); addPreference(problem, info, DEFAULT_PATTERN);
problem.setPreference(info);
} }
@Override @Override