mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
- added interface method to distinguish fast checkers that can be run in editor as you type
This commit is contained in:
parent
ac758f71fb
commit
2c2bc88be9
4 changed files with 49 additions and 20 deletions
codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan
core/model
internal/core
|
@ -21,8 +21,8 @@ public abstract class AbstractChecker implements IChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if checker is enabled in context of resource, if returns false checker's "processResource"
|
* @return true if checker is enabled in context of resource, if returns
|
||||||
* method won't be called
|
* false checker's "processResource" method won't be called
|
||||||
*/
|
*/
|
||||||
public boolean enabledInContext(IResource res) {
|
public boolean enabledInContext(IResource res) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,28 +30,37 @@ public abstract class AbstractChecker implements IChecker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports a simple problem for given file and line
|
* Reports a simple problem for given file and line
|
||||||
* @param id - problem id
|
*
|
||||||
* @param file - file
|
* @param id
|
||||||
* @param lineNumber - line
|
* - problem id
|
||||||
* @param arg - problem argument, if problem does not define error message it will be error message
|
* @param file
|
||||||
* (not recommended because of internationalization)
|
* - 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)
|
||||||
*/
|
*/
|
||||||
public void reportProblem(String id, IFile file, int lineNumber,
|
public void reportProblem(String id, IFile file, int lineNumber, String arg) {
|
||||||
String arg) {
|
getProblemReporter().reportProblem(id,
|
||||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
new ProblemLocation(file, lineNumber), arg);
|
||||||
lineNumber), arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports a simple problem for given file and line, error message comes from problem definition
|
* Reports a simple problem for given file and line, error message comes
|
||||||
* @param id - problem id
|
* from problem definition
|
||||||
* @param file - file
|
*
|
||||||
* @param lineNumber - line
|
* @param id
|
||||||
|
* - problem id
|
||||||
|
* @param file
|
||||||
|
* - file
|
||||||
|
* @param lineNumber
|
||||||
|
* - line
|
||||||
*/
|
*/
|
||||||
public void reportProblem(String id, IFile file, int lineNumber) {
|
public void reportProblem(String id, IFile file, int lineNumber) {
|
||||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
getProblemReporter().reportProblem(id,
|
||||||
lineNumber), new Object[]{});
|
new ProblemLocation(file, lineNumber), new Object[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,4 +69,8 @@ public abstract class AbstractChecker implements IChecker {
|
||||||
protected IProblemReporter getProblemReporter() {
|
protected IProblemReporter getProblemReporter() {
|
||||||
return CodanRuntime.getInstance().getProblemReporter();
|
return CodanRuntime.getInstance().getProblemReporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean runInEditor() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,4 +90,8 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
||||||
new ProblemLocation(astFile, astLocation
|
new ProblemLocation(astFile, astLocation
|
||||||
.getStartingLineNumber()), message);
|
.getStartingLineNumber()), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean runInEditor() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,13 @@ public interface IChecker {
|
||||||
public boolean processResource(IResource resource);
|
public boolean processResource(IResource resource);
|
||||||
|
|
||||||
boolean enabledInContext(IResource resource);
|
boolean enabledInContext(IResource resource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checker must implement this method to determine if it can run in editor
|
||||||
|
* "as you type", checker must be really light weight to run in this mode
|
||||||
|
*
|
||||||
|
* @return true if need to be run in editor as user types, and false
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
|
boolean runInEditor();
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
||||||
IFile resource = resources[0];
|
IFile resource = resources[0];
|
||||||
IProblemReporter problemReporter = CodanRuntime.getInstance()
|
IProblemReporter problemReporter = CodanRuntime.getInstance()
|
||||||
.getProblemReporter();
|
.getProblemReporter();
|
||||||
|
// TODO: this is wrong - should not delete all markers -
|
||||||
|
// only those that contributed by the checker that we run now
|
||||||
if (problemReporter instanceof CodanMarkerProblemReporter) {
|
if (problemReporter instanceof CodanMarkerProblemReporter) {
|
||||||
((CodanMarkerProblemReporter) problemReporter)
|
((CodanMarkerProblemReporter) problemReporter)
|
||||||
.deleteMarkers(resource);
|
.deleteMarkers(resource);
|
||||||
|
@ -159,7 +161,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
||||||
boolean run = false;
|
boolean run = false;
|
||||||
if (checker.enabledInContext(resource))
|
if (checker.enabledInContext(resource))
|
||||||
run = true;
|
run = true;
|
||||||
if (run && checker instanceof ICAstChecker)
|
if (run && checker instanceof ICAstChecker
|
||||||
|
&& checker.runInEditor())
|
||||||
((ICAstChecker) checker).processAst(ast);
|
((ICAstChecker) checker).processAst(ast);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
CodanCorePlugin.log(e);
|
CodanCorePlugin.log(e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue