detect array initializer type based on short variable array notation (IDEA-147881)

This commit is contained in:
Anna Kozlova
2015-11-13 16:07:17 +01:00
parent e1f9d33a32
commit cbbd0e4456
3 changed files with 16 additions and 0 deletions
@@ -218,6 +218,12 @@ public class PsiTypesUtil {
return ((PsiArrayType)type).getComponentType();
}
}
else if (gParent instanceof PsiVariable) {
final PsiType type = ((PsiVariable)gParent).getType();
if (type instanceof PsiArrayType) {
return ((PsiArrayType)type).getComponentType();
}
}
else if (gParent instanceof PsiArrayInitializerExpression) {
final PsiType expectedTypeByParent = getExpectedTypeByParent((PsiExpression)parent);
return expectedTypeByParent != null && expectedTypeByParent instanceof PsiArrayType
@@ -0,0 +1,6 @@
class Test {
{
Object x = null;
Object[] objs = {x == null ? "N/A" : x};
}
}
@@ -877,4 +877,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testUncheckedWarningsWhenInferredTypeLeadsToRawRoGenericAssignment() throws Exception {
doTest(true);
}
public void testExpectedTypeBasedOnArrayCreationWithoutExplicitType() throws Exception {
doTest();
}
}