mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
pull up conflicts: forbid to make package local method abstract (IDEA-56130)
This commit is contained in:
@@ -144,6 +144,8 @@ public class PullUpConflictsUtil {
|
||||
RefactoringConflictsUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList,
|
||||
new UsageInfo[0], targetRepresentativeElement, conflicts);
|
||||
for (final PsiMethod abstractMethod : abstractMethods) {
|
||||
final boolean toDifferentPackage =
|
||||
!Comparing.strEqual(targetPackage.getQualifiedName(), StringUtil.getPackageName(subclass.getQualifiedName()));
|
||||
abstractMethod.accept(new ClassMemberReferencesVisitor(subclass) {
|
||||
@Override
|
||||
protected void visitClassMemberReferenceElement(PsiMember classMember, PsiJavaCodeReferenceElement classMemberReference) {
|
||||
@@ -153,7 +155,7 @@ public class PullUpConflictsUtil {
|
||||
isAccessible = true;
|
||||
}
|
||||
else if (classMember.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) &&
|
||||
!Comparing.strEqual(targetPackage.getQualifiedName(), StringUtil.getPackageName(subclass.getQualifiedName()))) {
|
||||
toDifferentPackage) {
|
||||
isAccessible = true;
|
||||
}
|
||||
if (isAccessible) {
|
||||
@@ -167,6 +169,12 @@ public class PullUpConflictsUtil {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (abstractMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) && toDifferentPackage) {
|
||||
String message = "Can't make " + RefactoringUIUtil.getDescription(abstractMethod, false) +
|
||||
" abstract as it won't be accessible from the subclass.";
|
||||
message = CommonRefactoringUtil.capitalize(message);
|
||||
conflicts.putValue(abstractMethod, message);
|
||||
}
|
||||
}
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package a;
|
||||
|
||||
public abstract class Test {
|
||||
abstract void x();
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
package b;
|
||||
class E{}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package b;
|
||||
|
||||
import a.Test;
|
||||
|
||||
public class TestSubclass extends Test {
|
||||
@java.lang.Override void x() {
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package a;
|
||||
public class Test {
|
||||
void x() {
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
package b;
|
||||
class E{}
|
||||
@@ -54,6 +54,13 @@ public class ExtractSuperClassTest extends CodeInsightTestCase {
|
||||
new RefactoringTestUtil.MemberDescriptor("xx", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testConflictAbstractPackageLocalMethod() throws Exception {
|
||||
doTest("a.Test", "TestSubclass",
|
||||
new String[] {"Can't make method <b><code>x()</code></b> abstract as it won't be accessible from the subclass."},
|
||||
"b",
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class, true));
|
||||
}
|
||||
|
||||
public void testConflictUsingPackageLocalMethod() throws Exception {
|
||||
doTest("a.Test", "TestSubclass",
|
||||
new String[] {"method <b><code>Sup.foo()</code></b> won't be accessible"},
|
||||
|
||||
Reference in New Issue
Block a user