diff --git a/docs/checkstyle_checks.xml b/docs/checkstyle_checks.xml
index 4e1e2e509..2ca33529c 100644
--- a/docs/checkstyle_checks.xml
+++ b/docs/checkstyle_checks.xml
@@ -28,10 +28,12 @@
+
+
+
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodLengthCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodLengthCheck.java
index 1e9df6587..a462e09d1 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodLengthCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodLengthCheck.java
@@ -29,19 +29,19 @@ public class MethodLengthCheck extends Check
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
- if (aAST.getType() != TokenTypes.METHOD_DEF) {
- return;
- }
-
- DetailAST openingBrace = aAST.getLastChild();
- DetailAST closingBrace = openingBrace.getLastChild();
- int methodBodyStart = openingBrace.getLineNo();
- int methodBodyEnd = closingBrace.getLineNo();
- int length = methodBodyEnd - methodBodyStart + 1;
- if (length > mMax) {
- // TODO: This is old style but shouldn'r we use aAST.getLineNo() ?
- log(openingBrace.getLineNo(), "maxLen.method",
- new Integer(length), new Integer(mMax));
+ final DetailAST openingBrace = aAST.findFirstToken(TokenTypes.SLIST);
+ if (openingBrace != null) {
+ final DetailAST closingBrace =
+ openingBrace.findFirstToken(TokenTypes.RCURLY);
+ final int length =
+ closingBrace.getLineNo() - openingBrace.getLineNo() + 1;
+ if (length > mMax) {
+ log(aAST.getLineNo(),
+ aAST.getColumnNo(),
+ "maxLen.method",
+ new Integer(length),
+ new Integer(mMax));
+ }
}
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java
index a0d57429c..5c48104a6 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java
@@ -16,7 +16,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
-
package com.puppycrawl.tools.checkstyle;
import com.puppycrawl.tools.checkstyle.checks.MethodLengthCheck;
@@ -36,7 +35,18 @@ public class MethodLengthCheckTest extends BaseCheckTestCase
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSimple.java");
final String[] expected = {
- "80: Method length is 20 lines (max allowed is 19)."
+ "79:5: Method length is 20 lines (max allowed is 19)."
+ };
+ verify(c, fname, expected);
+ }
+
+ public void testAbstract() throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(MethodLengthCheck.class.getName());
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("InputModifier.java");
+ final String[] expected = {
};
verify(c, fname, expected);
}