class literal checks for parameterized type/type parameter (IDEA-89726)

This commit is contained in:
Anna Kozlova
2012-09-13 17:53:31 +04:00
parent 5a6fdedb9a
commit 87a2c4818d
2 changed files with 33 additions and 5 deletions
@@ -1005,17 +1005,32 @@ public class GenericsHighlightUtil {
public static HighlightInfo checkClassObjectAccessExpression(PsiClassObjectAccessExpression expression) {
PsiType type = expression.getOperand().getType();
if (type instanceof PsiClassType) {
PsiClass aClass = ((PsiClassType)type).resolve();
if (aClass instanceof PsiTypeParameter) {
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
expression.getOperand(),
JavaErrorMessages.message("cannot.select.dot.class.from.type.variable"));
return canSelectFrom((PsiClassType)type, expression.getOperand());
} else if (type instanceof PsiArrayType) {
final PsiType arrayComponentType = type.getDeepComponentType();
if (arrayComponentType instanceof PsiClassType) {
return canSelectFrom((PsiClassType)arrayComponentType, expression.getOperand());
}
}
return null;
}
@Nullable
private static HighlightInfo canSelectFrom(PsiClassType type, PsiTypeElement operand) {
PsiClass aClass = type.resolve();
if (aClass instanceof PsiTypeParameter) {
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
operand,
JavaErrorMessages.message("cannot.select.dot.class.from.type.variable"));
} else if (type.getParameters().length > 0) {
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
operand,
"Cannot select from parameterized type");
}
return null;
}
@Nullable
public static HighlightInfo checkOverrideAnnotation(PsiMethod method) {
PsiModifierList list = method.getModifierList();
@@ -1,3 +1,4 @@
import java.lang.Object;
import java.util.*;
class C<T,U> {
@@ -125,4 +126,16 @@ class IDontCompile {
abstract class GenericTest99<E extends Enum<E>> {
GenericTest99<<error descr="Type parameter 'java.lang.Enum' is not within its bound; should extend 'java.lang.Enum<java.lang.Enum>'">Enum</error>> local;
}
class ClassLiteral<T> {
{
Object c1 = <error descr="Cannot select from a type variable">T</error>.class;
Object c2 = <error descr="Cannot select from a type variable">T[]</error>.class;
Object c3 = <error descr="Cannot select from parameterized type">List<String></error>.class;
Object c4 = <error descr="Cannot select from parameterized type">List<String>[]</error>.class;
Object c5 = List[].class;
Object c6 = List.class;
}
}