KT-6159: allow local / private functions inlining

This commit is contained in:
Mikhail Glukhikh
2017-03-21 14:50:37 +03:00
parent 127b7c80df
commit de861066bf
7 changed files with 23 additions and 9 deletions
@@ -21,7 +21,6 @@ import com.intellij.lang.refactoring.InlineActionHandler
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.util.CommonRefactoringUtil
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
@@ -45,11 +44,7 @@ class KotlinInlineFunctionHandler: InlineActionHandler() {
override fun isEnabledForLanguage(language: Language) = language == KotlinLanguage.INSTANCE
//TODO: overrides etc
override fun canInlineElement(element: PsiElement): Boolean {
return element is KtNamedFunction
&& element.hasBody()
&& element.getUseScope() is GlobalSearchScope // TODO support local functions
}
override fun canInlineElement(element: PsiElement) = element is KtNamedFunction && element.hasBody()
override fun inlineElement(project: Project, editor: Editor?, element: PsiElement) {
element as KtNamedFunction
@@ -7,6 +7,5 @@ fun foo() {
bar(t)
}
// TODO: should be available
<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")
}
// TODO: should be available
<caret>local()
}
@@ -0,0 +1,6 @@
fun bar(s: String) {}
fun foo() {
bar("Test")
}
@@ -1,6 +1,5 @@
class My {
fun run() {
// TODO: should be available
val foo = <caret>doThing()
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)
}
}