From 087e26957b09b9347495b3068d08f3076f95d7e1 Mon Sep 17 00:00:00 2001 From: sschr15 Date: Sun, 25 Aug 2024 00:11:41 -0500 Subject: [PATCH] [Kotlin] Fix cast types being Java-style --- .../vineflower/kotlin/expr/KConstExprent.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/kotlin/src/main/java/org/vineflower/kotlin/expr/KConstExprent.java b/plugins/kotlin/src/main/java/org/vineflower/kotlin/expr/KConstExprent.java index 42d38585ac..7ca5793b9b 100644 --- a/plugins/kotlin/src/main/java/org/vineflower/kotlin/expr/KConstExprent.java +++ b/plugins/kotlin/src/main/java/org/vineflower/kotlin/expr/KConstExprent.java @@ -4,6 +4,8 @@ import org.jetbrains.java.decompiler.modules.decompiler.exps.ExprUtil; import org.jetbrains.java.decompiler.struct.gen.VarType; import org.jetbrains.java.decompiler.util.TextBuffer; +import org.vineflower.kotlin.util.KTypes; +import org.vineflower.kotlin.util.KUtils; public class KConstExprent extends ConstExprent implements KExprent { public KConstExprent(ConstExprent exprent) { @@ -12,6 +14,17 @@ public KConstExprent(ConstExprent exprent) { @Override public TextBuffer toJava(int indent) { + if (getValue() == null) { + if (getConstType().equals(VarType.VARTYPE_NULL)) { + return super.toJava(indent); + } + + TextBuffer buf = new TextBuffer(); + buf.addBytecodeMapping(bytecode); + buf.append(KTypes.getKotlinType(getConstType())); + return buf; + } + if (!getConstType().equals(VarType.VARTYPE_CLASS)) { return super.toJava(indent); } @@ -19,11 +32,6 @@ public TextBuffer toJava(int indent) { TextBuffer buf = new TextBuffer(); buf.addBytecodeMapping(bytecode); - if (getValue() == null) { - //TODO figure out why this happens here instead of elsewhere - return buf.append("Class<*>"); - } - String value = getValue().toString(); VarType type = new VarType(value, !value.startsWith("[")); buf.appendCastTypeName(type).append("::class.java");