From 625ae37de79b1dc1ca19b53262b91163ef0950b4 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 Nov 2011 17:21:48 +0400 Subject: [PATCH] test for the exception inside stub index --- .../com/intellij/testFramework/PsiTestCase.java | 16 ++++++++++++++++ .../intellij/openapi/application/RunResult.java | 17 +++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java index a906fc068d9f..35d132f23637 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java @@ -244,4 +244,20 @@ public abstract class PsiTestCase extends ModuleTestCase { PsiDocumentManager.getInstance(getProject()).commitDocument(document); } + protected static VirtualFile createChildData(final VirtualFile dir, @NonNls final String name) { + return new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + result.setResult(dir.createChildData(null, name)); + } + }.execute().throwException().getResultObject(); + } + protected static VirtualFile createChildDirectory(final VirtualFile dir, @NonNls final String name) { + return new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + result.setResult(dir.createChildDirectory(null, name)); + } + }.execute().throwException().getResultObject(); + } } diff --git a/platform/platform-api/src/com/intellij/openapi/application/RunResult.java b/platform/platform-api/src/com/intellij/openapi/application/RunResult.java index daddc8350144..5129c54a2fd0 100644 --- a/platform/platform-api/src/com/intellij/openapi/application/RunResult.java +++ b/platform/platform-api/src/com/intellij/openapi/application/RunResult.java @@ -35,14 +35,20 @@ public class RunResult extends Result { public RunResult run() { try { myActionRunnable.run(this); - } catch (ProcessCanceledException e) { + } + catch (ProcessCanceledException e) { throw e; // this exception may occur from time to time and it shouldn't be catched - } catch (Throwable throwable) { + } + catch (Throwable throwable) { myThrowable = throwable; if (!myActionRunnable.isSilentExecution()) { if (throwable instanceof RuntimeException) throw (RuntimeException)throwable; - if (throwable instanceof Error) throw (Error)throwable; - else throw new RuntimeException(myThrowable); + if (throwable instanceof Error) { + throw (Error)throwable; + } + else { + throw new RuntimeException(myThrowable); + } } } finally { @@ -64,7 +70,7 @@ public class RunResult extends Result { return this; } - public RunResult throwException() { + public RunResult throwException() throws RuntimeException, Error { if (hasException()) { if (myThrowable instanceof RuntimeException) { throw (RuntimeException)myThrowable; @@ -89,5 +95,4 @@ public class RunResult extends Result { public void setThrowable(Exception throwable) { myThrowable = throwable; } - }