This commit is contained in:
parent
27537e9a0a
commit
dfef8ec6d8
|
|
@ -562,7 +562,7 @@ public class FinalLocalVariableCheck extends AbstractCheck {
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the Class, Constructor, Enum or Method in which it is defined.
|
||||
* Find the Class, Constructor, Enum, Method, or Field in which it is defined.
|
||||
* @param ast Variable for which we want to find the scope in which it is defined
|
||||
* @return ast The Class or Constructor or Method in which it is defined.
|
||||
*/
|
||||
|
|
@ -571,7 +571,9 @@ public class FinalLocalVariableCheck extends AbstractCheck {
|
|||
while (astTraverse.getType() != TokenTypes.METHOD_DEF
|
||||
&& astTraverse.getType() != TokenTypes.CLASS_DEF
|
||||
&& astTraverse.getType() != TokenTypes.ENUM_DEF
|
||||
&& astTraverse.getType() != TokenTypes.CTOR_DEF) {
|
||||
&& astTraverse.getType() != TokenTypes.CTOR_DEF
|
||||
&& (astTraverse.getType() != TokenTypes.VARIABLE_DEF
|
||||
|| !ScopeUtils.isClassFieldDef(astTraverse))) {
|
||||
astTraverse = astTraverse.getParent();
|
||||
}
|
||||
return astTraverse;
|
||||
|
|
|
|||
|
|
@ -160,7 +160,9 @@ public class FinalLocalVariableCheckTest
|
|||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(FinalLocalVariableCheck.class);
|
||||
checkConfig.addAttribute("tokens", "PARAMETER_DEF,VARIABLE_DEF");
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
final String[] expected = {
|
||||
"32:16: " + "Variable 'result' should be declared final.",
|
||||
};
|
||||
verify(checkConfig, getNonCompilablePath("InputFinalLocalVariableNameLambda.java"),
|
||||
expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,3 +25,12 @@ public class InputFinalLocalVariableNameLambda {
|
|||
(t, u) -> t.add(u.getAmount()));
|
||||
}
|
||||
}
|
||||
interface Operation {
|
||||
public Object apply();
|
||||
|
||||
public static final Operation OPERATION = () -> {
|
||||
Object result;
|
||||
result = null;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue