From 3408c9833cf8a1887abcef117702797f417dc1c8 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 6 Jun 2012 23:58:19 +0400 Subject: [PATCH] ExceptionUtils.rethrow --- .../jet/checkers/JetDiagnosticsTest.java | 3 +- .../jet/codegen/CodegenTestCase.java | 5 ++- .../jetbrains/jet/codegen/TestlibTest.java | 15 +++----- .../jetbrains/jet/utils/ExceptionUtils.java | 36 +++++++++++++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java index ea3c9f867bc..1cec33fa494 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTest.java @@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import junit.framework.Test; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.utils.ExceptionUtils; import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestUtils; @@ -138,7 +139,7 @@ public class JetDiagnosticsTest extends JetLiteFixture { Files.write(content, javaFile, Charset.forName("utf-8")); hasJavaFiles = true; } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.rethrow(e); } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index 1b5d98eedb7..2d2fe3b8b9a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.codegen; -import com.google.common.base.Objects; import com.google.common.base.Predicates; import com.google.common.collect.Lists; import com.intellij.openapi.util.Pair; @@ -24,6 +23,7 @@ import com.intellij.psi.PsiFile; import com.intellij.testFramework.UsefulTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.utils.ExceptionUtils; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; @@ -43,7 +43,6 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Collections; import java.util.List; /** @@ -163,7 +162,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { } } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.rethrow(e); } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java index 07af2166582..37bcf308b48 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java @@ -21,6 +21,7 @@ import gnu.trove.THashSet; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jetbrains.jet.utils.ExceptionUtils; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; @@ -55,18 +56,14 @@ public class TestlibTest extends CodegenTestCase { try { setUp(); return doBuildSuite(); - } catch (RuntimeException e) { - throw e; } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.rethrow(e); } finally { try { tearDown(); - } catch (RuntimeException e) { - throw e; } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.rethrow(e); } } } @@ -155,10 +152,8 @@ public class TestlibTest extends CodegenTestCase { } return suite; - } catch (RuntimeException e) { - throw e; - } catch (Throwable e) { - throw new RuntimeException(e); + } catch (Exception e) { + throw ExceptionUtils.rethrow(e); } } diff --git a/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java b/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java new file mode 100644 index 00000000000..e344140be6f --- /dev/null +++ b/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.utils; + +/** + * @author Stepan Koltsov + */ +public class ExceptionUtils { + + /** + * Translate exception to unchecked exception. + */ + public static RuntimeException rethrow(Exception e) { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + else { + throw new RuntimeException(e); + } + } + +}