From c10134c1f6d374b79cc8f9b46d06a051401b4812 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 25 Dec 2019 12:30:52 +0000 Subject: [PATCH] Tidy toPrettyString() I missed this during the initial InsnNodeUtils port. --- .../main/java/dev/openrs2/asm/InsnNodeUtils.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt index 1d712f42..bcc65f8c 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt @@ -7,10 +7,8 @@ import org.objectweb.asm.tree.IntInsnNode import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.util.Textifier import org.objectweb.asm.util.TraceMethodVisitor -import java.io.IOException import java.io.PrintWriter import java.io.StringWriter -import java.io.UncheckedIOException private val PURE_OPCODES = setOf( -1, @@ -273,16 +271,14 @@ fun createIntConstant(value: Int): AbstractInsnNode = when (value) { fun AbstractInsnNode.toPrettyString(): String { val printer = Textifier() + val visitor = TraceMethodVisitor(printer) accept(visitor) - try { - StringWriter().use { stringWriter -> - PrintWriter(stringWriter).use { printWriter -> - printer.print(printWriter) - return stringWriter.toString().trim { it <= ' ' } - } + + StringWriter().use { stringWriter -> + PrintWriter(stringWriter).use { printWriter -> + printer.print(printWriter) + return stringWriter.toString().trim() } - } catch (ex: IOException) { - throw UncheckedIOException(ex) } }