diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 623f0873c14..63a80669140 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -674,7 +674,7 @@ fun main(args: Array) { testClass { model("codeInsight/moveUpDown/classBodyDeclarations", testMethod = "doTestClassBodyDeclaration") model("codeInsight/moveUpDown/closingBraces", testMethod = "doTestExpression") - model("codeInsight/moveUpDown/expressions", testMethod = "doTestExpression") + model("codeInsight/moveUpDown/expressions", pattern = KT_OR_KTS, testMethod = "doTestExpression") model("codeInsight/moveUpDown/parametersAndArguments", testMethod = "doTestExpression") } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDependenciesUpdater.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDependenciesUpdater.kt index 837e118f196..7e1c3ba2501 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDependenciesUpdater.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptDependenciesUpdater.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.core.script +import com.intellij.openapi.application.Application import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.components.ServiceManager @@ -24,6 +25,7 @@ import com.intellij.openapi.project.ProjectUtil import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.roots.ex.ProjectRootManagerEx import com.intellij.openapi.util.EmptyRunnable +import com.intellij.openapi.util.Key import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.vfs.newvfs.BulkFileListener @@ -32,13 +34,15 @@ import kotlinx.coroutines.experimental.CoroutineDispatcher import kotlinx.coroutines.experimental.Job import kotlinx.coroutines.experimental.asCoroutineDispatcher import kotlinx.coroutines.experimental.launch +import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.idea.util.application.runWriteAction +import org.jetbrains.kotlin.psi.NotNullableUserDataProperty import org.jetbrains.kotlin.script.* import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executors +import kotlin.script.experimental.dependencies.AsyncDependenciesResolver import kotlin.script.experimental.dependencies.DependenciesResolver import kotlin.script.experimental.dependencies.ScriptDependencies -import kotlin.script.experimental.dependencies.AsyncDependenciesResolver internal class ScriptDependenciesUpdater( private val project: Project, @@ -233,11 +237,14 @@ internal class ScriptDependenciesUpdater( private fun listenToVfsChanges() { project.messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener.Adapter() { - val projectFileIndex = ProjectRootManager.getInstance(project).fileIndex val application = ApplicationManager.getApplication() override fun after(events: List) { + if (application.isUnitTestMode && application.isScriptDependenciesUpdaterDisabled == true) { + return + } + if (updateCache(events.mapNotNull { // The check is partly taken from the BuildManager.java it.file?.takeIf { @@ -258,7 +265,6 @@ internal class ScriptDependenciesUpdater( } } - private data class TimeStamp(private val stamp: Long) { operator fun compareTo(other: TimeStamp) = this.stamp.compareTo(other.stamp) } @@ -267,4 +273,7 @@ private object TimeStamps { private var current: Long = 0 fun next() = TimeStamp(current++) -} \ No newline at end of file +} + +@set: TestOnly +var Application.isScriptDependenciesUpdaterDisabled by NotNullableUserDataProperty(Key.create("SCRIPT_DEPENDENCIES_UPDATER_DISABLED"), false) \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java index 4f367fb8d47..9265e0aeb24 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java @@ -184,7 +184,7 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover { while (current != null) { PsiElement parent = current.getParent(); if (parent instanceof KtClassBody || - parent instanceof KtAnonymousInitializer || + (parent instanceof KtAnonymousInitializer && !(parent instanceof KtScriptInitializer)) || parent instanceof KtNamedFunction || (parent instanceof KtProperty && !((KtProperty) parent).isLocal())) { return null; diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts new file mode 100644 index 00000000000..c46b92eba10 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts @@ -0,0 +1,7 @@ +// MOVE: down +fun takeLamb(f: () -> Unit) {} +fun foo() {} +takeLamb { + foo() +} + diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts.after b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts.after new file mode 100644 index 00000000000..cd02c489580 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts.after @@ -0,0 +1,7 @@ +// MOVE: down +fun takeLamb(f: () -> Unit) {} +fun foo() {} +takeLamb { +} +foo() + diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts new file mode 100644 index 00000000000..88e45acf8f1 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts @@ -0,0 +1,7 @@ +// MOVE: up +fun takeLamb(f: () -> Unit) {} +takeLamb { + foo() +} + +fun foo() {} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts.after b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts.after new file mode 100644 index 00000000000..75f2a81a030 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts.after @@ -0,0 +1,7 @@ +// MOVE: up +fun takeLamb(f: () -> Unit) {} +foo() +takeLamb { +} + +fun foo() {} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt index 8ca8a79aa7b..4ad044e9212 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt @@ -21,7 +21,7 @@ import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementRightActi import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementDownAction import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementUpAction import com.intellij.codeInsight.editorActions.moveUpDown.StatementUpDownMover -import com.intellij.openapi.actionSystem.Presentation +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.editor.actionSystem.EditorAction import com.intellij.openapi.extensions.Extensions @@ -33,6 +33,7 @@ import junit.framework.TestCase import org.jetbrains.kotlin.formatter.FormatSettingsUtil import org.jetbrains.kotlin.idea.codeInsight.upDownMover.KotlinDeclarationMover import org.jetbrains.kotlin.idea.codeInsight.upDownMover.KotlinExpressionMover +import org.jetbrains.kotlin.idea.core.script.isScriptDependenciesUpdaterDisabled import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File @@ -67,6 +68,16 @@ abstract class AbstractMoveLeftRightTest : AbstractCodeMoverTest() { } abstract class AbstractCodeMoverTest : LightCodeInsightTestCase() { + override fun setUp() { + super.setUp() + ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled = true + } + + override fun tearDown() { + ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled = false + super.tearDown() + } + protected fun doTest(path: String, isApplicableChecker: (isApplicableExpected: Boolean, direction: String) -> Unit) { configureByFile(path) diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java index f67e3f8845e..188ecee94d0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java @@ -821,7 +821,7 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest { @RunWith(JUnit3RunnerWithInners.class) public static class Expressions extends AbstractMoveStatementTest { public void testAllFilesPresentInExpressions() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/moveUpDown/expressions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/moveUpDown/expressions"), Pattern.compile("^(.+)\\.(kt|kts)$"), TargetBackend.ANY, true); } @TestMetadata("binaryExpr1.kt") @@ -1106,6 +1106,18 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest { doTestExpression(fileName); } + @TestMetadata("outOfClosureInScriptsDown.kts") + public void testOutOfClosureInScriptsDown() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsDown.kts"); + doTestExpression(fileName); + } + + @TestMetadata("outOfClosureInScriptsUp.kts") + public void testOutOfClosureInScriptsUp() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/moveUpDown/expressions/outOfClosureInScriptsUp.kts"); + doTestExpression(fileName); + } + @TestMetadata("outOfClosureWithParams1.kt") public void testOutOfClosureWithParams1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/moveUpDown/expressions/outOfClosureWithParams1.kt");