LocalVariableCouldBeFinal: Added property to allow ignoring variables declared in a for-each statement.
This commit is contained in:
@ -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 {
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user