From 1dc017942d17b1693a0c8eef80fde63121c9b7a1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Sat, 12 May 2012 18:06:36 +0400 Subject: [PATCH] cleanup --- .../openapi/command/WriteCommandAction.java | 11 ++++++++-- .../testFramework/PlatformTestCase.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/openapi/command/WriteCommandAction.java b/platform/lang-api/src/com/intellij/openapi/command/WriteCommandAction.java index ecdd377f0f5b..87a47e9cc75a 100644 --- a/platform/lang-api/src/com/intellij/openapi/command/WriteCommandAction.java +++ b/platform/lang-api/src/com/intellij/openapi/command/WriteCommandAction.java @@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.ui.GuiUtils; import com.intellij.util.SmartList; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.lang.reflect.InvocationTargetException; @@ -41,7 +42,7 @@ public abstract class WriteCommandAction extends BaseActionRunnable { this(project, "Undefined", files); } - protected WriteCommandAction(Project project, String commandName, PsiFile... files) { + protected WriteCommandAction(Project project, @NonNls String commandName, PsiFile... files) { this(project, commandName, null, files); } @@ -64,11 +65,13 @@ public abstract class WriteCommandAction extends BaseActionRunnable { return myGroupID; } + @Override public RunResult execute() { final RunResult result = new RunResult(this); try { Runnable runnable = new Runnable() { + @Override public void run() { performWriteCommandAction(result); } @@ -83,7 +86,7 @@ public abstract class WriteCommandAction extends BaseActionRunnable { } catch (Throwable e) { if (e instanceof InvocationTargetException) e = e.getCause(); if (e instanceof Error) throw (Error)e; - else if (e instanceof RuntimeException) throw (RuntimeException)e; + if (e instanceof RuntimeException) throw (RuntimeException)e; throw new Error(e); } return result; @@ -116,8 +119,10 @@ public abstract class WriteCommandAction extends BaseActionRunnable { final RunResult[] results = {result}; CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + @Override public void run() { getApplication().runWriteAction(new Runnable() { + @Override public void run() { results[0].run(); results[0] = null; @@ -141,6 +146,7 @@ public abstract class WriteCommandAction extends BaseActionRunnable { final RunResult[] results = {result}; CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { + @Override public void run() { if (isGlobalUndoAction()) CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject); results[0].run(); @@ -167,6 +173,7 @@ public abstract class WriteCommandAction extends BaseActionRunnable { super(project, name, groupID, files); } + @Override protected void run(final Result result) throws Throwable { run(); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index df145e7ff9f0..6463c7c5e07b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -790,4 +790,25 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } }.execute().throwException().getResultObject(); } + protected static void delete(@NotNull final VirtualFile file) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + try { + file.delete(null); + } + catch (IOException e) { + fail(); + } + } + }); + } + protected static void rename(@NotNull final VirtualFile vFile1, @NotNull final String newName) { + new WriteCommandAction.Simple(null) { + @Override + protected void run() throws Throwable { + vFile1.rename(this, newName); + } + }.execute().throwException(); + } }