mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
forbid type annotations on anonymous class creation with interface base class (IDEA-67598)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user