type parameter referenced from static context error (IDEA-104160)

(cherry picked from commit ac98afef2ab67f2b548e6723e63b3b9752bf82f5)
This commit is contained in:
anna
2013-03-29 20:10:02 +01:00
parent 9641c94bd1
commit 7cb3c66d87
3 changed files with 22 additions and 0 deletions
@@ -964,6 +964,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (PsiTreeUtil.isAncestor(aClass, place, false) && aClass.hasTypeParameters()) {
myHolder.add(HighlightClassUtil.checkCreateInnerClassFromStaticContext(ref, place, (PsiClass)resolved));
}
} else if (resolved instanceof PsiTypeParameter) {
final PsiTypeParameterListOwner owner = ((PsiTypeParameter)resolved).getOwner();
if (owner instanceof PsiClass) {
final PsiClass outerClass = (PsiClass)owner;
if (!HighlightClassUtil.hasEnclosingInstanceInScope(outerClass, ref, true, false)) {
myHolder.add(HighlightClassUtil.reportIllegalEnclosingUsage(ref, aClass, (PsiClass)owner, ref));
}
}
}
}
@@ -0,0 +1,13 @@
import java.util.*;
class Test<T> {
public static void foo(<error descr="'Test.this' cannot be referenced from a static context">T</error> t) {}
public void bar(T t) {}
static class A extends ArrayList<<error descr="'Test.this' cannot be referenced from a static context">T</error>> {
static void boo(<error descr="'Test.this' cannot be referenced from a static context">T</error> t){}
}
class B extends ArrayList<T> {
void foo(T r){}
}
}
@@ -220,6 +220,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
}
public void testIDEA104100() {doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);}
public void testIDEA104160() {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()));