Mariusz Czarnowski 3 vuotta sitten
vanhempi
commit
35c43af6b5

+ 5 - 0
assira.core/src/main/java/net/ranides/assira/collection/iterators/SpliteratorUtils.java

@@ -82,6 +82,11 @@ public final class SpliteratorUtils {
                 && spliterator.tryAdvance(t -> { if ((active = condition.test(t))) { action.accept(t); }})
                 && active;
         }
+
+        @Override
+        public Comparator<? super T> getComparator() {
+            return spliterator.getComparator();
+        }
     }
 
     /**

+ 24 - 0
assira.core/src/main/java/net/ranides/assira/reflection/impl/FClass.java

@@ -22,6 +22,7 @@ import net.ranides.assira.collection.arrays.NativeArrayBuilder;
 import net.ranides.assira.lexer.StringTokenizer;
 import net.ranides.assira.reflection.IClass;
 import net.ranides.assira.reflection.IContext;
+import net.ranides.assira.reflection.IExecutable;
 import net.ranides.assira.reflection.IReflectiveException;
 import net.ranides.assira.reflection.util.ClassUtils;
 
@@ -88,6 +89,29 @@ public final class FClass {
         }
     }
 
+    public static IClass<?> newArgumentClass(IExecutable method, IContext context, Type itype, AnnotatedType atype) {
+        if(itype instanceof GenericArrayType) {
+            return FClass.newClass(context, (GenericArrayType) itype);
+        } else {
+            return CACHE.get(context, atype, () -> newArgumentClass0(method, context, itype, atype));
+        }
+    }
+
+    private static RFClass<?> newArgumentClass0(IExecutable method, IContext context, Type itype, AnnotatedType atype) {
+        boolean isGenericMethodParam = method.params().stream().map(IClass::reflective).anyMatch(itype::equals);
+
+        if(!isGenericMethodParam) {
+            return new RFClass<>(context, context.typeinfo(itype), atype);
+        }
+
+        IClass<?> typeinfo = context.typeinfo(itype);
+        if(typeinfo instanceof RWClass<?>) {
+            typeinfo = ((RWClass<?>)typeinfo).swap();
+        }
+
+        return new RFClass<>(context, typeinfo, atype);
+    }
+
     /**
      * Creates IClass for provided annotated type, using context for type resolution.
      *

+ 1 - 1
assira.core/src/main/java/net/ranides/assira/reflection/impl/RArgument.java

@@ -60,7 +60,7 @@ public class RArgument extends AElement implements IArgument, Serializable {
     @Override
     public IClass<?> type() {
         final IContext c = context();
-        return FClass.newClass(c, param.getParameterizedType(), param.getAnnotatedType());
+        return FClass.newArgumentClass(parent(), c, param.getParameterizedType(), param.getAnnotatedType());
     }
 
     @Override

+ 13 - 1
assira.core/src/main/java/net/ranides/assira/reflection/impl/RWClass.java

@@ -57,7 +57,15 @@ public class RWClass<T> extends AClass<T> implements Serializable {
         this.lower = EMPTY;
         this.atype = type;
     }
-    
+
+    public RWClass(IContext context, Type type, IClass<?>[] upper, IClass<?>[] lower, AnnotatedElement atype) {
+        super(context);
+        this.type = type;
+        this.upper = upper;
+        this.lower = lower;
+        this.atype = atype;
+    }
+
     @Override
     public IAnnotations annotations() {
         AHints attr = FElements.newHints();
@@ -127,6 +135,10 @@ public class RWClass<T> extends AClass<T> implements Serializable {
         return WATTRS;
     }
 
+    public IClass<?> swap() {
+        return new RWClass<>(context(), type, lower, upper, atype);
+    }
+
     private CQuery<Annotation> getAnnotations(AHints attr) {
         return CQuery.from().array(() -> {
             boolean is = attr.require().contains(IAttribute.DECLARED);