generate method: insert Override when super method is accessible (IDEA-189949)

This commit is contained in:
Anna.Kozlova
2018-04-24 10:30:09 +02:00
parent e49f9e7d4c
commit 8437fb24b4
6 changed files with 33 additions and 1 deletions
@@ -719,7 +719,7 @@ public class GenerateMembersUtil {
if (JavaCodeStyleSettings.getInstance(targetClass.getContainingFile()).INSERT_OVERRIDE_ANNOTATION) {
PsiMethod superMethod = targetClass.findMethodBySignature(generated, true);
if (superMethod != null && superMethod.getContainingClass() != targetClass) {
if (superMethod != null && superMethod.getContainingClass() != targetClass && PsiUtil.isAccessible(superMethod, targetClass, null)) {
OverrideImplementUtil.annotateOnOverrideImplement(generated, targetClass, superMethod, true);
}
}
@@ -0,0 +1,5 @@
package a;
public class A {
int getFoo();
}
@@ -0,0 +1,13 @@
package b;
import a.A;
class B extends A {
int foo;
public int getFoo() {
return foo;
}
public void setFoo(int foo) {
this.foo = foo;
}
}
@@ -0,0 +1,5 @@
package a;
public class A {
int getFoo();
}
@@ -0,0 +1,5 @@
package b;
import a.A;
class B extends A {
int foo;
}
@@ -61,6 +61,10 @@ public class EncapsulateFieldsTest extends MultiFileTestCase {
doTest("i", "B.A", null);
}
public void testInaccessibleSuperMethod() {
doTest("foo", "b.B", null);
}
public void testHideOuterclassMethod() {
doTest("i", "A.B", "There is already a method <b><code>A.getI()</code></b> which would be hidden by generated getter");
}