SuspiciousToArrayCallInspection: support parentheses

This commit is contained in:
Tagir Valeev
2018-11-18 15:36:27 +07:00
parent e2548785d1
commit 990ff8c7ba
2 changed files with 13 additions and 3 deletions
@@ -91,7 +91,8 @@ public class SuspiciousToArrayCallInspection extends BaseInspection {
if (arguments.length != 1) {
return;
}
final PsiExpression argument = arguments[0];
final PsiExpression argument = PsiUtil.skipParenthesizedExprDown(arguments[0]);
if (argument == null) return;
final PsiClassType classType = (PsiClassType)type;
final PsiClass aClass = classType.resolve();
@@ -77,16 +77,25 @@ public class SuspiciousToArrayCallInspectionTest extends LightInspectionTestCase
public void testStreams() {
doTest("import java.util.stream.Stream;\n" +
"class Test {\n" +
" {\n" +
" static {\n" +
" Stream.of(1.0, 2.0, 3.0).toArray(/*Array of type 'java.lang.Double[]' expected, 'java.lang.Integer[]' found*/Integer[]::new/**/);\n" +
" }\n" +
"}");
}
public void testStreamsParens() {
doTest("import java.util.stream.Stream;\n" +
"class Test {\n" +
" static {\n" +
" Stream.of(1.0, 2.0, 3.0).toArray(((/*Array of type 'java.lang.Double[]' expected, 'java.lang.Integer[]' found*/Integer[]::new/**/)));\n" +
" }\n" +
"}");
}
public void testStreamsIntersection() {
doTest("import java.util.stream.Stream;\n" +
"class Test {\n" +
" {\n" +
" static {\n" +
" Stream.of(1, 2.0, 3.0).toArray(/*Array of type 'java.lang.Number[]' expected, 'java.lang.Integer[]' found*/Integer[]::new/**/);\n" +
" }\n" +
"}");