The issues here are taken from the query project: Kotlin State: -Fixed,-Duplicate,-Rejected,-{As Designed},-Obsolete type: Feature,{Feature Group} refactoring.
For any Feature Groups child issues were added.
I extracted a summary from the issue and placed it here for convenience. If you find the summary relevant to your needs, please follow the issue link and vote the issue up. If there is an issue that is missing please open it on YouTrack and add a comment with a link to it here.
Kotlin YouTrack Refactoring Issues
Â
KT-15679 - Rename refactoring for header/impl interface/class/function/typealias
Rename refactoring for header/impl should work at header or impl side for:
-
interface
-
class
-
function
-
type alias
Â
Â
KT-15638 - Extract Interface/Superclass: suggest to search and update usages of refactored class (like for Java)
Dummy Kotlin:
class SelfRef {
fun refer(p: SelfRef) {}
}
Extract Interface/Superclass, select refer() , get the result.
Now implemented interface/parent class refers to implementing/child class.
In Java after the same refactorings IDEA suggests to search usages and change them to interface/parent class, when possible.
NB: this occurs NOT only for self-references, but for any.
The same could be implemented in Kotlin.
Â
Â
KT-14272 - Support Move function refactoring when instance is not captured
class Test {
fun can_be_global(): Int = 3
}
Â
Â
KT-13623 - Enhancement for Quick fix: while in a apply-style block, offer âCreate member functionâ without âthis.â and similarly allow âExtract Methodâ refactoring
class SomeClass () {
}
fun main(args: Array<String>) {
SomeClass().apply {
this.newMethod1("abc") //Quick fix "Create member function" is offered
newMethod2("abc") //Quick fix "Create member function" is currently not offered. The user
// is forced to put "this." in to achieve the desired
// effect of creating a new SomeClass method
println(123)//when selecting this expression, Extract Method (to "applied" class SomeClass)
// is not currently offered (currently only extract function is offered)
}
}
Â
Â
KT-13436 - Replace âwhenâ with return: handle case when all branches jump out (return Nothing)
Example:
fun test(a: Int): String {
when (a) {
0 -> return "No"
1 -> return "Yes"
else -> TODO("hmmm?")
}
}
Here expression in else branch returns Nothing , so itâs safe to refactor this code to:
fun test(a: Int): String {
return when (a) {
0 -> "No"
1 -> "Yes"
else -> TODO("hmmm?")
}
}
which will allow to convert this function to expression body.
Â
Â
KT-13309 - Create field from local variable intention/refactoring
This should be allowed to do via âIntroduce property refactoringâ and/or an intention
class A {
fun foo(p: String) {
val <caret>x = p.length //I want to turn this local variable to a field/property
}
}
The refactoring should generate something like this:
class A {
val x: Int //I think `var` declaration should not be forced here
fun foo(p: String) {
x = p.length
}
}
Â
Â
KT-12740 - Refactor / Rename element with @JvmName: element name is suggested as current value, while the change is applied to annotation
Dummy Kotlin:
KotlinFile.kt
class Access {
@get:JvmName("getObject")
@set:JvmName("setObject")
var subject: Int = 0
}
@JvmName("filterValidString")
fun List<String>.filterValid(): List<String> { return this }
Java usage:
public class JavaUser {
public void use(Access p1, List<String> p2) {
int v = p1.getObject();
p1.setObject(v);
KotlinFileKt.filterValidString(p2);
}
}
Call Refactor / Rename (Shift+F6) on getObject() , setObject() , filterValidString() .
The dialog suggests subject and filterValid as current names. Thatâs the issue. It should suggest annotation values.
On applying Rename the annotation value is changed, not the element name (expected).
NB: on calling Rename for the value of @file:JvmName() annotation it suggests annotation value, so itâs Ok.
Â
Â
KT-12727 - Rename only one directory presenting package: FQN in text file is lost
Set up a module with the following structure:
âŠ/module-content-root/source-root-1/pack1/SubjectJava.kt with SubjectJava class.
âŠ/module-content-root/source-root-1/pack1/SubjectKotlin.kt with SubjectKotlin class.
âŠ/module-content-root/source-root-1/pack2/Ref.txt
âŠ/module-content-root/source-root-2/pack1/Weight.kt
Ref.txt has the content with classes FQNs:
pack1.SubjectJava
pack1.SubjectKotlin
In the Project tool window select pack1 in source root 1. Refactor / Rename (Shift+F6).
Youâll be asked, what to rename, the whole package or only the directory. Select only one directory.
In the dialog ask to search for text occurrences. Go on.
Result: in the text file Java FQN is preserved, Kotlin FQN is lost:
pack1ren.SubjectJava
SubjectKotlin
NB: no problem in case of renaming the whole package.
Â
Â
KT-12713 - Either/ Result to handle errors without exceptions
Â
Â
KT-12348 - Rename class refactoring: propose to rename usages in comments
Â
Â
KT-12162 - Refactor / Rename Java bean property from Kotlin: field name could be kept in sync with accessors
Provide a Java bean with a property:
public class Bean {
private String prop = "value";
public String getProp() { return prop; }
public void setProp(String prop) { this.prop = prop; }
}
Provide a usage in Kotlin code:
fun context(bean: Bean) {
bean.prop = "a"
println(bean.prop)
}
Try to Refactor / Rename (Shift+F6) java property from the reference in .kt file.
All goes Ok, but in Java code only accessors are changed. The field name is still prop .
Would be better to rename it accordingly?
Â
Â
KT-11883 - IntelliJ - Extract Variable refactoring - Specify type explicitly by default
I havenât found a way to configure that I need âspecify type explicitlyâ checkbox to be set by default on Extract Variable refactoring.
Â
Â
KT-11050 - âExtract constantâ refactoring
It is useful to have the refactoring which creates âvalâ property in companion object.
Relates to: KT-4938
Subtask of: KT-4728
Â
Â
KT-10346 - Support ||
in when conditions in âIntroduce subjectâ intention
Comma-separated conditions for when without argument are prohibited.
So, instead of
when {
x is A, x is B -> println("A or B")
}
we have
when {
x is A || x is B -> println("A or B")
}
However, this is not supported in âIntroduce subjectâ intention action for when . Ideally it should be something like âtreat || arguments as separate or-ed conditions when determining applicability and introducing when subjectâ, so the example above should be refactored into:
when (x) {
is A, is B -> println("A or B")
}
Â
Â
KT-9941 - Unwrap does nothing when called from a companion object
class Test {
companion object {
<cursor> val v = "";
}
}
- Invoke âUnwrapâ.
Expected:
class Test {
val v = "";
}
Actual: no changes.
Rather inconvenient especially after converting Java to Kotlin when all statics are converted to members of the companion object.
Â
Â
KT-9851 - Create âExtract/Introduce lateinit varâ Refactoring
Iâm looking for the Kotlin equivalent refactoring to https://www.jetbrains.com/idea/help/extract-field.html, for example:
//Before
class MyClass() : SomeLibrary {
override fun someLibraryInitMethod() {
var theSomething = newSomething()
}
private fun useTheSomethingLater() {
theSomething.doSomething() // is in error since theSomething isn't in scope
}
}
becomes (after putting cursor on âtheSomethingâ and selecting âExtract âŠâ)
//After
class MyClass() {
private lateinit var something : Something
override fun someLibraryInitMethod() {
theSomething = newSomething()
}
private fun useTheSomethingLater() {
theSomething.doSomething() //now not in error
}
}
Â
Â
KT-9822 - Inline should provide label inside lambda
Inlining the val toDigest
fun String.toSha1():String {
val toDigest = this
val digest = with(MessageDigest.getInstance("SHA-1")) {
update(toDigest.toByteArray("UTF-8"))
digest()
}
return BigInteger(1, digest).toString(16)
}
produces
fun String.toSha1():String {
val digest = with(MessageDigest.getInstance("SHA-1")) {
update(this.toByteArray("UTF-8"))
digest()
}
return BigInteger(1, digest).toString(16)
}
witch is false.
It should produce
fun String.toSha1():String {
val digest = with(MessageDigest.getInstance("SHA-1")) {
update(this@toSha1.toByteArray("UTF-8"))
digest()
}
return BigInteger(1, digest).toString(16)
}
Â
Â
KT-9748 - Rename function may change semantics of the code when overload with default parameters exist
class C {
fun foo() {
bar()
}
fun bar(p: Int = 0) {
}
}
Rename âfooâ to âbarâ or âbarâ to âfooâ. Semantics of the function âfooâ body is changed so that it calls itself.
Â
Â
KT-9383 - Refactor / Rename: inconsistent update of annotation references with use-site targets
Provide usages of annotation with use-site targets:
annotation class AnnTarget
class Dummy(@field:AnnTarget val pf: Int,
@get:AnnTarget val pg: Int,
@set:AnnTarget var ps: Int,
@param:AnnTarget var pp: Int)
Close the project, reopen the project and file.
The source looks correct. All AnnTarget entries are dark-blue, Quick Doc (Ctrl+Q) works on them. Ok.
Refactor / Rename AnnTarget to something, AnnTarget2 . Wait for analysis to complete.
One stable effect is that all entries are still dark-blue, while @field:AnnTarget2 is black. Why is that?
But there are other effects, that occurred only once for me (out of 5-6 attempts):
- One time entries in @get: and @set: have not been renamed.
- One time Quick Doc said âNo documentation foundâ for @field:AnnTarget2 .
- One time Ctrl+B said âCannot find declarationâ for @field:AnnTarget2 .
Â
Â
KT-9212 - Inline rename for method parameters
Â
Â
KT-9054 - Copy / pasting a Kotlin file should bring up the Copy Class dialog
In Java, if you have a class you want to duplicate, you can just select the file in the Project toolbar and press CTRL-C, CTRL-V it. It brings up the âCopy Classâ dialog which is so easy to use.
In Kotlin, it asks me to specify a new directory, and if I try to keep the directory the same, it treats that as an error. So I canât just copy / paste it quickly anymore.
Â
Â
KT-8980 - Renaming constructor parameter is very slow
For example, create a class with constructor parameter (not even val!) named âelementâ. Renaming it takes quite some time.
Â
Â
KT-8954 - Refactor / Copy could have âUpdate package directiveâ option
Invoke Refactor / Move for a .kt file, check the dialog: there is âUpdate package directiveâ option.
Invoke Refactor / Copy for the same file, check the dialog: there is no such option.
Actually it may be useful on copy to different directory.
Â
Â
KT-8563 - Refactor / Rename inserts line breaks without reason
Create sample Kotlin class like:
public class OneLineKotlin {
var subject = 1
var aux = 1
public fun simple0() { subject }
public fun simple1() { subject = 2 }
public fun simple2() { aux = subject }
}
Refactor / Rename subject to, say subject2 . Result:
public class OneLineKotlin {
var subject2 = 1
var aux = 1
public fun simple0() {
subject2
}
public fun simple1() { subject2 = 2 }
public fun simple2() { aux = subject2
}
}
Why the line breaks are added?
Itâs not the fully formatted code, otherwise every function body would get line breaks, while this result is different.
Probably no âformattingâ or line breaks inserting should be done.
Â
Â
KT-8545 - Rename: in-place mode could be supported for Kotlin
Settings / ⊠/ Editor / General / Refactorings / Enable in-place mode = Yes.
Call Rename (Shift+F6) on a Java class, field, method: itâs in-place.
Call Rename on a Kotlin class, property, function: the dialog is still shown.
Â
Â
KT-8514 - Refactor / Rename: âRename variablesâ option could be supported for object declaration
Declare an object, like:
public object ObjectA {
fun objectContent() { println("Inside an object.") }
}
fun main(args: Array<String>) {
val objectA = ObjectA
objectA.objectContent()
}
Call Refactor / Rename on the object name: there is no âRename variablesâ option in the dialog.
In general, a variable can exist, like in the example.
(We can make it more complex, e.g. surround the assignment with a condition, so the assignment can have some sense.)
So, the option could be supported.
Â
Â
KT-8397 Safe Delete leaves syntactically incorrect code
import kotlin.data as import
class A // Safe delete A
import class B
ACTUAL:
import kotlin.data as import
import class B // Error: Expecting qualified name
EXPECTED:
import kotlin.data as import
@import class B // OK
Â
Â
KT-8349 - Rename: changing Kotlin file item to Kotlin class item loses selection in the project tree
Create package P.
Open Project tool window to see the P item in the tree.
In P create a file FileName.kt with the only class ClassName inside.
Select FileName.kt in the tree.
Refactor / Rename the file to ClassName (so you want to get single-class file).
Refactoring is successful, but the file node is transformed to a class node, and loses selection. Thatâs the issue.
No problem if file item is changed to file item.
Failed to model the same case in Java support.
Â
Â
KT-8306 - Poor conflict resolution in Rename refactoring
import D
import D.A
class D { // Rename D to A
open class A
}
class E : A()
ACTUAL:
import A
import A.A
class A {
open class A
}
class E : A() // Error: This type is final, so it cannot be inherited from
EXPECTED:
import A
import A.A
class A {
open class A
}
class E : A.A() // OK
Â
Â
KT-8180 - Implement Copy Class action for Kotlin classes
Â
Â
KT-7520 - Exception when try rename label from usage
fun foo<R>(f: () -> R) = f()
public fun test() {
foo {
return@<caret0>foo false
}
foo (fun (): Boolean {
return@<caret1>foo<caret2> false
})
}
Â
Â
KT-7516 - Rename refactoring doesnât rename related labels
fun <caret>foo<R>(f: () -> R) = f()
public fun test() {
foo {
return@foo false
}
}
Result:
fun bar<R>(f: () -> R) = f()
public fun test() {
bar {
return@foo false // red code here
}
}
Â
Â
KT-7107 - Rename refactoring for labels
Â
Â
KT-6731 - Rename class/method refactoring should also rename relevant run configurations
Â
Â
KT-6322 - âInline Super Classâ fails with exception when invoked on java class
Invoke âInlineâ refactoring on âBâ reference in the following code:
public class K: B() {
override fun run() {
}
}
where B.java is
public abstract class B implements Runnable {
}
IDE will show âInline Super Classâ dialog but will fail with exception when you press âRefactorâ (note that if âBâ is Kotlin class refactoring will be disabled):
Â
Â
KT-6215 - Converter: provide an option to place multiple java files converted to Kotlin in one Kotlin file
Â
Â
KT-5864 - Refactoring: convert get/set methods to property
Â
Â
KT-5602 - move class/method refactoring should be able to move file
Â
Â
KT-4473 - Getter rename does not work right from JSP bean
I have JSP bean that uses Kotlin data class.
data class foo(val bar:String)
<jsp:useBean id="a" type="foo" /> ${a.bar}
I rename bar into zzz form JSP code.
I see warning in JSP after rename around ${a.zzz}
In the Kotlin class I see getZzz instead of zzz for the property
Â
Â
KT-4379 Support renaming import alias
for example:
import java.lang.String as jString
then pressing Shift-F6 while cursor is over jString or other use of jString in code, does not allow renaming
Â
Â
KT-2638 - Inline function/non-trivial property refactoring
The absence of this feature is extremely annoying. It devalues the whole local function feature in the language.
fun main(args: Array<String>) {
fun local() { // Inline refactoring is not available here
println("Test")
}
local()
}
Â
Â
KT-1351 References are not updated after java private package class rename
References are not updated after java private package class rename if kotlin file has same package but placed in another folder.
Â
Feature Groups
-
KT-8178 - Copy Refactoring
-
KT-4478 - Refactorings
-
KT-4728 - Introduce Property
-
KT-2637 - Inline variable/constant refactoring
Parent for: KT-9822
-
KT-2615 - Rename refactoring
Parent for: KT-12740 KT-12727 KT-12348 KT-12162 KT-9748 KT-9383 KT-9212 KT-8980 KT-8563 KT-8545 KT-8514 KT-8349 KT-8306 KT-7627 KT-7520 KT-7516 KT-7283 KT-7107 KT-6731 IDEA-126656 KT-4473 KT-4379 KT-1351