From 044889b26a868b1b7200526ceeb40cdbe1e903fc Mon Sep 17 00:00:00 2001 From: Ruslan Diachenko Date: Wed, 26 Aug 2015 22:11:18 +0100 Subject: [PATCH] Issue #1566: partial fix of ReturnCount violations --- .../checkstyle/checks/imports/PkgControl.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgControl.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgControl.java index 27647b06b..c77b82207 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgControl.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgControl.java @@ -82,23 +82,23 @@ class PkgControl { * @return the finest match, or null if no match at all. */ PkgControl locateFinest(final String forPkg) { + PkgControl finestMatch = null; // Check if we are a match. - // This algormithm should be improved to check for a trailing "." + // This algorithm should be improved to check for a trailing "." // or nothing following. - if (!forPkg.startsWith(fullPackage)) { - return null; - } - - // Check if any of the children match. - for (PkgControl pc : children) { - final PkgControl match = pc.locateFinest(forPkg); - if (match != null) { - return match; + if (forPkg.startsWith(fullPackage)) { + // If there won't be match so I am the best there is. + finestMatch = this; + // Check if any of the children match. + for (PkgControl pc : children) { + final PkgControl match = pc.locateFinest(forPkg); + if (match != null) { + finestMatch = match; + break; + } } } - - // No match so I am the best there is. - return this; + return finestMatch; } /** @@ -112,16 +112,19 @@ class PkgControl { * @return an {@link AccessResult}. */ AccessResult checkAccess(final String forImport, final String inPkg) { + AccessResult result; final AccessResult retVal = localCheckAccess(forImport, inPkg); if (retVal != AccessResult.UNKNOWN) { - return retVal; + result = retVal; } - if (parent == null) { + else if (parent == null) { // we are the top, so default to not allowed. - return AccessResult.DISALLOWED; + result = AccessResult.DISALLOWED; } - - return parent.checkAccess(forImport, inPkg); + else { + result = parent.checkAccess(forImport, inPkg); + } + return result; } /**