|
|
@@ -6,15 +6,19 @@
|
|
|
*/
|
|
|
package net.ranides.assira.reflection.impl;
|
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+
|
|
|
+import net.ranides.assira.collection.lists.RTList;
|
|
|
+import net.ranides.assira.collection.maps.HashMap;
|
|
|
+import net.ranides.assira.generic.SerializationUtils;
|
|
|
+import net.ranides.assira.reflection.*;
|
|
|
+
|
|
|
import java.io.Serializable;
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.lang.reflect.TypeVariable;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
-import net.ranides.assira.collection.lists.RTList;
|
|
|
-import net.ranides.assira.collection.maps.HashMap;
|
|
|
-import net.ranides.assira.generic.SerializationUtils;
|
|
|
-import net.ranides.assira.reflection.IContext;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -84,5 +88,43 @@ public final class RContext extends AContext implements Serializable {
|
|
|
map.putAll(super.map());
|
|
|
return map;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ protected Object writeReplace() {
|
|
|
+ String[] cKeys = keys.stream().map(TypeVariable::getName).toArray(String[]::new);
|
|
|
+ IClass[] cVars = vars.stream().map(this::typeinfo).toArray(IClass[]::new);
|
|
|
+ return new SContext(parent, new RTList<>(cKeys), new RTList<>(cVars));
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiredArgsConstructor
|
|
|
+ private static final class SContext extends AContext implements Serializable {
|
|
|
+
|
|
|
+ private final AContext parent;
|
|
|
+ private final RTList<String> keys;
|
|
|
+ private final RTList<IClass<?>> vars;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Type resolve(TypeVariable type) {
|
|
|
+ for(int i=0, n=keys.size(); i<n; i++) {
|
|
|
+ if( match(keys.get(i), type) ) {
|
|
|
+ return vars.get(i).reflective();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return parent.resolve(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean match(String key, TypeVariable type) {
|
|
|
+ return key.equals(type.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Type> map() {
|
|
|
+ HashMap<String, Type> map = new HashMap<>();
|
|
|
+ for(int i=0, n=keys.size(); i<n; i++) {
|
|
|
+ map.put(keys.get(i), vars.get(i).reflective());
|
|
|
+ }
|
|
|
+ map.putAll(super.map());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|