J2K: KotlinIntroduceVariableHandler

This commit is contained in:
Alexey Sedunov
2015-11-11 14:25:39 +03:00
parent a591c27dbf
commit d652623f90
4 changed files with 444 additions and 572 deletions
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.*
public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() { public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
override fun isSafeDeleteAvailable(element: PsiElement) = element.canDeleteElement() override fun isSafeDeleteAvailable(element: PsiElement) = element.canDeleteElement()
override fun getIntroduceVariableHandler() = KotlinIntroduceVariableHandler() override fun getIntroduceVariableHandler() = KotlinIntroduceVariableHandler
override fun getIntroduceParameterHandler() = KotlinIntroduceParameterHandler() override fun getIntroduceParameterHandler() = KotlinIntroduceParameterHandler()
@@ -40,6 +40,7 @@ import com.intellij.openapi.ui.popup.JBPopupAdapter
import com.intellij.openapi.ui.popup.LightweightWindowEvent import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.ui.popup.PopupChooserBuilder import com.intellij.openapi.ui.popup.PopupChooserBuilder
import com.intellij.openapi.util.Key import com.intellij.openapi.util.Key
import com.intellij.openapi.util.Pass
import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.TextRange
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.LocalFileSystem
@@ -744,3 +745,7 @@ fun <ListType : KtElement> replaceListPsiAndKeepDelimiters(
return originalList return originalList
} }
fun <T> Pass(body: (T) -> Unit) = object: Pass<T>() {
override fun pass(t: T) = body(t)
}
@@ -32,6 +32,7 @@ import com.intellij.refactoring.introduceField.ElementToWorkOn
import com.intellij.refactoring.introduceParameter.AbstractJavaInplaceIntroducer import com.intellij.refactoring.introduceParameter.AbstractJavaInplaceIntroducer
import com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor import com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor
import com.intellij.refactoring.introduceParameter.Util import com.intellij.refactoring.introduceParameter.Util
import com.intellij.refactoring.util.CommonRefactoringUtil
import com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager import com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
@@ -67,11 +68,11 @@ public abstract class AbstractExtractionTest() : KotlinLightCodeInsightFixtureTe
doTest(path) { file -> doTest(path) { file ->
file as KtFile file as KtFile
KotlinIntroduceVariableHandler().invoke( KotlinIntroduceVariableHandler.invoke(
fixture.getProject(), fixture.project,
fixture.getEditor(), fixture.editor,
file, file,
DataManager.getInstance().getDataContext(fixture.getEditor().getComponent()) DataManager.getInstance().getDataContext(fixture.editor.component)
) )
} }
} }
@@ -342,6 +343,9 @@ public abstract class AbstractExtractionTest() : KotlinLightCodeInsightFixtureTe
val message = e.messages.sorted().joinToString(" ").replace("\n", " ") val message = e.messages.sorted().joinToString(" ").replace("\n", " ")
KotlinTestUtils.assertEqualsToFile(conflictFile, message) KotlinTestUtils.assertEqualsToFile(conflictFile, message)
} }
catch(e: CommonRefactoringUtil.RefactoringErrorHintException) {
KotlinTestUtils.assertEqualsToFile(conflictFile, e.message!!)
}
catch(e: RuntimeException) { // RuntimeException is thrown by IDEA code in CodeInsightUtils.java catch(e: RuntimeException) { // RuntimeException is thrown by IDEA code in CodeInsightUtils.java
if (e.javaClass != RuntimeException::class.java) throw e if (e.javaClass != RuntimeException::class.java) throw e
KotlinTestUtils.assertEqualsToFile(conflictFile, e.message!!) KotlinTestUtils.assertEqualsToFile(conflictFile, e.message!!)