From faa8a0b7a427385fab564d2959244355f8d9813f Mon Sep 17 00:00:00 2001 From: Ilja Dubinin Date: Mon, 31 Aug 2015 16:44:14 +0100 Subject: [PATCH] Issue #46. Statements shouldn't be nested too deep --- .../checks/javadoc/JavadocMethodCheck.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java index 14cdf650f..506ec9d62 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java @@ -750,19 +750,8 @@ public class JavadocMethodCheck extends AbstractTypeAwareCheck { boolean found = removeMatchingParam(params, arg1); if (CommonUtils.startsWithChar(arg1, '<') && CommonUtils.endsWithChar(arg1, '>')) { - // Loop looking for matching type param - final Iterator typeParamsIt = typeParams.iterator(); - while (typeParamsIt.hasNext()) { - final DetailAST typeParam = typeParamsIt.next(); - if (typeParam.findFirstToken(TokenTypes.IDENT).getText() - .equals( - arg1.substring(1, - arg1.length() - 1))) { - found = true; - typeParamsIt.remove(); - break; - } - } + found = searchMatchingTypeParameter(typeParams, + arg1.substring(1, arg1.length() - 1)); } @@ -790,6 +779,31 @@ public class JavadocMethodCheck extends AbstractTypeAwareCheck { } } + /** + * Returns true if required type found in type parameters. + * @param typeParams + * list of type parameters + * @param requiredTypeName + * name of required type + * @return true if required type found in type parameters. + */ + private static boolean searchMatchingTypeParameter(List typeParams, + String requiredTypeName) { + // Loop looking for matching type param + final Iterator typeParamsIt = typeParams.iterator(); + boolean found = false; + while (typeParamsIt.hasNext()) { + final DetailAST typeParam = typeParamsIt.next(); + if (typeParam.findFirstToken(TokenTypes.IDENT).getText() + .equals(requiredTypeName)) { + found = true; + typeParamsIt.remove(); + break; + } + } + return found; + } + /** * Remove parameter from params collection by name. * @param params collection of DetailAST parameters