FinalLocalVariable should check if variable is used in left side of assignment (bug 1241722)

This commit is contained in:
Oleg Sukhodolsky 2005-07-21 13:25:13 +00:00
parent b78fa7ddd8
commit 43fe1ad269
4 changed files with 24 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -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>