can be final: ensure non final for base of anonymous class (IDEA-118493)

This commit is contained in:
Anna Kozlova
2013-12-20 16:53:03 +04:00
parent 90d256cf28
commit fb53d06dfd
4 changed files with 32 additions and 5 deletions
@@ -51,11 +51,7 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx {
((RefClassImpl)refClass).setFlag(false, CAN_BE_FINAL_MASK);
return;
}
if (refClass.isAbstract() || refClass.isAnonymous() || refClass.isInterface()) {
((RefClassImpl)refClass).setFlag(false, CAN_BE_FINAL_MASK);
return;
}
if (!refClass.isSelfInheritor(psiClass)) {
if (psiClass != null && !refClass.isSelfInheritor(psiClass)) {
for (PsiClass psiSuperClass : psiClass.getSupers()) {
if (myManager.belongsToScope(psiSuperClass)) {
RefClass refSuperClass = (RefClass)myManager.getReference(psiSuperClass);
@@ -65,6 +61,9 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx {
}
}
}
if (refClass.isAbstract() || refClass.isAnonymous() || refClass.isInterface()) {
((RefClassImpl)refClass).setFlag(false, CAN_BE_FINAL_MASK);
}
}
else if (refElement instanceof RefMethod) {
final RefMethod refMethod = (RefMethod)refElement;
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,22 @@
final class Test
{
public static class Foo
{
void fun()
{
}
}
public Foo get()
{
return new Foo()
{
@Override
void fun()
{
super.fun();
}
};
}
}
@@ -42,6 +42,10 @@ public class CanBeFinalTest extends InspectionTestCase {
doTest();
}
public void testanonymous() throws Exception {
doTest();
}
public void testmethodInheritance() throws Exception {
doTest();
}