use of org.osgl.inject.BeanSpec in project actframework by actframework.
the class SimpleEventListenerMetaInfo method convert.
public static List<BeanSpec> convert(List<String> paramTypes, String className, String methodName, $.Var<Method> methodHolder) {
int sz = paramTypes.size();
App app = Act.app();
ClassLoader cl = app.classLoader();
Class c = $.classForName(className, cl);
Class[] paramClasses = new Class[sz];
int i = 0;
for (String s : paramTypes) {
paramClasses[i++] = $.classForName(s, cl);
}
Method method = $.getMethod(c, methodName, paramClasses);
method.setAccessible(true);
methodHolder.set(method);
if (0 == sz) {
return C.list();
}
List<BeanSpec> retVal = new ArrayList<>(sz);
Type[] types = method.getGenericParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
DependencyInjector injector = app.injector();
for (i = 0; i < types.length; ++i) {
retVal.add(BeanSpec.of(types[i], annotations[i], null, injector));
}
return C.list(retVal);
}
use of org.osgl.inject.BeanSpec in project java-di by osglworks.
the class GH26 method test.
@Test
public void test() {
Genie genie = Genie.create();
BeanSpec fooHolderSpec = BeanSpec.of(FooHolder.class, genie);
BeanSpec fooSpec = fooHolderSpec.field("foo");
BeanSpec dataSpec = fooSpec.field("data");
eq(String.class, dataSpec.rawType());
}
use of org.osgl.inject.BeanSpec in project java-di by osglworks.
the class Gh18 method test.
@Test
@Ignore
public void test() {
Genie genie = Genie.create();
BeanSpec spec = BeanSpec.of(int[].class, genie);
eq(int.class, spec.typeParams().get(0));
}
use of org.osgl.inject.BeanSpec in project actframework by actframework.
the class Endpoint method paramInfo.
private ParamInfo paramInfo(Type type, Annotation[] annos, DependencyInjector injector, String name) {
if (isLoginUser(annos)) {
return null;
}
BeanSpec spec = BeanSpec.of(type, annos, name, injector);
if (ParamValueLoaderService.providedButNotDbBind(spec, injector)) {
return null;
}
if (ParamValueLoaderService.hasDbBind(spec.allAnnotations())) {
if (org.osgl.util.S.blank(name)) {
name = spec.name();
}
return new ParamInfo(name, BeanSpec.of(String.class, Act.injector()), name + " id");
}
String description = "";
Description descAnno = spec.getAnnotation(Description.class);
if (null != descAnno) {
description = descAnno.value();
}
return new ParamInfo(spec.name(), spec, description);
}
use of org.osgl.inject.BeanSpec in project actframework by actframework.
the class ParamValueLoaderService method findMethodParamLoaders.
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 = method.getParameterAnnotations();
for (int i = 0; i < sz; ++i) {
String name = paramName(i);
Type type = types[i];
if (type instanceof TypeVariable) {
TypeVariable var = $.cast(type);
if (null != host) {
type = Generics.buildTypeParamImplLookup(host).get(var.getName());
}
if (null == type) {
throw new UnexpectedException("Cannot infer param type: %s", var.getName());
}
}
BeanSpec spec = BeanSpec.of(type, annotations[i], name, injector);
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;
}
Aggregations