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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
- Fixed Kotlin package nodes under **Kotlin Source Packages** and **Kotlin Test Packages** retaining the standard **Refactor** submenu in the Projects window, so Rename opens **Rename Kotlin Package Directory...** for a non-empty Kotlin package; Java, resource, generated, empty, and non-Kotlin folders retain their existing handling, while package-tree headings are unchanged.
- Added Kotlin filesystem rename commands: choose **Refactor → Rename Kotlin File...** to rename the active `.kt` basename, or right-click a Kotlin-containing folder and choose **Rename Kotlin Package Directory...** to rename the physical directory and all descendants while preserving Kotlin package directives and code references; use **Change Kotlin Package...** for package/reference changes. **Undo Last Refactoring** restores original paths and text. Java file-facade, automatic-renamer, Java/comment/text/index-only, Unicode/quoted-name, and full IDEA project-model cases remain unavailable.
- Added Move Nested Member refactoring: choose **Refactor → Move Nested Member...** on a nested Kotlin class/object or a companion function/property, select a compatible target from a structured package/class tree, and apply the atomic source/target change; nested classes/objects can move into a target class/object without a body, which gains one automatically, while companion functions/properties require an existing companion object. **Undo Last Refactoring** restores both files. Instance members, import aliases, and unvalidated external qualified-use rewrites remain unavailable.
- Added Inline Anonymous Function/Lambda refactoring: place the caret in an immediately invoked Kotlin lambda or anonymous function, press **Ctrl+Alt+N** or choose **Refactor → Inline...**, preview the one-call rewrite, and apply the IntelliJ IDEA K2-generated substitution; **Undo Last Refactoring** restores the original document.
- Added separate Java and Kotlin package trees in Project Explorer: conventional `src/main/java` and `src/test/java` remain under **Source Packages** and **Test Packages**, while `src/main/kotlin` and `src/test/kotlin` appear under **Kotlin Source Packages** and **Kotlin Test Packages** in Maven, Gradle, and Ant/J2SE projects.
- Added Inline Type Alias refactoring: place the caret on a Kotlin `typealias` declaration or one of its type uses, press **Ctrl+Alt+N** or choose **Refactor → Inline...**, then expand every supported Kotlin occurrence or only the selected use and optionally retain the alias declaration; generic arguments, imports, and parenthesisation use the IntelliJ IDEA K2 engine, while **Undo Last Refactoring** restores all changed Kotlin files.
- 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.
- Improved Change Kotlin Package refactoring: **Refactor → Change Kotlin Package...** now opens from Kotlin package nodes as well as the active Kotlin file and reliably updates package directives in place for a file or its recursive Kotlin descendants; nested files retain their relative package hierarchy, supported Kotlin code references and direct imports update, physical paths remain unchanged, 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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-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.260-SNAPSHOT</version>
<version>0.11.280-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-intention-utils</artifactId>
Expand Down
49 changes: 46 additions & 3 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.260-SNAPSHOT</version>
<version>0.11.280-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-refactoring</artifactId>
Expand Down Expand Up @@ -1637,7 +1637,7 @@ if (extractableDescriptor.exists()) {
}

// 14. K2MoveRenameUsageInfo.kt: the IDEA Copy Declaration retargeting engine (E9.19).
// Three adaptations for standalone use:
// Four adaptations for standalone use:
// a. Drop the Java-reference `Light` path and the external-usage helpers
// (find/findExternalUsages/preProcessUsages). They pull in platform move handlers
// (MoveClassHandler/MoveMemberHandler/MoveMembersProcessor) and asJava light classes
Expand All @@ -1647,6 +1647,10 @@ if (extractableDescriptor.exists()) {
// (same as patch #1 for shortenUtils.kt).
// c. ProgressManager.getInstance().progressIndicator is null in the standalone container —
// fall back to an EmptyProgressIndicator so pushState()/text/fraction are no-ops.
// d. Standalone FIR can reject a shortening range containing local declarations with
// "ClassId should not be local" after usages have already been rebound. Retain the valid
// qualified reference for that known failure, but always remove the internal root prefix.
// Regression coverage: KaChangePackageTest.local-shortener fixture in the Nbm module.
def k2MoveUsage = new File(srcDir, 'org/jetbrains/kotlin/idea/k2/refactoring/move/processor/usages/K2MoveRenameUsageInfo.kt')
if (k2MoveUsage.exists()) {
def text = k2MoveUsage.text
Expand Down Expand Up @@ -1703,8 +1707,47 @@ if (k2MoveUsage.exists()) {
text = text.replace(' val mainReference = expr.mainReference\n',
' val mainReference = expr.references.filterIsInstance<KtReference>().firstOrNull() ?: return\n')

// e. K2's standalone reference shortener cannot establish a FIR designation for a range that
// contains local declarations (it throws "ClassId should not be local"). At this point
// Source.retarget has already rebound every affected reference in NO_SHORTENING mode, so the
// fully-qualified text is semantically correct. Keep that fallback narrow: only this known
// shortener exception is absorbed, while all other K2 failures still abort the refactoring.
// Root-prefix removal must run whether shortening succeeds or falls back, otherwise the
// internal IDE-resolution marker could be written to a user document.
text = text.replace(
''' if (file is KtFile) {
shortenReferences(usageMap.keys.filterIsInstance<KtElement>())
}
// There are some circumstances where the reference shortener does not shorten an expression we added the root prefix to.
// This can happen if the reference shortener is unable to add an import because the declaration's name is already
// being used in the target package.
// In these cases, we need to manually remove the added root prefix.
for (pointer in qualifiedExpressionPointers) {
val qualifiedExpression = pointer.element ?: continue
qualifiedExpression.removeRootPrefix()
}''',
''' try {
if (file is KtFile) {
try {
shortenReferences(usageMap.keys.filterIsInstance<KtElement>())
} catch (error: Throwable) {
if (error.message != "ClassId should not be local") throw error
}
}
} finally {
// There are some circumstances where the reference shortener does not shorten an expression we added the root prefix to.
// This can happen if the reference shortener is unable to add an import because the declaration's name is already
// being used in the target package.
// In these cases, we need to manually remove the added root prefix.
for (pointer in qualifiedExpressionPointers) {
val qualifiedExpression = pointer.element ?: continue
qualifiedExpression.removeRootPrefix()
}
}'''
)

k2MoveUsage.text = text
log.info("Patched K2MoveRenameUsageInfo.kt: dropped Light/external paths, analyze swap, null-safe progress")
log.info("Patched K2MoveRenameUsageInfo.kt: dropped Light/external paths, standalone shortener fallback, analyze swap, null-safe progress")
}

// 15. K2ReferenceMutateService is `internal`; make it public so the Nbm session can register it
Expand Down
2 changes: 1 addition & 1 deletion Nbm/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.260-SNAPSHOT</version>
<version>0.11.280-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>netbeans-plugin-kotlin-nbm</artifactId>
Expand Down
Loading
Loading