From aab286cf1342da45828d0eadea259646056aede7 Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 23 Dec 2019 20:50:42 +0000 Subject: [PATCH] Convert Slf4jFernflowerLogger to Kotlin --- .../decompiler/Slf4jFernflowerLogger.java | 60 ------------------- .../decompiler/Slf4jFernflowerLogger.kt | 32 ++++++++++ 2 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.java create mode 100644 decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.kt diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.java b/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.java deleted file mode 100644 index 4bbcba526a..0000000000 --- a/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.java +++ /dev/null @@ -1,60 +0,0 @@ -package dev.openrs2.decompiler; - -import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class Slf4jFernflowerLogger extends IFernflowerLogger { - private static final Logger logger = LoggerFactory.getLogger(Slf4jFernflowerLogger.class); - - public static final IFernflowerLogger INSTANCE = new Slf4jFernflowerLogger(); - - private Slf4jFernflowerLogger() { - /* empty */ - } - - @Override - public void startClass(String className) { - logger.info("Decompiling {}", className); - } - - @Override - public void writeMessage(String message, Severity severity) { - switch (severity) { - case TRACE: - logger.trace(message); - break; - case INFO: - logger.info(message); - break; - case WARN: - logger.warn(message); - break; - case ERROR: - logger.error(message); - break; - default: - throw new IllegalArgumentException(); - } - } - - @Override - public void writeMessage(String message, Severity severity, Throwable t) { - switch (severity) { - case TRACE: - logger.trace(message, t); - break; - case INFO: - logger.info(message, t); - break; - case WARN: - logger.warn(message, t); - break; - case ERROR: - logger.error(message, t); - break; - default: - throw new IllegalArgumentException(); - } - } -} diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.kt b/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.kt new file mode 100644 index 0000000000..3d2f11123d --- /dev/null +++ b/decompiler/src/main/java/dev/openrs2/decompiler/Slf4jFernflowerLogger.kt @@ -0,0 +1,32 @@ +package dev.openrs2.decompiler + +import com.github.michaelbull.logging.InlineLogger +import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger + +object Slf4jFernflowerLogger : IFernflowerLogger() { + private val logger = InlineLogger() + + override fun startClass(className: String) { + logger.info { "Decompiling $className" } + } + + override fun writeMessage(message: String, severity: Severity) { + when (severity) { + Severity.TRACE -> logger.trace { message } + Severity.INFO -> logger.info { message } + Severity.WARN -> logger.warn { message } + Severity.ERROR -> logger.error { message } + else -> throw IllegalArgumentException() + } + } + + override fun writeMessage(message: String, severity: Severity, t: Throwable) { + when (severity) { + Severity.TRACE -> logger.trace(t) { message } + Severity.INFO -> logger.info(t) { message } + Severity.WARN -> logger.warn(t) { message } + Severity.ERROR -> logger.error(t) { message } + else -> throw IllegalArgumentException() + } + } +}