forked from JetBrains/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy: Support multiple classes in the same file
- Loading branch information
Showing
18 changed files
with
276 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
idea/src/org/jetbrains/kotlin/idea/refactoring/move/AutocreatingPsiDirectoryWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2010-2017 JetBrains s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.idea.refactoring.move | ||
|
||
import com.intellij.psi.PsiDirectory | ||
import com.intellij.refactoring.MoveDestination | ||
import org.jetbrains.kotlin.idea.core.getPackage | ||
|
||
sealed class AutocreatingPsiDirectoryWrapper { | ||
class ByPsiDirectory(val psiDirectory: PsiDirectory) : AutocreatingPsiDirectoryWrapper() { | ||
override fun getPackageName(): String = psiDirectory.getPackage()?.qualifiedName ?: "" | ||
override fun getOrCreateDirectory(source: PsiDirectory) = psiDirectory | ||
} | ||
|
||
class ByMoveDestination(val moveDestination: MoveDestination) : AutocreatingPsiDirectoryWrapper() { | ||
override fun getPackageName() = moveDestination.targetPackage.qualifiedName | ||
override fun getOrCreateDirectory(source: PsiDirectory) = moveDestination.getTargetDirectory(source) | ||
} | ||
|
||
abstract fun getPackageName(): String | ||
abstract fun getOrCreateDirectory(source: PsiDirectory): PsiDirectory | ||
} | ||
|
||
fun MoveDestination.toDirectoryWrapper() = AutocreatingPsiDirectoryWrapper.ByMoveDestination(this) | ||
fun PsiDirectory.toDirectoryWrapper() = AutocreatingPsiDirectoryWrapper.ByPsiDirectory(this) |
11 changes: 11 additions & 0 deletions
11
idea/testData/refactoring/copy/copyMultiClassFile/after/bar/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bar | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
} |
11 changes: 11 additions & 0 deletions
11
idea/testData/refactoring/copy/copyMultiClassFile/after/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package foo | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
} |
11 changes: 11 additions & 0 deletions
11
idea/testData/refactoring/copy/copyMultiClassFile/before/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package foo | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
} |
4 changes: 4 additions & 0 deletions
4
idea/testData/refactoring/copy/copyMultiClassFile/copyMultiClassFile.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"mainFile": "foo/test.kt", | ||
"targetPackage": "bar" | ||
} |
19 changes: 19 additions & 0 deletions
19
idea/testData/refactoring/copy/copyMultipleClassesToExistingFile/after/bar/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package bar | ||
|
||
import foo.B | ||
|
||
fun test() { | ||
|
||
} | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
19 changes: 19 additions & 0 deletions
19
idea/testData/refactoring/copy/copyMultipleClassesToExistingFile/after/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package foo | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
5 changes: 5 additions & 0 deletions
5
idea/testData/refactoring/copy/copyMultipleClassesToExistingFile/before/bar/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bar | ||
|
||
fun test() { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
idea/testData/refactoring/copy/copyMultipleClassesToExistingFile/before/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package foo | ||
|
||
class <caret>A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class <caret>C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
4 changes: 4 additions & 0 deletions
4
...refactoring/copy/copyMultipleClassesToExistingFile/copyMultipleClassesToExistingFile.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"mainFile": "foo/test.kt", | ||
"targetPackage": "bar" | ||
} |
15 changes: 15 additions & 0 deletions
15
idea/testData/refactoring/copy/copyMultipleClassesToNewFile/after/bar/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bar | ||
|
||
import foo.B | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
19 changes: 19 additions & 0 deletions
19
idea/testData/refactoring/copy/copyMultipleClassesToNewFile/after/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package foo | ||
|
||
class A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
19 changes: 19 additions & 0 deletions
19
idea/testData/refactoring/copy/copyMultipleClassesToNewFile/before/foo/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package foo | ||
|
||
class <caret>A { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class B { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} | ||
|
||
class <caret>C { | ||
val a: A = A() | ||
val b: B = B() | ||
val c: C = C() | ||
} |
Oops, something went wrong.