Browse Source

Added type mapping when generic base type is a class

kindlich 4 years ago
parent
commit
8dd4cef26d
No known key found for this signature in database

+ 12
- 2
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

@@ -899,9 +899,10 @@ public class JavaNativeModule {
899 899
             TypeVariable<?> variable = (TypeVariable<?>) type;
900 900
             return registry.getGeneric(context.get(variable)).stored();
901 901
         }else if(type instanceof AnnotatedType){
902
-		    final StoredType storedType;
902
+		    StoredType storedType;
903 903
 		    if(type instanceof AnnotatedParameterizedType) {
904 904
                 AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) type;
905
+
905 906
                 final Type rawType = ((ParameterizedType) parameterizedType.getType()).getRawType();
906 907
                 final AnnotatedType[] actualTypeArguments = parameterizedType.getAnnotatedActualTypeArguments();
907 908
                 final StoredType[] codeParameters = new StoredType[actualTypeArguments.length];
@@ -911,7 +912,16 @@ public class JavaNativeModule {
911 912
             
912 913
                 if(rawType == Map.class) {
913 914
                     storedType = registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
914
-                } else {
915
+                } else if(rawType instanceof Class<?>){
916
+                	final Map<TypeParameter, StoredType> map = new HashMap<>();
917
+					final TypeVariable<? extends Class<?>>[] typeParameters = ((Class<?>) rawType).getTypeParameters();
918
+					final StoredType loadType = loadType(context, (AnnotatedElement) rawType, unsigned);
919
+					for (int i = 0; i < typeParameters.length; i++) {
920
+						final TypeParameter typeParameter = context.get(typeParameters[i]);
921
+						map.put(typeParameter, codeParameters[i]);
922
+					}
923
+					storedType = loadType.instance(new GenericMapper(CodePosition.NATIVE, registry, map));
924
+				} else {
915 925
                     storedType = loadType(context, (AnnotatedElement) rawType, unsigned);
916 926
                 }
917 927
             } else {

Loading…
Cancel
Save