From 3673f8003be131521ad3ad6e0c09dcd307c82658 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 26 Apr 2013 18:35:33 +0400 Subject: [PATCH] reportException() moved to a utility class and used where appropriate --- .../common/messages/MessageCollectorUtil.java | 27 +++++++++++++++++++ .../jetbrains/jet/cli/jvm/K2JVMCompiler.java | 3 +-- .../compiler/KotlinToJVMBytecodeCompiler.java | 3 +-- .../compiler/runner/CompilerOutputParser.java | 11 ++++---- .../compiler/runner/KotlinCompilerRunner.java | 3 ++- 5 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/messages/MessageCollectorUtil.java diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/messages/MessageCollectorUtil.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/messages/MessageCollectorUtil.java new file mode 100644 index 00000000000..e8680af6328 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/messages/MessageCollectorUtil.java @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2013 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.cli.common.messages; + +import org.jetbrains.annotations.NotNull; + +public class MessageCollectorUtil { + public static void reportException(@NotNull MessageCollector messageCollector, @NotNull Throwable exception) { + messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(exception), + CompilerMessageLocation.NO_LOCATION); + } + +} diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java index f7d58b3ab20..3dc30dc3ec0 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java @@ -73,8 +73,7 @@ public class K2JVMCompiler extends CLICompiler { configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments)); } catch (Throwable t) { - messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), - CompilerMessageLocation.NO_LOCATION); + MessageCollectorUtil.reportException(messageCollector, t); return INTERNAL_ERROR; } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 5c998bdfdbe..0b3961e8be0 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -400,8 +400,7 @@ public class KotlinToJVMBytecodeCompiler { return null; } catch (Throwable t) { - messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t), - CompilerMessageLocation.NO_LOCATION); + MessageCollectorUtil.reportException(messageCollector, t); return null; } diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java index 98775988899..d890f717bb3 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerOutputParser.java @@ -19,9 +19,11 @@ package org.jetbrains.jet.compiler.runner; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.cli.common.messages.*; +import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; +import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; +import org.jetbrains.jet.cli.common.messages.MessageCollector; +import org.jetbrains.jet.cli.common.messages.OutputMessageUtil; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -35,6 +37,7 @@ import java.util.Map; import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION; import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*; +import static org.jetbrains.jet.cli.common.messages.MessageCollectorUtil.reportException; public class CompilerOutputParser { public static void parseCompilerMessagesFromReader(MessageCollector messageCollector, final Reader reader, OutputItemsCollector collector) { @@ -94,10 +97,6 @@ public class CompilerOutputParser { } } - public static void reportException(@NotNull MessageCollector messageCollector, @NotNull Throwable e) { - messageCollector.report(EXCEPTION, MessageRenderer.PLAIN.renderException(e), NO_LOCATION); - } - private static class CompilerOutputSAXHandler extends DefaultHandler { private static final Map CATEGORIES = new ContainerUtil.ImmutableMapBuilder() .put("error", ERROR) diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java index 7737a7fac94..3efb83f6b9d 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java @@ -29,6 +29,7 @@ import com.intellij.util.SystemProperties; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageCollector; +import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil; import java.io.File; import java.io.IOException; @@ -81,7 +82,7 @@ public class KotlinCompilerRunner { return CompilerRunnerUtil.getReturnCodeFromObject(rc); } catch (Throwable e) { - CompilerOutputParser.reportException(messageCollector, e); + MessageCollectorUtil.reportException(messageCollector, e); return -1; } }