Skip to content

Commit

Permalink
[Kotlin] Fix cast types being Java-style
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Aug 25, 2024
1 parent 842371b commit 087e269
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -12,18 +14,24 @@ 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);
}

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");
Expand Down

0 comments on commit 087e269

Please sign in to comment.