mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +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
|
@ -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"
|
||||
* method won't be called
|
||||
* @return true if checker is enabled in context of resource, if returns
|
||||
* false checker's "processResource" method won't be called
|
||||
*/
|
||||
public boolean enabledInContext(IResource res) {
|
||||
return true;
|
||||
|
@ -30,34 +30,47 @@ public abstract class AbstractChecker implements IChecker {
|
|||
|
||||
/**
|
||||
* Reports a simple problem for given file and line
|
||||
* @param id - problem id
|
||||
* @param 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)
|
||||
*
|
||||
* @param id
|
||||
* - problem id
|
||||
* @param 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)
|
||||
*/
|
||||
public void reportProblem(String id, IFile file, int lineNumber,
|
||||
String arg) {
|
||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
||||
lineNumber), arg);
|
||||
public void reportProblem(String id, IFile file, int lineNumber, String arg) {
|
||||
getProblemReporter().reportProblem(id,
|
||||
new ProblemLocation(file, lineNumber), arg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reports a simple problem for given file and line, error message comes from problem definition
|
||||
* @param id - problem id
|
||||
* @param file - file
|
||||
* @param lineNumber - line
|
||||
* Reports a simple problem for given file and line, error message comes
|
||||
* from problem definition
|
||||
*
|
||||
* @param id
|
||||
* - problem id
|
||||
* @param file
|
||||
* - file
|
||||
* @param lineNumber
|
||||
* - line
|
||||
*/
|
||||
public void reportProblem(String id, IFile file, int lineNumber) {
|
||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
||||
lineNumber), new Object[]{});
|
||||
getProblemReporter().reportProblem(id,
|
||||
new ProblemLocation(file, lineNumber), new Object[] {});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return problem reporter for given checker
|
||||
*/
|
||||
protected IProblemReporter 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
|
||||
.getStartingLineNumber()), message);
|
||||
}
|
||||
|
||||
public boolean runInEditor() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,13 @@ public interface IChecker {
|
|||
public boolean processResource(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];
|
||||
IProblemReporter problemReporter = CodanRuntime.getInstance()
|
||||
.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) {
|
||||
((CodanMarkerProblemReporter) problemReporter)
|
||||
.deleteMarkers(resource);
|
||||
|
@ -159,7 +161,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
|
|||
boolean run = false;
|
||||
if (checker.enabledInContext(resource))
|
||||
run = true;
|
||||
if (run && checker instanceof ICAstChecker)
|
||||
if (run && checker instanceof ICAstChecker
|
||||
&& checker.runInEditor())
|
||||
((ICAstChecker) checker).processAst(ast);
|
||||
} catch (Throwable e) {
|
||||
CodanCorePlugin.log(e);
|
||||
|
|
Loading…
Add table
Reference in a new issue