From aeadc1f9129274949daaa57738c7c4550bdfbc7b Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 6 Sep 2010 14:08:06 +0000 Subject: SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console --- .../org/sonar/it/checkstyle/MethodsCountCheck.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/integration/checkstyle-extensions/src/main/java/org/sonar/it/checkstyle/MethodsCountCheck.java (limited to 'tests/integration/checkstyle-extensions/src') 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" ); + } + } +} -- cgit v1.2.3