LocalVariableCouldBeFinal: Added property to allow ignoring variables declared in a for-each statement.

This commit is contained in:
Kristian Scheibe
2018-12-08 16:18:50 +01:00
parent e6ddfb9af3
commit c15ece60e2
2 changed files with 17 additions and 0 deletions

View File

@ -1127,6 +1127,9 @@ public interface MissingProperSuffix extends javax.ejb.EJBLocalObject {} // n
A local variable assigned only once can be declared final.
</description>
<priority>3</priority>
<properties>
<property name="ignoreForEachDecl" type="Boolean" description="Ignore non-final loop variables in a for-each statement." value="false"/>
</properties>
<example>
<![CDATA[
public class Bar {

View File

@ -175,4 +175,18 @@ public class Test {
}
]]></code>
</test-code>
<test-code>
<description>Parameter to ignore non-final variables in for each loops (see #1513).</description>
<rule-property name="ignoreForEachDecl">true</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void bar() {
for ( String c : strings ) {
System.out.println(c); // use c
}
}
}
]]></code>
</test-code>
</test-data>