aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/checkstyle-extensions
diff options
context:
space:
mode:
authorfmallet <freddy.mallet@gmail.com>2010-09-20 13:43:04 +0000
committerfmallet <freddy.mallet@gmail.com>2010-09-20 13:43:04 +0000
commitbb32902cf66508fbdf2e3991fba329f557b5de4c (patch)
treea7b5082669bdede206ef8be0873204673da14fee /tests/integration/checkstyle-extensions
parent8a7e71bd6d156d83676f105e90482c88cfcd27b8 (diff)
downloadsonarqube-bb32902cf66508fbdf2e3991fba329f557b5de4c.tar.gz
sonarqube-bb32902cf66508fbdf2e3991fba329f557b5de4c.zip
fix Checkstyle extension implementation : MethodsCountCheck. A NullPointerException was thrown on files without java class definition.
Diffstat (limited to 'tests/integration/checkstyle-extensions')
-rw-r--r--tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java b/tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java
index c824851d524..b82a6a98d17 100644
--- a/tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java
+++ b/tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java
@@ -19,6 +19,11 @@ public class MethodsCountCheck extends Check {
return new int[]{TokenTypes.CLASS_DEF, TokenTypes.METHOD_DEF};
}
+ public void beginTree(DetailAST rootAST) {
+ methodsCount = 0;
+ classAST = null;
+ }
+
public void visitToken(DetailAST ast) {
//ensure this is an unit test.
if ( ast.getType() == TokenTypes.CLASS_DEF ) {
@@ -31,7 +36,7 @@ public class MethodsCountCheck extends Check {
public void finishTree(DetailAST rootAST) {
super.finishTree(rootAST);
- if (methodsCount < minMethodsCount) {
+ if (classAST != null && methodsCount < minMethodsCount) {
log(classAST.getLineNo(), classAST.getColumnNo(), "Too few methods (" + methodsCount + ") in class" );
}
}