/** * Build class type variable name and type variable implementation lookup * * @param theClass the class to build the lookup * @return the lookup */ public static Map<String, Class> buildTypeParamImplLookup(Class theClass) { Map<String, Class> lookup = new HashMap<>(); buildTypeParamImplLookup(theClass, lookup); return lookup; }
/** * Build class type variable name and type variable implementation lookup * * @param theClass the class to build the lookup * @return the lookup */ public static Map<String, Class> buildTypeParamImplLookup(Class theClass) { Map<String, Class> lookup = new HashMap<>(); buildTypeParamImplLookup(theClass, lookup); return lookup; }
private Map<String, Class> getTypeLookup(Class host) { Map<String, Class> lookup = typeLookupLookup.get(host); if (null == lookup) { lookup = Generics.buildTypeParamImplLookup(host); typeLookupLookup.put(host, lookup); } return lookup; }
private Map<String, Class> getTypeLookup(Class host) { Map<String, Class> lookup = typeLookupLookup.get(host); if (null == lookup) { lookup = Generics.buildTypeParamImplLookup(host); typeLookupLookup.put(host, lookup); } return lookup; }
public static void buildTypeParamImplLookup(Class theClass, Map<String, Class> lookup) { if (null == theClass || Object.class == theClass) { return; } // what type variable of the super class implemented by this class Type superType = theClass.getGenericSuperclass(); if (superType instanceof ParameterizedType) { ParameterizedType ptype = $.cast(superType); Type[] typeParams = ptype.getActualTypeArguments(); TypeVariable[] typeArgs = theClass.getSuperclass().getTypeParameters(); buildTypeParamImplLookup("", typeParams, typeArgs, lookup); } buildTypeParamImplLookup(theClass.getSuperclass(), lookup); }
public static void buildTypeParamImplLookup(Class theClass, Map<String, Class> lookup) { if (null == theClass || Object.class == theClass) { return; } // what type variable of the super class implemented by this class Type superType = theClass.getGenericSuperclass(); if (superType instanceof ParameterizedType) { ParameterizedType ptype = $.cast(superType); Type[] typeParams = ptype.getActualTypeArguments(); TypeVariable[] typeArgs = theClass.getSuperclass().getTypeParameters(); buildTypeParamImplLookup("", typeParams, typeArgs, lookup); } buildTypeParamImplLookup(theClass.getSuperclass(), lookup); }
private void exploreTypes() { Map<String, Class> typeParamLookup = Generics.buildTypeParamImplLookup(getClass()); List<Type> types = Generics.typeParamImplementations(getClass(), SimpleRestfulServiceBase.class); int sz = types.size(); if (sz < 3) { throw new IllegalArgumentException("Cannot determine DAO type"); } Type daoType = types.get(2); BeanSpec spec = BeanSpec.of(daoType, Act.injector(), typeParamLookup); DaoLoader loader = Act.getInstance(DaoLoader.class); dao = $.cast(loader.load(spec)); }
Map<String, Class> lookup = Generics.buildTypeParamImplLookup(theClass); String name = ((TypeVariable) type).getName(); Class<?> realType = lookup.get(name);
private void exploreTypes() { Map<String, Class> typeParamLookup = Generics.buildTypeParamImplLookup(getClass()); List<Type> types = Generics.typeParamImplementations(getClass(), SimpleRestfulServiceBase.class); int sz = types.size(); if (sz < 3) { throw new IllegalArgumentException("Cannot determine DAO type"); } Type daoType = types.get(2); BeanSpec spec = BeanSpec.of(daoType, Act.injector(), typeParamLookup); DaoLoader loader = Act.getInstance(DaoLoader.class); dao = $.cast(loader.load(spec)); }
Map<String, Class> lookup = Generics.buildTypeParamImplLookup(theClass); String name = ((TypeVariable) type).getName(); Class<?> realType = lookup.get(name);
if (rawType instanceof Class) { lookup.put(lookupKey(typeVar, prefix), (Class) rawType); buildTypeParamImplLookup(lookupKey(typeVar, prefix), ptype0.getActualTypeArguments(), ((Class) rawType).getTypeParameters(), lookup); } else { throw new UnexpectedException("Unknown typeParam: " + ptype0);
public Class<? extends JsonDto> get(List<BeanSpec> beanSpecs, Class<?> host) { String key = key(beanSpecs); if (S.blank(key)) { return null; } Class<? extends JsonDto> cls = dtoClasses.get(key); if (null == cls) { try { Map<String, Class> typeParamLookup = Generics.buildTypeParamImplLookup(host); Class<? extends JsonDto> newClass = generate(key, beanSpecs, typeParamLookup); cls = dtoClasses.putIfAbsent(key, newClass); if (null == cls) { cls = newClass; } } catch (LinkageError e) { if (e.getMessage().contains("duplicate class definition")) { // another thread has already the DTO class cls = dtoClasses.get(key); E.unexpectedIf(null == cls, "We don't know what happened here ..."); } else { throw e; } } } return cls; }
String typeVarName = typeVar.getName(); Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(host); type = typeVarLookup.get(typeVarName); if (null == type) { if (type instanceof ParameterizedType && !isStatic) { Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(host); spec = BeanSpec.of(type, anno, injector, typeVarLookup); } else {
if (rawType instanceof Class) { lookup.put(lookupKey(typeVar, prefix), (Class) rawType); buildTypeParamImplLookup(lookupKey(typeVar, prefix), ptype0.getActualTypeArguments(), ((Class) rawType).getTypeParameters(), lookup); } else { throw new UnexpectedException("Unknown typeParam: " + ptype0);
String typeVarName = typeVar.getName(); Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(host); type = typeVarLookup.get(typeVarName); if (null == type) { if (type instanceof ParameterizedType && !isStatic) { Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(host); spec = BeanSpec.of(type, anno, injector, typeVarLookup); } else {
public Class<? extends JsonDto> get(List<BeanSpec> beanSpecs, Class<?> host) { String key = key(beanSpecs); if (S.blank(key)) { return null; } Class<? extends JsonDto> cls = dtoClasses.get(key); if (null == cls) { try { Map<String, Class> typeParamLookup = Generics.buildTypeParamImplLookup(host); Class<? extends JsonDto> newClass = generate(key, beanSpecs, typeParamLookup); cls = dtoClasses.putIfAbsent(key, newClass); if (null == cls) { cls = newClass; } } catch (LinkageError e) { if (e.getMessage().contains("duplicate class definition")) { // another thread has already the DTO class cls = dtoClasses.get(key); E.unexpectedIf(null == cls, "We don't know what happened here ..."); } else { throw e; } } } return cls; }
protected ParamValueLoader[] findMethodParamLoaders( Method method, Class host, ActContext ctx, $.Var<Boolean> hasValidationConstraint) { Type[] types = method.getGenericParameterTypes(); int sz = types.length; if (0 == sz) { return DUMB; } ParamValueLoader[] loaders = new ParamValueLoader[sz]; Annotation[][] annotations = ReflectedInvokerHelper.requestHandlerMethodParamAnnotations(method); for (int i = 0; i < sz; ++i) { String name = paramName(i); Type type = types[i]; Map<String, Class> typeLookups = null; if (type instanceof TypeVariable || type instanceof ParameterizedType) { typeLookups = Generics.buildTypeParamImplLookup(host); } BeanSpec spec = BeanSpec.of(type, annotations[i], name, injector, typeLookups); if (hasValidationConstraint(spec)) { hasValidationConstraint.set(true); } ParamValueLoader loader = paramValueLoaderOf(spec, ctx); if (null == loader) { throw new UnexpectedException("Cannot find param value loader for param: " + spec); } loaders[i] = loader; } return loaders; }
protected ParamValueLoader[] findMethodParamLoaders( Method method, Class host, ActContext ctx, $.Var<Boolean> hasValidationConstraint) { Type[] types = method.getGenericParameterTypes(); int sz = types.length; if (0 == sz) { return DUMB; } ParamValueLoader[] loaders = new ParamValueLoader[sz]; Annotation[][] annotations = ReflectedInvokerHelper.requestHandlerMethodParamAnnotations(method); for (int i = 0; i < sz; ++i) { String name = paramName(i); Type type = types[i]; Map<String, Class> typeLookups = null; if (type instanceof TypeVariable || type instanceof ParameterizedType) { typeLookups = Generics.buildTypeParamImplLookup(host); } BeanSpec spec = BeanSpec.of(type, annotations[i], name, injector, typeLookups); if (hasValidationConstraint(spec)) { hasValidationConstraint.set(true); } ParamValueLoader loader = paramValueLoaderOf(spec, ctx); if (null == loader) { throw new UnexpectedException("Cannot find param value loader for param: " + spec); } loaders[i] = loader; } return loaders; }
typeParamLookup = Generics.buildTypeParamImplLookup(controllerClass);
typeParamLookup = Generics.buildTypeParamImplLookup(controllerClass);