KT-6159: allow local / private functions inlining
This commit is contained in:
+1
-6
@@ -21,7 +21,6 @@ import com.intellij.lang.refactoring.InlineActionHandler
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
|
||||||
import com.intellij.refactoring.RefactoringBundle
|
import com.intellij.refactoring.RefactoringBundle
|
||||||
import com.intellij.refactoring.util.CommonRefactoringUtil
|
import com.intellij.refactoring.util.CommonRefactoringUtil
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
@@ -45,11 +44,7 @@ class KotlinInlineFunctionHandler: InlineActionHandler() {
|
|||||||
override fun isEnabledForLanguage(language: Language) = language == KotlinLanguage.INSTANCE
|
override fun isEnabledForLanguage(language: Language) = language == KotlinLanguage.INSTANCE
|
||||||
|
|
||||||
//TODO: overrides etc
|
//TODO: overrides etc
|
||||||
override fun canInlineElement(element: PsiElement): Boolean {
|
override fun canInlineElement(element: PsiElement) = element is KtNamedFunction && element.hasBody()
|
||||||
return element is KtNamedFunction
|
|
||||||
&& element.hasBody()
|
|
||||||
&& element.getUseScope() is GlobalSearchScope // TODO support local functions
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun inlineElement(project: Project, editor: Editor?, element: PsiElement) {
|
override fun inlineElement(project: Project, editor: Editor?, element: PsiElement) {
|
||||||
element as KtNamedFunction
|
element as KtNamedFunction
|
||||||
|
|||||||
@@ -7,6 +7,5 @@ fun foo() {
|
|||||||
bar(t)
|
bar(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be available
|
|
||||||
<caret>local()
|
<caret>local()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun bar(s: String) {}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val t = "Test"
|
||||||
|
|
||||||
|
bar(t)
|
||||||
|
}
|
||||||
@@ -5,6 +5,5 @@ fun foo() {
|
|||||||
bar("Test")
|
bar("Test")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be available
|
|
||||||
<caret>local()
|
<caret>local()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun bar(s: String) {}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
bar("Test")
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
class My {
|
class My {
|
||||||
fun run() {
|
fun run() {
|
||||||
// TODO: should be available
|
|
||||||
val foo = <caret>doThing()
|
val foo = <caret>doThing()
|
||||||
System.out.println(foo)
|
System.out.println(foo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class My {
|
||||||
|
fun run() {
|
||||||
|
// foo1 should be here
|
||||||
|
val foo = 1 + 2
|
||||||
|
val foo = foo
|
||||||
|
System.out.println(foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user