Skip to content

Commit 253c367

Browse files
committed
Fixed the JavaNativeModule class to be compatible with the new changes
1 parent 7c0db13 commit 253c367

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openzen.zenscript.codemodel.type.*;
2121
import org.openzen.zenscript.codemodel.type.member.*;
2222
import org.openzen.zenscript.javashared.*;
23+
import org.openzen.zenscript.javashared.types.JavaFunctionalInterfaceTypeID;
2324
import org.openzen.zenscript.lexer.*;
2425
import org.openzen.zenscript.parser.*;
2526
import org.openzen.zenscript.parser.expression.*;
@@ -889,20 +890,14 @@ private FunctionHeader getHeader(
889890
Expression defaultValue = getDefaultValue(parameter, type);
890891
parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
891892
}
892-
893-
TypeParameter[] typeParameters = new TypeParameter[javaTypeParameters.length];
894-
for (int i = 0; i < javaTypeParameters.length; i++) {
895-
TypeVariable<Method> javaTypeParameter = javaTypeParameters[i];
896-
typeParameters[i] = new TypeParameter(CodePosition.UNKNOWN, javaTypeParameter.getName());
897-
context.put(javaTypeParameter, typeParameters[i]);
898-
899-
for (AnnotatedType bound : javaTypeParameter.getAnnotatedBounds())
900-
typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, loadType(context, bound)));
893+
if (classParameters > 0 && classParameters == typeParameters.length) {
894+
parameters = Arrays.copyOfRange(parameters, classParameters, parameters.length);
901895
}
902-
896+
903897
if (exceptionTypes.length > 1)
904898
throw new IllegalArgumentException("A method can only throw a single exception type!");
905899

900+
TypeID returnType = javaReturnType == null ? BasicTypeID.VOID : loadStoredType(context, javaReturnType);
906901
TypeID thrownType = exceptionTypes.length == 0 ? null : loadStoredType(context, exceptionTypes[0]);
907902
return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
908903
}
@@ -931,7 +926,7 @@ else if (annotatedType.isAnnotationPresent(ZenCodeType.NullableUSize.class))
931926
return loadType(context, annotatedType, nullable, unsigned);
932927
}
933928

934-
private TypeID loadType(TypeVariableContext context, Type type, boolean nullable, boolean unsigned) {
929+
private TypeID loadType(TypeVariableContext context, AnnotatedElement type, boolean nullable, boolean unsigned) {
935930
TypeID result = loadType(context, type, unsigned);
936931
if (nullable)
937932
result = registry.getOptional(result);
@@ -1045,7 +1040,7 @@ private TypeID loadFunctionalInterface(TypeVariableContext loadContext, Class<?>
10451040
getMethodDescriptor(functionalInterfaceMethod),
10461041
JavaModifiers.PUBLIC | JavaModifiers.ABSTRACT,
10471042
header.getReturnType().isGeneric());
1048-
return registry.getFunction(header);
1043+
return new JavaFunctionalInterfaceTypeID(registry, header, functionalInterfaceMethod, method);
10491044
}
10501045

10511046
private <T> TypeVariableContext convertTypeParameters(Class<T> cls) {

0 commit comments

Comments
 (0)