check for abstract method implemented optimized: don't go through hierarchy if superClass is not abstract and there is no interfaces, would also fix asm implementations with 'broken' erasures inside

This commit is contained in:
Anna.Kozlova
2016-04-11 21:51:18 +02:00
parent 1466b0155e
commit fc14dddfd8
3 changed files with 22 additions and 0 deletions
@@ -20,6 +20,7 @@
package com.intellij.codeInsight;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,6 +47,10 @@ public class ClassUtil {
@Nullable
public static PsiMethod getAnyMethodToImplement(@NotNull PsiClass aClass) {
final PsiClass superClass = aClass instanceof PsiAnonymousClass ? PsiUtil.resolveClassInClassTypeOnly(((PsiAnonymousClass)aClass).getBaseClassType()) : aClass.getSuperClass();
if (superClass != null && !superClass.hasModifierProperty(PsiModifier.ABSTRACT) && aClass.getImplementsListTypes().length == 0) {
return null;
}
Set<PsiMethod> alreadyImplemented = new THashSet<PsiMethod>();
for (HierarchicalMethodSignature signatureHierarchical : aClass.getVisibleSignatures()) {
for (PsiMethod superS : signatureHierarchical.getMethod().findSuperMethods()) {
@@ -0,0 +1,14 @@
interface I {
void m();
}
<error descr="Class 'A' must either be declared abstract or implement abstract method 'm()' in 'I'">class A implements I</error> {}
class B extends A {}
class U {
{
new B() {};
B b = new B();
}
}
@@ -69,4 +69,7 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
public void testUnhandledErrorsFromEnumConstructors() {
doTest(true, false);
}
public void testSkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass() {
doTest(false, false);
}
}