Issue #1566: ReturnCount violation fixed for RequireThisCheck

This commit is contained in:
Ruslan Diachenko 2015-08-28 01:04:26 +01:00 committed by Roman Ivanov
parent 5a3f05ec80
commit 99ce97725c
1 changed files with 14 additions and 23 deletions

View File

@ -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);
}
}
}