accept intersection types in foreach stmts (IDEA-125800)

This commit is contained in:
Anna Kozlova
2014-06-02 20:13:55 +04:00
parent f1d927b6ea
commit b1b3b1db37
3 changed files with 19 additions and 0 deletions

View File

@@ -286,6 +286,14 @@ public class JavaGenericsUtil {
PsiType itemType = superClassSubstitutor.substitute(typeParameter);
return itemType == null ? PsiType.getJavaLangObject(manager, aClass.getResolveScope()) : itemType;
}
if (type instanceof PsiIntersectionType) {
for (PsiType conjunct : ((PsiIntersectionType)type).getConjuncts()) {
final PsiType itemType = getCollectionItemType(conjunct, scope);
if (itemType != null) {
return itemType;
}
}
}
return null;
}

View File

@@ -0,0 +1,10 @@
import java.util.List;
abstract class Test {
abstract <T extends List<String> & Runnable> T list();
public void test()
{
for (String s : list()) {}
}
}

View File

@@ -364,6 +364,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA119757() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA67578() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA57388() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA125800() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
//jdk should propagate LL 1.4 but actually it provides LL 1.7?!
public void testCastObjectToIntJdk14() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_4, false); }