summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java')
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java115
1 files changed, 100 insertions, 15 deletions
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
index f1e5028..411ba67 100644
--- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
+ * Copyright (c) 2009, 2010 Alena Laskavaia
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,12 +11,21 @@
package org.eclipse.cdt.codan.core.model;
import org.eclipse.cdt.codan.core.CodanRuntime;
+import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+/**
+ * Convenience implementation of IChecker interface. Has a default
+ * implementation for common methods.
+ *
+ */
public abstract class AbstractChecker implements IChecker {
protected String name;
+ /**
+ * Default constructor
+ */
public AbstractChecker() {
}
@@ -32,19 +41,38 @@ public abstract class AbstractChecker implements IChecker {
* Reports a simple problem for given file and line
*
* @param id
- * - problem id
+ * - problem id
* @param file
- * - file
+ * - file
* @param lineNumber
- * - line
- * @param arg
- * - problem argument, if problem does not define error message
- * it will be error message (not recommended because of
- * internationalization)
+ * - line
+ * @param args
+ * - problem arguments, if problem does not define error message
+ * it will be error message (not recommended because of
+ * internationalization)
*/
- public void reportProblem(String id, IFile file, int lineNumber, String arg) {
+ public void reportProblem(String id, IFile file, int lineNumber,
+ Object... args) {
getProblemReporter().reportProblem(id,
- new ProblemLocation(file, lineNumber), arg);
+ createProblemLocation(file, lineNumber), args);
+ }
+
+ /**
+ * Finds an instance of problem by given id, in user profile registered for
+ * specific file
+ *
+ * @param id
+ * - problem id
+ * @param file
+ * - file in scope
+ * @return problem instance
+ */
+ public IProblem getProblemById(String id, IResource file) {
+ IProblem problem = CheckersRegistry.getInstance()
+ .getResourceProfile(file).findProblem(id);
+ if (problem == null)
+ throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
+ return problem;
}
/**
@@ -52,15 +80,15 @@ public abstract class AbstractChecker implements IChecker {
* from problem definition
*
* @param id
- * - problem id
+ * - problem id
* @param file
- * - file
+ * - file
* @param lineNumber
- * - line
+ * - line
*/
public void reportProblem(String id, IFile file, int lineNumber) {
getProblemReporter().reportProblem(id,
- new ProblemLocation(file, lineNumber), new Object[] {});
+ createProblemLocation(file, lineNumber), new Object[] {});
}
/**
@@ -70,7 +98,64 @@ public abstract class AbstractChecker implements IChecker {
return CodanRuntime.getInstance().getProblemReporter();
}
+ /**
+ * Convenience method to return codan runtime
+ *
+ * @return
+ */
+ protected CodanRuntime getRuntime() {
+ return CodanRuntime.getInstance();
+ }
+
+ /**
+ * Convenience method to create and return instance of IProblemLocation
+ *
+ * @param file
+ * - file where problem is found
+ * @param line
+ * - line number 1-relative
+ * @return instance of IProblemLocation
+ */
+ protected IProblemLocation createProblemLocation(IFile file, int line) {
+ return getRuntime().getProblemLocationFactory().createProblemLocation(
+ file, line);
+ }
+
+ /**
+ * Convenience method to create and return instance of IProblemLocation
+ *
+ * @param file
+ * - file where problem is found
+ * @param startChar
+ * - start char of the problem in the file, is zero-relative
+ * @param endChar
+ * - end char of the problem in the file, is zero-relative and
+ * exclusive.
+ * @return instance of IProblemLocation
+ */
+ protected IProblemLocation createProblemLocation(IFile file, int startChar,
+ int endChar) {
+ return getRuntime().getProblemLocationFactory().createProblemLocation(
+ file, startChar, endChar);
+ }
+
+ /**
+ * Defines if checker should be run as user type in C editor. Override this
+ * method is checker is too heavy for that (runs too long)
+ */
public boolean runInEditor() {
- return false;
+ return this instanceof IRunnableInEditorChecker;
+ }
+
+ /**
+ * report a problem
+ *
+ * @param problemId - id of a problem
+ * @param loc - problem location
+ * @param args - extra problem arguments
+ */
+ public void reportProblem(String problemId, IProblemLocation loc,
+ Object... args) {
+ getProblemReporter().reportProblem(problemId, loc, args);
}
}