Add additional test case to cover "var"
This commit is contained in:
@ -2135,7 +2135,8 @@ E.g. `int[] x = new int[] { 1, 2, 3 };` can be written as `int[] x = { 1, 2, 3 }
|
|||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value><![CDATA[
|
<value><![CDATA[
|
||||||
//VariableDeclarator
|
//(LocalVariableDeclaration[@TypeInferred = false()] | FieldDeclaration)
|
||||||
|
/VariableDeclarator
|
||||||
[VariableDeclaratorId[@ArrayType = true()]]
|
[VariableDeclaratorId[@ArrayType = true()]]
|
||||||
[VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/ArrayInitializer]
|
[VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/ArrayInitializer]
|
||||||
]]></value>
|
]]></value>
|
||||||
|
@ -77,6 +77,19 @@ public class UseShortArrayExample {
|
|||||||
private int[] f2 = new int[] {1,2,3}, f3 = new int[] { 4,5,6 };
|
private int[] f2 = new int[] {1,2,3}, f3 = new int[] { 4,5,6 };
|
||||||
|
|
||||||
private int[] good = { 1,2,3 };
|
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>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
Reference in New Issue
Block a user