From 883558a4c7cb0a7d2b4e89dd4160f67a205b1eb1 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Mon, 19 Feb 2018 17:18:39 +0300 Subject: [PATCH] Move/Copy: Fix 'protected' conflict reporting for references in super type entries #KT-22678 Fixed --- .../move/moveDeclarations/moveConflictUtils.kt | 8 ++++++-- .../after/bar/Test2.kt | 3 +++ .../after/bar/dummy.txt | 0 .../after/foo/Test.kt | 3 +++ .../after/foo/TestBase.java | 5 +++++ .../before/bar/dummy.txt | 0 .../before/foo/Test.kt | 3 +++ .../before/foo/TestBase.java | 5 +++++ .../protectedConstructorRefInSuperListEntry.test | 5 +++++ .../after/bar/Test.kt | 5 +++++ .../after/bar/dummy.txt | 0 .../after/foo/Test.kt | 2 ++ .../after/foo/TestBase.java | 5 +++++ .../before/bar/dummy.txt | 0 .../before/foo/Test.kt | 3 +++ .../before/foo/TestBase.java | 5 +++++ .../protectedConstructorRefInSuperListEntry.test | 5 +++++ .../kotlin/idea/refactoring/copy/CopyTestGenerated.java | 6 ++++++ .../kotlin/idea/refactoring/move/MoveTestGenerated.java | 6 ++++++ 19 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/Test2.kt create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/Test.kt create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/Test.kt create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java create mode 100644 idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/Test.kt create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/Test.kt create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/Test.kt create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java create mode 100644 idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt index 20bb6505266..07649317f6b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt @@ -392,8 +392,12 @@ class MoveConflictChecker( val targetVisibility = visibility.normalize() if (targetVisibility == Visibilities.PUBLIC) return true - val referrer = ref.element.getStrictParentOfType() - val referrerDescriptor = referrer?.unsafeResolveToDescriptor() ?: return true + val refElement = ref.element + val referrer = refElement.getStrictParentOfType() + var referrerDescriptor = referrer?.resolveToDescriptorIfAny() ?: return true + if (referrerDescriptor is ClassDescriptor && refElement.getParentOfTypeAndBranch { typeReference } != null) { + referrerDescriptor.unsubstitutedPrimaryConstructor?.let { referrerDescriptor = it } + } if (!isVisibleIn(referrerDescriptor)) return true diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/Test2.kt b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/Test2.kt new file mode 100644 index 00000000000..dbb9625ad85 --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/Test2.kt @@ -0,0 +1,3 @@ +package bar + +class Test2(name: String) : TestBase(name) \ No newline at end of file diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/Test.kt b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/Test.kt new file mode 100644 index 00000000000..6a296225cfd --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/Test.kt @@ -0,0 +1,3 @@ +package foo + +class Test(name: String) : TestBase(name) \ No newline at end of file diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java new file mode 100644 index 00000000000..163b3cabda4 --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java @@ -0,0 +1,5 @@ +package foo; + +public class TestBase { + protected TestBase(final String test) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/Test.kt b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/Test.kt new file mode 100644 index 00000000000..801e811c444 --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/Test.kt @@ -0,0 +1,3 @@ +package foo + +class Test(name: String) : TestBase(name) \ No newline at end of file diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java new file mode 100644 index 00000000000..163b3cabda4 --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java @@ -0,0 +1,5 @@ +package foo; + +public class TestBase { + protected TestBase(final String test) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test new file mode 100644 index 00000000000..646cf1ab6f3 --- /dev/null +++ b/idea/testData/refactoring/copy/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test @@ -0,0 +1,5 @@ +{ + "mainFile": "foo/Test.kt", + "targetPackage": "bar", + "newName": "Test2" +} diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/Test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/Test.kt new file mode 100644 index 00000000000..6436d5fcd78 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/Test.kt @@ -0,0 +1,5 @@ +package bar + +import foo.TestBase + +class Test(name: String) : TestBase(name) \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/bar/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/Test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/Test.kt new file mode 100644 index 00000000000..d1b1429cb4d --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/Test.kt @@ -0,0 +1,2 @@ +package foo + diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java new file mode 100644 index 00000000000..163b3cabda4 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/after/foo/TestBase.java @@ -0,0 +1,5 @@ +package foo; + +public class TestBase { + protected TestBase(final String test) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/bar/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/Test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/Test.kt new file mode 100644 index 00000000000..801e811c444 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/Test.kt @@ -0,0 +1,3 @@ +package foo + +class Test(name: String) : TestBase(name) \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java new file mode 100644 index 00000000000..163b3cabda4 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/before/foo/TestBase.java @@ -0,0 +1,5 @@ +package foo; + +public class TestBase { + protected TestBase(final String test) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test new file mode 100644 index 00000000000..460039ae6ee --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/protectedConstructorRefInSuperListEntry/protectedConstructorRefInSuperListEntry.test @@ -0,0 +1,5 @@ +{ + "mainFile": "foo/Test.kt", + "type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS", + "targetPackage": "bar" +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/copy/CopyTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/copy/CopyTestGenerated.java index c4c71878d54..9db0e85d772 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/copy/CopyTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/copy/CopyTestGenerated.java @@ -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"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java index 96f98d3e490..7ff6e34d60a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java @@ -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");