|
|
@@ -28,30 +28,55 @@ public final class RContext extends AContext implements Serializable {
|
|
|
|
|
|
private final AContext parent;
|
|
|
|
|
|
- private final ParameterizedType derived;
|
|
|
+ private final Type derived;
|
|
|
|
|
|
private final RTList<TypeVariable> keys = new RTList<>();
|
|
|
|
|
|
private final RTList<Type> vars = new RTList<>();
|
|
|
|
|
|
- private RContext(IContext parent, ParameterizedType type) {
|
|
|
+ private RContext(IContext parent, Type type) {
|
|
|
this.parent = (AContext)parent;
|
|
|
this.derived = type;
|
|
|
add(type);
|
|
|
}
|
|
|
|
|
|
- static IContext create(IContext parent, ParameterizedType type) {
|
|
|
+ static IContext create(IContext parent, Type type) {
|
|
|
return CACHE.get(parent, type, () -> new RContext(parent, type));
|
|
|
}
|
|
|
|
|
|
- private void add(ParameterizedType type) {
|
|
|
+ private void add(Type type) {
|
|
|
+ if(type instanceof Class<?>) {
|
|
|
+ addc((Class<?>)type);
|
|
|
+ }
|
|
|
+ if(type instanceof ParameterizedType) {
|
|
|
+ addp((ParameterizedType)type);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addc(Class<?> ctype) {
|
|
|
+ Class<?> sc = ctype.getSuperclass();
|
|
|
+
|
|
|
+ if(sc == null || sc.equals(Object.class)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(sc.getTypeParameters().length != 0) {
|
|
|
+ add(ctype.getGenericSuperclass());
|
|
|
+ }
|
|
|
+
|
|
|
+ add(sc);
|
|
|
+ try {
|
|
|
+ add(ctype.getEnclosingClass());
|
|
|
+ } catch (IncompatibleClassChangeError e) {
|
|
|
+ // ca be thrown by dynamic classes: it is not our fault :-)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addp(ParameterizedType type) {
|
|
|
keys.addAll(raw(type).getTypeParameters());
|
|
|
vars.addAll(type.getActualTypeArguments());
|
|
|
-
|
|
|
- Type owner = type.getOwnerType();
|
|
|
- if(owner instanceof ParameterizedType) {
|
|
|
- add((ParameterizedType)owner);
|
|
|
- }
|
|
|
+
|
|
|
+ add(type.getOwnerType());
|
|
|
}
|
|
|
|
|
|
private static Class<?> raw(ParameterizedType type) {
|
|
|
@@ -63,6 +88,16 @@ public final class RContext extends AContext implements Serializable {
|
|
|
return derived.equals(type) || parent.derived(type);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected Type resolve(String type) {
|
|
|
+ for(int i=0, n=keys.size(); i<n; i++) {
|
|
|
+ if( keys.get(i).getName().equals(type) ) {
|
|
|
+ return resolve0(vars.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return parent.resolve(type);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected Type resolve(TypeVariable type) {
|
|
|
for(int i=0, n=keys.size(); i<n; i++) {
|
|
|
@@ -108,6 +143,15 @@ public final class RContext extends AContext implements Serializable {
|
|
|
private final RTList<String> keys;
|
|
|
private final RTList<IClass<?>> vars;
|
|
|
|
|
|
+ protected Type resolve(String type) {
|
|
|
+ for(int i=0, n=keys.size(); i<n; i++) {
|
|
|
+ if( keys.get(i).equals(type) ) {
|
|
|
+ return vars.get(i).reflective();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return parent.resolve(type);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected Type resolve(TypeVariable type) {
|
|
|
for(int i=0, n=keys.size(); i<n; i++) {
|