FinalLocalVariable should check if variable is used in left side of assignment (bug 1241722)
This commit is contained in:
parent
b78fa7ddd8
commit
43fe1ad269
|
|
@ -138,7 +138,11 @@ public class FinalLocalVariableCheck extends Check
|
|||
|| (TokenTypes.BOR_ASSIGN == parentType)
|
||||
|| (TokenTypes.BAND_ASSIGN == parentType))
|
||||
{
|
||||
removeVariable(aAST);
|
||||
// TODO: is there better way to check is aAST
|
||||
// in left part of assignment?
|
||||
if (aAST.getParent().getFirstChild() == aAST) {
|
||||
removeVariable(aAST);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -141,3 +141,18 @@ class Blah
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class test_1241722
|
||||
{
|
||||
private Object o_;
|
||||
|
||||
public void doSomething(Object _o)
|
||||
{
|
||||
System.out.println(_o);
|
||||
}
|
||||
|
||||
public void doSomething2(Object _o1)
|
||||
{
|
||||
o_ = _o1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public class FinalLocalVariableCheckTest
|
|||
|
||||
final String[] expected = {
|
||||
"45:28: Variable 'aArg' should be declared final.",
|
||||
"149:36: Variable '_o' should be declared final.",
|
||||
"154:37: Variable '_o1' should be declared final.",
|
||||
};
|
||||
verify(checkConfig, getPath("coding/InputFinalLocalVariable.java"), expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@
|
|||
<li>Fixed problem with cache file (patch 1012389) thanks to
|
||||
Dave Wood.</li>
|
||||
|
||||
<li>Fixed example for FinalLocalVariable (bug 1241722)</li>
|
||||
<li>Fixed example for FinalLocalVariable snf the check itself
|
||||
(bug 1241722)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue