diff --git a/pom.xml b/pom.xml index 919a27a76..c2e8418d6 100644 --- a/pom.xml +++ b/pom.xml @@ -851,14 +851,7 @@ .*.checks.regexp.RegexpSinglelineCheck10076 .*.checks.regexp.SinglelineDetector9396 - .*.checks.sizes.AnonInnerLengthCheck10092 - .*.checks.sizes.ExecutableStatementCountCheck8195 - .*.checks.sizes.LineLengthCheck10089 .*.checks.sizes.MethodCountCheck3123 - .*.checks.sizes.MethodLengthCheck10095 - .*.checks.sizes.OuterTypeNumberCheck7594 - .*.checks.sizes.ParameterNumberCheck10093 - .*.checks.whitespace.AbstractParenPadCheck88100 .*.checks.whitespace.EmptyForInitializerPadCheck9193 diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java index 28494d679..0e60a5534 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java @@ -172,18 +172,17 @@ public final class ExecutableStatementCountCheck // find member AST for the statement list final DetailAST contextAST = context.getAST(); DetailAST parent = ast.getParent(); - while (parent != null) { - final int type = parent.getType(); - if (type == TokenTypes.CTOR_DEF - || type == TokenTypes.METHOD_DEF - || type == TokenTypes.INSTANCE_INIT - || type == TokenTypes.STATIC_INIT) { - if (parent == contextAST) { - context.addCount(ast.getChildCount() / 2); - } - break; - } + int type = parent.getType(); + while (type != TokenTypes.CTOR_DEF + && type != TokenTypes.METHOD_DEF + && type != TokenTypes.INSTANCE_INIT + && type != TokenTypes.STATIC_INIT) { + parent = parent.getParent(); + type = parent.getType(); + } + if (parent == contextAST) { + context.addCount(ast.getChildCount() / 2); } } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheckTest.java index 269c67004..1e1e60870 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheckTest.java @@ -60,4 +60,14 @@ public class OuterTypeNumberCheckTest extends BaseCheckTestSupport { }; verify(checkConfig, getPath("InputSimple.java"), expected); } + + @Test + public void testWithInnerClass() throws Exception { + final DefaultConfiguration checkConfig = + createCheckConfig(OuterTypeNumberCheck.class); + checkConfig.addAttribute("max", "1"); + final String[] expected = { + }; + verify(checkConfig, getPath("OuterTypeNumberCheckInput.java"), expected); + } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/OuterTypeNumberCheckInput.java b/src/test/resources/com/puppycrawl/tools/checkstyle/OuterTypeNumberCheckInput.java new file mode 100644 index 000000000..3b505a680 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/OuterTypeNumberCheckInput.java @@ -0,0 +1,10 @@ +package com.puppycrawl.tools.checkstyle; + +/**Contains empty inner class for OuterTypeNumberCheckTest*/ +public class OuterTypeNumberCheckInput { + + /** Just empty inner class*/ + private class InnerClass { + // Do nothing + } +}