From 99ce97725cd037d152c571e5ff58eac9247d072d Mon Sep 17 00:00:00 2001 From: Ruslan Diachenko Date: Fri, 28 Aug 2015 01:04:26 +0100 Subject: [PATCH] Issue #1566: ReturnCount violation fixed for RequireThisCheck --- .../checks/coding/RequireThisCheck.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheck.java index c655f5604..ad547b494 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheck.java @@ -158,31 +158,22 @@ public class RequireThisCheck extends AbstractDeclarationCollector { * @param parentType type of the parrent */ private void processField(DetailAST ast, int parentType) { - if (ScopeUtils.getSurroundingScope(ast) == null) { - // it is not a class or interface it's - // either import or package - // we shouldn't checks this - return; - } + final boolean importOrPackage = ScopeUtils.getSurroundingScope(ast) == null; + final boolean methodNameInMethodCall = parentType == TokenTypes.DOT + && ast.getPreviousSibling() != null; + final boolean typeName = parentType == TokenTypes.TYPE + || parentType == TokenTypes.LITERAL_NEW; - if (parentType == TokenTypes.DOT - && ast.getPreviousSibling() != null) { - // it's the method name in a method call; no problem - return; - } - if (parentType == TokenTypes.TYPE - || parentType == TokenTypes.LITERAL_NEW) { - // it's a type name; no problem - return; - } - if (isDeclarationToken(parentType)) { - // it's being declared; no problem - return; - } + if (!importOrPackage + && !methodNameInMethodCall + && !typeName + && !isDeclarationToken(parentType)) { - final String name = ast.getText(); - if (isClassField(name)) { - log(ast, MSG_VARIABLE, name); + final String name = ast.getText(); + + if (isClassField(name)) { + log(ast, MSG_VARIABLE, name); + } } }