forbid type annotations on anonymous class creation with interface base class (IDEA-67598)

This commit is contained in:
anna
2012-10-23 17:10:47 +02:00
parent 0dfb29db51
commit c8f56fcb28
3 changed files with 19 additions and 0 deletions

View File

@@ -1236,6 +1236,12 @@ public class HighlightMethodUtil {
}
if (classReference != null && aClass.hasModifierProperty(PsiModifier.PROTECTED) && callingProtectedConstructorFromDerivedClass(constructorCall, aClass)) {
holder.add(buildAccessProblem(classReference, typeResolveResult, aClass));
} else if (aClass.isInterface() && constructorCall instanceof PsiNewExpression) {
final PsiReferenceParameterList typeArgumentList = ((PsiNewExpression)constructorCall).getTypeArgumentList();
if (typeArgumentList.getTypeArguments().length > 0) {
holder.add(HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeArgumentList,
"Anonymous class implements interface; cannot have type arguments"));
}
}
}
else {

View File

@@ -0,0 +1,12 @@
class C
{
Object x = new <error descr="Anonymous class implements interface; cannot have type arguments"><Integer></error> D() { };
Object x1 = new <Integer> P() { };
Object x2 = new <Integer> U() { };
Object x3 = new <error descr="Anonymous class implements interface; cannot have type arguments"><Integer></error> I() { };
interface D{}
abstract class P {}
}
interface I {}
class U {}

View File

@@ -155,6 +155,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testContinueInferenceAfterFirstRawResult() throws Exception { doTest(false); }
public void testStaticOverride() throws Exception { doTest(false); }
public void testTypeArgumentsGivenOnRawType() throws Exception { doTest(false); }
public void testTypeArgumentsGivenOnAnonymousClassCreation() throws Exception { doTest(false); }
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));