[Codenarc-developer] SuppressWarnings refactoring (may effect IDE plugins)
Brought to you by:
chrismair
|
From: Hamlet D'A. <ham...@gm...> - 2011-09-10 09:16:20
|
Hi everyone,
This weekend I redesigned how the @SuppressWarnings annotations are
handled by CodeNarc. It may affect IDE support (but maybe not).
Previously, the @SuppressWarnings were handled by the
AbstractAstVisitor class. The problem with this is that not all rules
subclass this class, so not all rules respect @SuppressWarnings. Also,
a subclass could sometimes accidentally ignore the annotation. Also,
the old design made it difficult to support suppressions on parameters
and general expressions. The design has none of these problems and it
will perform better as well. Also, by removing the suppression
complexity from the visitors, it makes those classes more extensible.
Basically, it needs to be done for the two big features I have
planned: type inference and performance.
The new design moves the suppress warning functionality to a new
object: SuppressionAnalyzer. This object is invoked by any of the
other Analyzer objects, like FilesystemSourceAnalyzer and
DirectorySourceAnalyzer. If you have created a custom subclass of
Analyzer, then you need to update your code. If you have not created a
custom subclass then do nothing and be happy and quit reading!
If you have a custom analyzer, then your analyze(RuleSet):Results
object needs to change. Here is what a typical implementation should
look like:
Results analyze(RuleSet ruleSet) {
def allViolations = []
def suppressionService = new SuppressionAnalyzer(source)
ruleSet.rules.each { rule ->
if (!suppressionService.isRuleSuppressed(rule)) {
def violations = rule.applyTo(source)
violations.removeAll {
suppressionService.isViolationSuppressed(it) }
allViolations.addAll(violations)
}
}
new VirtualResults(allViolations)
}
You can see that you just need to create the SuppressionAnalyzer
object and then make sure it gets called correctly.
The code is not checked in yet, but I expect it to be checked in later today.
Thanks,
--
Hamlet D'Arcy
ham...@gm...
|