Add additional test case to cover "var"

This commit is contained in:
Andreas Dangel
2019-05-25 10:43:17 +02:00
parent 65f897e56d
commit d1044287c3
2 changed files with 15 additions and 1 deletions

View File

@ -2135,7 +2135,8 @@ E.g. `int[] x = new int[] { 1, 2, 3 };` can be written as `int[] x = { 1, 2, 3 }
<properties>
<property name="xpath">
<value><![CDATA[
//VariableDeclarator
//(LocalVariableDeclaration[@TypeInferred = false()] | FieldDeclaration)
/VariableDeclarator
[VariableDeclaratorId[@ArrayType = true()]]
[VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/ArrayInitializer]
]]></value>

View File

@ -77,6 +77,19 @@ public class UseShortArrayExample {
private int[] f2 = new int[] {1,2,3}, f3 = new int[] { 4,5,6 };
private int[] good = { 1,2,3 };
}
]]></code>
</test-code>
<test-code>
<description>array initialization with var</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class UseShortArrayExample {
public void foo() {
var ar1 = new int[] { 1, 2 };
//var ar2 = { 1, 2 }; // this is actually a compile-time error and is forbidden. See JLS 14.4.
}
}
]]></code>
</test-code>