retrieve expected type by containing array creation expression (IDEA-132794)

This commit is contained in:
Anna Kozlova
2014-11-12 19:38:03 +01:00
parent fd9f90239d
commit b5a7fdbbf8
3 changed files with 22 additions and 0 deletions
@@ -215,6 +215,15 @@ public class PsiTypesUtil {
}
else if (PsiUtil.isCondition(methodCall, parent)) {
return PsiType.BOOLEAN.getBoxedType(parent);
}
else if (parent instanceof PsiArrayInitializerExpression) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiNewExpression) {
final PsiType type = ((PsiNewExpression)gParent).getType();
if (type instanceof PsiArrayType) {
return ((PsiArrayType)type).getComponentType();
}
}
}
return null;
}
@@ -0,0 +1,9 @@
class Test {
public <T> T f() {
return null;
}
public Object foo() {
return true ? new String[]{f()} : new String[][]{f()};
}
}
@@ -434,6 +434,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testExpectedTypeFromOuterArrayCreation() throws Exception {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
assertNotNull(collectionsClass);