Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Added Change Kotlin Package refactoring: use **Refactor → Change Kotlin Package...** for the active Kotlin file or a folder's recursive Kotlin descendants to update package directives in place; nested files retain their relative package hierarchy, supported Kotlin code references and direct imports update, and **Undo Last Refactoring** restores the original contents.
- Added Move Kotlin File and Directory refactoring: move the active `.kt` file from **Refactor → Move Kotlin File...**, or right-click a folder and choose **Move Kotlin Directory...** to recursively move its Kotlin files while retaining the selected directory and nested structure below a selected source root/package; matching package directives and supported Kotlin code references are updated, and **Undo Last Refactoring** restores the original locations and contents.
- Improved Kotlin Inline Variable: local `var` declarations with one initializer and no subsequent writes can now be inlined from either a declaration or selected usage; assignments and increment/decrement writes are rejected before changing the source with the conflicting expression identified.
- Improved Kotlin Introduce Type Alias: selecting a complete generic type now creates a concrete alias, while selecting only its type constructor creates a parameterized alias that preserves nested and qualified type structures and each same-file usage's own type arguments; star projections and local type parameters that cannot form a valid top-level alias are rejected.
Expand Down
2 changes: 1 addition & 1 deletion CoreImpl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-core-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinCompilerCliBase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-compiler-cli-base</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinFixesImpl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-fixes-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinFormatter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-formatter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinHighlighting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-highlighting</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinIcons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-icons</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion KotlinIntentionUtils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-intention-utils</artifactId>
Expand Down
52 changes: 48 additions & 4 deletions KotlinRefactoring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.nbplugins</groupId>
<artifactId>netbeans-plugin-kotlin</artifactId>
<version>0.11.245-SNAPSHOT</version>
<version>0.11.249-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-refactoring</artifactId>
Expand Down Expand Up @@ -751,9 +751,10 @@
KaMoveFileComputer invokes the K2 handler semantics through a lifecycle-free adapter.
Excluded: K2MoveHandler.kt (IDE action-system dispatch), ui/** (Swing dialog/model —
NB provides its own UI), K2MoveDirectoryWithClassesHelper.kt (generic filesystem move),
K2ChangePackageDescriptor.kt/K2ChangePackageRefactoringProcessor.kt (F4.2), and
K2MoveDeclarationsRefactoringListener.kt (message-bus event topic, stripped from the
declaration processor because no standalone listeners are subscribed). -->
and K2MoveDeclarationsRefactoringListener.kt (message-bus event topic, stripped from
the declaration processor because no standalone listeners are subscribed). F4.2 ports
K2ChangePackageDescriptor/K2ChangePackageRefactoringProcessor and strips only their
IDEA lifecycle wrapper after copying. -->
<execution>
<id>copy-kotlin-refactoring-move-k2-declarations</id>
<phase>initialize</phase>
Expand All @@ -770,6 +771,8 @@
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/descriptor/K2MoveSourceDescriptor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/descriptor/K2MoveTargetDescriptor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/descriptor/K2MoveOperationDescriptor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/descriptor/K2ChangePackageDescriptor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/processor/K2ChangePackageRefactoringProcessor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/processor/K2MoveDeclarationsRefactoringProcessor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/processor/K2MoveFilesOrDirectoriesRefactoringProcessor.kt</include>
<include>org/jetbrains/kotlin/idea/k2/refactoring/move/processor/moveUtil.kt</include>
Expand Down Expand Up @@ -1967,6 +1970,47 @@ if (k2MoveFilesProcessor.exists()) {
log.info("Patched K2MoveFilesOrDirectoriesRefactoringProcessor.kt: retained lifecycle-free K2MoveFilesHandler only")
}

// 16b. K2ChangePackageRefactoringProcessor.kt (F4.2): preserve the real IDEA K2 package-change
// algorithm while removing only BaseRefactoringProcessor's IDEA command, modal progress,
// conflict-dialog, usage-view, and event-listener lifecycle. KaChangePackageComputer supplies
// a per-file target package plan (needed for recursive NetBeans folder selection) and invokes
// this lifecycle-free port for its actual usage discovery, conflict check, package rewrite,
// declaration map, and retargeting sequence.
def k2ChangePackageProcessor = new File(srcDir, 'org/jetbrains/kotlin/idea/k2/refactoring/move/processor/K2ChangePackageRefactoringProcessor.kt')
if (k2ChangePackageProcessor.exists()) {
def text = k2ChangePackageProcessor.text
text = text.replace('import com.intellij.openapi.actionSystem.ex.ActionUtil\n', '')
text = text.replace('import com.intellij.openapi.util.Ref\n', '')
text = text.replace('import com.intellij.refactoring.BaseRefactoringProcessor\n', '')
text = text.replace('import com.intellij.refactoring.RefactoringBundle\n', '')
text = text.replace('import com.intellij.refactoring.listeners.RefactoringEventData\n', '')
text = text.replace('import com.intellij.usageView.UsageViewDescriptor\n', '')
text = text.replace('import com.intellij.util.containers.MultiMap\n', '')
text = text.replace('import com.intellij.refactoring.util.MoveRenameUsageInfo\n', '')
text = text.replace('import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt\n', '')
text = text.replace('import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt\n', '')
text = text.replace('import org.jetbrains.kotlin.idea.base.resources.KotlinBundle\n', '')
text = text.replace('class K2ChangePackageRefactoringProcessor(private val descriptor: K2ChangePackageDescriptor) : BaseRefactoringProcessor(descriptor.project) {',
'class K2ChangePackageRefactoringProcessor(private val descriptor: K2ChangePackageDescriptor) {')
def commandStart = text.indexOf(' override fun getCommandName()')
def findUsagesStart = text.indexOf(' protected override fun findUsages()')
if (commandStart >= 0 && findUsagesStart > commandStart) {
text = text.substring(0, commandStart) + text.substring(findUsagesStart)
}
text = text.replace(' protected override fun findUsages()', ' fun findUsages()')
def preprocessStart = text.indexOf(' protected override fun preprocessUsages(')
def performStart = text.indexOf(' @OptIn(KaAllowAnalysisOnEdt::class)\n override fun performRefactoring(')
if (preprocessStart >= 0 && performStart > preprocessStart) {
text = text.substring(0, preprocessStart) + text.substring(performStart)
}
text = text.replace(' @OptIn(KaAllowAnalysisOnEdt::class)\n override fun performRefactoring(usages: Array<out UsageInfo>) = allowAnalysisOnEdt {',
' fun findConflicts(usages: List<com.intellij.refactoring.util.MoveRenameUsageInfo>): com.intellij.util.containers.MultiMap<PsiElement, String> =\n findAllMoveConflicts(descriptor.files, descriptor.target, usages)\n\n fun prepareRefactoring(oldToNewMap: MutableMap<PsiElement, PsiElement>) {\n val files = descriptor.files\n files.forEach { it.updatePackageDirective(descriptor.target) }\n files.forEach { file ->\n oldToNewMap[file] = file\n file.declarations.filterIsInstance<org.jetbrains.kotlin.psi.KtNamedDeclaration>().forEach { declaration ->\n oldToNewMap[declaration] = declaration\n }\n }\n }\n\n fun retargetUsages(usages: Collection<UsageInfo>, oldToNewMap: Map<PsiElement, PsiElement>) {\n retargetUsagesAfterMove(usages.toList(), oldToNewMap)\n }\n\n fun performRefactoring(usages: Collection<UsageInfo>) {\n val oldToNewMap = linkedMapOf<PsiElement, PsiElement>()\n prepareRefactoring(oldToNewMap)\n retargetUsages(usages, oldToNewMap)\n }')
text = text.replace('\n\n override fun getBeforeData(): RefactoringEventData = RefactoringEventData().apply {\n addElements(descriptor.files)\n }', '')
text = text.replace(' val files = descriptor.files\n files.forEach { it.updatePackageDirective(descriptor.target) }\n val oldToNewMap: MutableMap<PsiElement, PsiElement> = files.associateWith { it }.toMutableMap()\n files.forEach { file -> file.allDeclarationsToUpdate.forEach { decl -> oldToNewMap[decl] = decl } }\n retargetUsagesAfterMove(usages.toList(), oldToNewMap)\n }', '')
k2ChangePackageProcessor.text = text
log.info("Patched K2ChangePackageRefactoringProcessor.kt: retained lifecycle-free upstream K2 semantic sequence")
}

// 17. K2MoveOperationDescriptor.kt (E9.7/F4.1): preserve the Files descriptor so its upstream
// source/target data model stays available to the lifecycle-free F4.1 adapter. The descriptor's
// refactoringProcessor() would construct the full IDEA MoveFilesOrDirectoriesProcessor, which
Expand Down
Loading
Loading