Skip to content

Commit

Permalink
Fix a handful of missing method issues and clarify error
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Nov 13, 2023
1 parent 619caba commit 4a6c391
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vineflower.kotlin.expr;

import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.plugins.PluginImplementationException;
import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent;
Expand Down Expand Up @@ -40,7 +41,13 @@ public KFunctionExprent(FunctionType funcType, List<Exprent> operands, BitSet by
public KFunctionExprent(FunctionExprent func) {
super(func.getFuncType(), new ArrayList<>(KUtils.replaceExprents(func.getLstOperands())), func.bytecode);

setImplicitType(func.getExprType());
if (func instanceof KFunctionExprent) {
KFunctionExprent kFunc = (KFunctionExprent) func;
this.kType = kFunc.kType;
} else {
setImplicitType(func.getExprType());
}

setNeedsCast(func.doesCast());

if (getFuncType() == FunctionType.EQ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,31 @@ public static Map<StructMethod, KFunction> parse(ClassesProcessor.ClassNode node

KType returnType = KType.from(function.getReturnType(), resolver);

StringBuilder desc = new StringBuilder("(");
if (receiverType != null) {
desc.append(receiverType);
}
MethodWrapper method = null;

for (KParameter parameter : parameters) {
desc.append(parameter.type);
if (jvmData.hasDesc()) {
String lookupName = jvmData.hasName() ? resolver.resolve(jvmData.getName()) : name;
method = wrapper.getMethodWrapper(lookupName, resolver.resolve(jvmData.getDesc()));
}

int endOfParams = desc.length();
desc.append(")").append(returnType);
if (method == null) {
StringBuilder desc = new StringBuilder("(");
if (receiverType != null) {
desc.append(receiverType);
}

for (KParameter parameter : parameters) {
desc.append(parameter.type);
}

int endOfParams = desc.length();
desc.append(")").append(returnType);

MethodWrapper method = wrapper.getMethodWrapper(name, desc.toString());
if (method == null && flags.isSuspend) {
desc.setLength(endOfParams);
desc.append("Lkotlin/coroutines/Continuation;)Ljava/lang/Object;");
method = wrapper.getMethodWrapper(name, desc.toString());

if (method == null) {
throw new IllegalStateException("Couldn't find method " + name + " " + desc + " in class " + struct.qualifiedName);
}
}

List<KTypeParameter> typeParameters = function.getTypeParameterList().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class KTypes {
Map.entry("kotlin/Float", "java/lang/Float"),
Map.entry("kotlin/Int", "java/lang/Integer"),
Map.entry("kotlin/Long", "java/lang/Long"),
Map.entry("kotlin/Nothing", "java/lang/Void"),
Map.entry("kotlin/Number", "java/lang/Number"),
Map.entry("kotlin/Short", "java/lang/Short"),
Map.entry("kotlin/String", "java/lang/String"),
Expand Down Expand Up @@ -85,6 +86,10 @@ public static String getJavaSignature(String kotlinType, boolean isNullable) {
if (kotlinType.startsWith("kotlin/")) {
if (KOTLIN_PRIMITIVE_TYPES.containsKey(kotlinType) && !isNullable) {
return KOTLIN_PRIMITIVE_TYPES.get(kotlinType);
} else if (kotlinType.endsWith("$Companion") && KOTLIN_PRIMITIVE_TYPES.containsKey(kotlinType.replace("$Companion", ""))) {
return "Lkotlin/jvm/internal/" + kotlinType.split("/")[1].split("\\$")[0] + "CompanionObject;";
} else if (kotlinType.endsWith("Array") && KOTLIN_PRIMITIVE_TYPES.containsKey(kotlinType.replace("Array", ""))) {
return "[" + KOTLIN_PRIMITIVE_TYPES.get(kotlinType.replace("Array", ""));
} else if (KOTLIN_TO_JAVA_LANG.containsKey(kotlinType)) {
return "L" + KOTLIN_TO_JAVA_LANG.get(kotlinType) + ";";
} else if (KOTLIN_TO_JAVA_UTIL.containsKey(kotlinType)) {
Expand Down

0 comments on commit 4a6c391

Please sign in to comment.