Move/Copy: Fix 'protected' conflict reporting for references in super type entries

#KT-22678 Fixed
This commit is contained in:
Alexey Sedunov
2018-02-19 17:18:39 +03:00
parent 27f5ddcf83
commit 883558a4c7
19 changed files with 67 additions and 2 deletions
@@ -392,8 +392,12 @@ class MoveConflictChecker(
val targetVisibility = visibility.normalize()
if (targetVisibility == Visibilities.PUBLIC) return true
val referrer = ref.element.getStrictParentOfType<KtNamedDeclaration>()
val referrerDescriptor = referrer?.unsafeResolveToDescriptor() ?: return true
val refElement = ref.element
val referrer = refElement.getStrictParentOfType<KtNamedDeclaration>()
var referrerDescriptor = referrer?.resolveToDescriptorIfAny() ?: return true
if (referrerDescriptor is ClassDescriptor && refElement.getParentOfTypeAndBranch<KtSuperTypeListEntry> { typeReference } != null) {
referrerDescriptor.unsubstitutedPrimaryConstructor?.let { referrerDescriptor = it }
}
if (!isVisibleIn(referrerDescriptor)) return true
@@ -0,0 +1,3 @@
package bar
class Test2(name: String) : TestBase(name)
@@ -0,0 +1,3 @@
package foo
class Test(name: String) : TestBase(name)
@@ -0,0 +1,5 @@
package foo;
public class TestBase {
protected TestBase(final String test) {}
}
@@ -0,0 +1,3 @@
package foo
class <caret>Test(name: String) : TestBase(name)
@@ -0,0 +1,5 @@
package foo;
public class TestBase {
protected TestBase(final String test) {}
}
@@ -0,0 +1,5 @@
{
"mainFile": "foo/Test.kt",
"targetPackage": "bar",
"newName": "Test2"
}
@@ -0,0 +1,5 @@
package bar
import foo.TestBase
class Test(name: String) : TestBase(name)
@@ -0,0 +1,5 @@
package foo;
public class TestBase {
protected TestBase(final String test) {}
}
@@ -0,0 +1,3 @@
package foo
class <caret>Test(name: String) : TestBase(name)
@@ -0,0 +1,5 @@
package foo;
public class TestBase {
protected TestBase(final String test) {}
}
@@ -0,0 +1,5 @@
{
"mainFile": "foo/Test.kt",
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
"targetPackage": "bar"
}
@@ -211,6 +211,12 @@ public class CopyTestGenerated extends AbstractCopyTest {
doTest(fileName);
}
@TestMetadata("protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test")
public void testProtectedConstructorRefInSuperListEntry_ProtectedConstructorRefInSuperListEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test");
doTest(fileName);
}
@TestMetadata("refToImportJavaStaticField/refToImportedJavaStaticField.test")
public void testRefToImportJavaStaticField_RefToImportedJavaStaticField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/refToImportJavaStaticField/refToImportedJavaStaticField.test");
@@ -661,6 +661,12 @@ public class MoveTestGenerated extends AbstractMoveTest {
doTest(fileName);
}
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test")
public void testKotlin_moveTopLevelDeclarations_misc_protectedConstructorRefInSuperListEntry_ProtectedConstructorRefInSuperListEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test");
doTest(fileName);
}
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/protectedMembersExternalRefs/protectedMembersExternalRefs.test")
public void testKotlin_moveTopLevelDeclarations_misc_protectedMembersExternalRefs_ProtectedMembersExternalRefs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedMembersExternalRefs/protectedMembersExternalRefs.test");