Przeglądaj źródła

Fixed the JavaNativeModule class to be compatible with the new changes

Stan Hebben 4 lat temu
rodzic
commit
253c367b29

+ 7
- 12
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Wyświetl plik

20
 import org.openzen.zenscript.codemodel.type.*;
20
 import org.openzen.zenscript.codemodel.type.*;
21
 import org.openzen.zenscript.codemodel.type.member.*;
21
 import org.openzen.zenscript.codemodel.type.member.*;
22
 import org.openzen.zenscript.javashared.*;
22
 import org.openzen.zenscript.javashared.*;
23
+import org.openzen.zenscript.javashared.types.JavaFunctionalInterfaceTypeID;
23
 import org.openzen.zenscript.lexer.*;
24
 import org.openzen.zenscript.lexer.*;
24
 import org.openzen.zenscript.parser.*;
25
 import org.openzen.zenscript.parser.*;
25
 import org.openzen.zenscript.parser.expression.*;
26
 import org.openzen.zenscript.parser.expression.*;
889
 			Expression defaultValue = getDefaultValue(parameter, type);
890
 			Expression defaultValue = getDefaultValue(parameter, type);
890
 			parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
891
 			parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
891
 		}
892
 		}
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);
901
 		}
895
 		}
902
-		
896
+
903
 		if (exceptionTypes.length > 1)
897
 		if (exceptionTypes.length > 1)
904
 			throw new IllegalArgumentException("A method can only throw a single exception type!");
898
 			throw new IllegalArgumentException("A method can only throw a single exception type!");
905
 
899
 
900
+		TypeID returnType = javaReturnType == null ? BasicTypeID.VOID : loadStoredType(context, javaReturnType);
906
 		TypeID thrownType = exceptionTypes.length == 0 ? null : loadStoredType(context, exceptionTypes[0]);
901
 		TypeID thrownType = exceptionTypes.length == 0 ? null : loadStoredType(context, exceptionTypes[0]);
907
 		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
902
 		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
908
 	}
903
 	}
931
 		return loadType(context, annotatedType, nullable, unsigned);
926
 		return loadType(context, annotatedType, nullable, unsigned);
932
 	}
927
 	}
933
 	
928
 	
934
-	private TypeID loadType(TypeVariableContext context, Type type, boolean nullable, boolean unsigned) {
929
+	private TypeID loadType(TypeVariableContext context, AnnotatedElement type, boolean nullable, boolean unsigned) {
935
 		TypeID result = loadType(context, type, unsigned);
930
 		TypeID result = loadType(context, type, unsigned);
936
 		if (nullable)
931
 		if (nullable)
937
 			result = registry.getOptional(result);
932
 			result = registry.getOptional(result);
1045
 				getMethodDescriptor(functionalInterfaceMethod),
1040
 				getMethodDescriptor(functionalInterfaceMethod),
1046
 				JavaModifiers.PUBLIC | JavaModifiers.ABSTRACT,
1041
 				JavaModifiers.PUBLIC | JavaModifiers.ABSTRACT,
1047
 				header.getReturnType().isGeneric());
1042
 				header.getReturnType().isGeneric());
1048
-		return registry.getFunction(header);
1043
+		return new JavaFunctionalInterfaceTypeID(registry, header, functionalInterfaceMethod, method);
1049
 	}
1044
 	}
1050
 
1045
 
1051
 	private <T> TypeVariableContext convertTypeParameters(Class<T> cls) {
1046
 	private <T> TypeVariableContext convertTypeParameters(Class<T> cls) {

Ładowanie…
Anuluj
Zapisz