diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
commit | aeadc1f9129274949daaa57738c7c4550bdfbc7b (patch) | |
tree | 08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /tests/integration/checkstyle-extensions/src | |
download | sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip |
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'tests/integration/checkstyle-extensions/src')
-rw-r--r-- | tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java | 38 |
1 files changed, 38 insertions, 0 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 new file mode 100644 index 00000000000..c824851d524 --- /dev/null +++ b/tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java @@ -0,0 +1,38 @@ +package org.sonar.it.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.Check; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; + +public class MethodsCountCheck extends Check { + + private int minMethodsCount = 1; + + private int methodsCount = 0; + private DetailAST classAST = null; + + public void setMinMethodsCount(int minMethodsCount) { + this.minMethodsCount = minMethodsCount; + } + + public int[] getDefaultTokens() { + return new int[]{TokenTypes.CLASS_DEF, TokenTypes.METHOD_DEF}; + } + + public void visitToken(DetailAST ast) { + //ensure this is an unit test. + if ( ast.getType() == TokenTypes.CLASS_DEF ) { + classAST = ast; + + } else if ( ast.getType() == TokenTypes.METHOD_DEF ) { + methodsCount++; + } + } + + public void finishTree(DetailAST rootAST) { + super.finishTree(rootAST); + if (methodsCount < minMethodsCount) { + log(classAST.getLineNo(), classAST.getColumnNo(), "Too few methods (" + methodsCount + ") in class" ); + } + } +} |