From 2b7be736aa958a5727094c622c82698a7cb8f098 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 6 Jul 2015 11:33:53 +0200 Subject: [PATCH] IDEA-CR-3497 it's better to use verb in method name to make it clearer what it does, i.e. it would be better to rename this method to 'runWriteAction'. add javadoc to avoid "exposes Function0 class from Kotlin stdlib to public API, it's forbidden for now" --- platform/built-in-server/testSrc/TestManager.kt | 10 +++++----- .../src/com/intellij/openapi/application/actions.kt | 8 +++++++- .../com/intellij/openapi/options/SchemeManagerImpl.kt | 7 ++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/platform/built-in-server/testSrc/TestManager.kt b/platform/built-in-server/testSrc/TestManager.kt index be3fc2ef57e3..eb36f2a63d76 100644 --- a/platform/built-in-server/testSrc/TestManager.kt +++ b/platform/built-in-server/testSrc/TestManager.kt @@ -1,7 +1,7 @@ package org.jetbrains.ide import com.intellij.openapi.application.invokeAndWaitIfNeed -import com.intellij.openapi.application.writeAction +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.util.io.FileUtilRt @@ -68,7 +68,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { val normalizedFilePath = FileUtilRt.toSystemIndependentName(filePath!!) if (annotation!!.relativeToProject) { val root = projectFixture.getProject().getBaseDir() - writeAction { + runWriteAction { fileToDelete = root.findOrCreateChildData(this@TestManager, normalizedFilePath) } } @@ -77,7 +77,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { ModuleRootModificationUtil.updateModel(projectFixture.getModule()) { model -> val contentEntry = model.getContentEntries()[0] val contentRoot = contentEntry.getFile()!! - writeAction { + runWriteAction { contentRoot.findChild(EXCLUDED_DIR_NAME)?.delete(this@TestManager) fileToDelete = contentRoot.createChildDirectory(this@TestManager, EXCLUDED_DIR_NAME) fileToDelete!!.createChildData(this@TestManager, normalizedFilePath) @@ -89,7 +89,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { } else { val root = ModuleRootManager.getInstance(projectFixture.getModule()).getSourceRoots()[0] - writeAction { + runWriteAction { fileToDelete = root.findOrCreateChildData(this@TestManager, normalizedFilePath) } } @@ -103,7 +103,7 @@ class TestManager(val projectFixture: IdeaProjectTestFixture) : TestWatcher() { } if (fileToDelete != null) { - invokeAndWaitIfNeed { writeAction { fileToDelete?.delete(this@TestManager) } } + invokeAndWaitIfNeed { runWriteAction { fileToDelete?.delete(this@TestManager) } } fileToDelete = null } diff --git a/platform/core-impl/src/com/intellij/openapi/application/actions.kt b/platform/core-impl/src/com/intellij/openapi/application/actions.kt index 4be236085b50..d7071412640c 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/actions.kt +++ b/platform/core-impl/src/com/intellij/openapi/application/actions.kt @@ -17,7 +17,10 @@ package com.intellij.openapi.application import javax.swing.SwingUtilities -public inline fun writeAction(runnable: () -> Unit) { +/** + * @exclude Internal use only + */ +public inline fun runWriteAction(runnable: () -> Unit) { val token = WriteAction.start() try { runnable() @@ -27,6 +30,9 @@ public inline fun writeAction(runnable: () -> Unit) { } } +/** + * @exclude Internal use only + */ public fun invokeAndWaitIfNeed(runnable: () -> Unit) { val app = ApplicationManager.getApplication() if (app == null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemeManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/options/SchemeManagerImpl.kt index 4c575727d86d..e887c56b3d57 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemeManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemeManagerImpl.kt @@ -19,7 +19,7 @@ import com.intellij.openapi.application.AccessToken import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.WriteAction import com.intellij.openapi.application.ex.DecodeDefaultsUtil -import com.intellij.openapi.application.writeAction +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.components.RoamingType import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.impl.stores.DirectoryBasedStorage @@ -527,7 +527,8 @@ public class SchemeManagerImpl(private val if (renamed) { file = dir.findChild(externalInfo!!.fileName) if (file != null) { - writeAction { + runWriteAction { } + runWriteAction { file!!.rename(this, fileName) } } @@ -537,7 +538,7 @@ public class SchemeManagerImpl(private val file = DirectoryBasedStorage.getFile(fileName, dir, this) } - writeAction { + runWriteAction { file!!.getOutputStream(this).use { byteOut.writeTo(it) }