Skip to content

Commit

Permalink
Issue #4727: fixed FinalLocalVariable scanning anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Jul 30, 2017
1 parent e77e2c8 commit 8fef906
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Expand Up @@ -210,7 +210,8 @@ public void visitToken(DetailAST ast) {
break;
case TokenTypes.VARIABLE_DEF:
if (ast.getParent().getType() != TokenTypes.OBJBLOCK
&& !ast.branchContains(TokenTypes.FINAL)
&& ast.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.FINAL) == null
&& !isVariableInForInit(ast)
&& shouldCheckEnhancedForLoopVariable(ast)) {
insertVariable(ast);
Expand Down
Expand Up @@ -254,4 +254,13 @@ public void testBreakOrReturn() throws Exception {
};
verify(checkConfig, getPath("InputFinalLocalVariableBreak.java"), expected);
}

@Test
public void testAnonymousClass() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(FinalLocalVariableCheck.class);
final String[] expected = {
"5:16: " + getCheckMessage(MSG_KEY, "testSupport"),
};
verify(checkConfig, getPath("InputFinalLocalVariableAnonymousClass.java"), expected);
}
}
@@ -0,0 +1,14 @@
package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;

public class InputFinalLocalVariableAnonymousClass {
public void test() {
Object testSupport = new Object() {
@Override
public String toString() {
final String dc = new String();
return dc;
}
};
testSupport.toString();
}
}

0 comments on commit 8fef906

Please sign in to comment.