Search in sources :

Example 11 with BeanSpec

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);
}
Also used : App(act.app.App) DependencyInjector(act.inject.DependencyInjector) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Type(java.lang.reflect.Type) BeanSpec(org.osgl.inject.BeanSpec)

Example 12 with BeanSpec

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());
}
Also used : Genie(org.osgl.inject.Genie) BeanSpec(org.osgl.inject.BeanSpec) Test(org.junit.Test)

Example 13 with BeanSpec

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));
}
Also used : Genie(org.osgl.inject.Genie) BeanSpec(org.osgl.inject.BeanSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with BeanSpec

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);
}
Also used : BeanSpec(org.osgl.inject.BeanSpec)

Example 15 with BeanSpec

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;
}
Also used : UnexpectedException(org.osgl.exception.UnexpectedException) BeanSpec(org.osgl.inject.BeanSpec)

Aggregations

BeanSpec (org.osgl.inject.BeanSpec)16 Annotation (java.lang.annotation.Annotation)4 Test (org.junit.Test)4 Genie (org.osgl.inject.Genie)4 DependencyInjector (act.inject.DependencyInjector)2 UnexpectedException (org.osgl.exception.UnexpectedException)2 App (act.app.App)1 DefaultValue (act.inject.DefaultValue)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Inject (javax.inject.Inject)1 Ignore (org.junit.Ignore)1 org.osgl.$ (org.osgl.$)1 ConfigurationValueLoader (org.osgl.inject.loader.ConfigurationValueLoader)1 ISObject (org.osgl.storage.ISObject)1