Search in sources :

Example 1 with BeanSpec

use of org.osgl.inject.BeanSpec in project java-di by osglworks.

the class Gh20 method test.

@Test
public void test() {
    Genie genie = Genie.create();
    BeanSpec spec = BeanSpec.of(int[].class, genie);
    eq(int.class, spec.componentSpec().rawType());
}
Also used : Genie(org.osgl.inject.Genie) BeanSpec(org.osgl.inject.BeanSpec) Test(org.junit.Test)

Example 2 with BeanSpec

use of org.osgl.inject.BeanSpec in project java-di by osglworks.

the class Gh19 method test.

@Test
public void test() {
    Genie genie = Genie.create();
    BeanSpec spec = BeanSpec.of(IntA.class, genie);
    yes(spec.isInterface());
    spec = BeanSpec.of(Gh19.class, genie);
    no(spec.isInterface());
}
Also used : Genie(org.osgl.inject.Genie) BeanSpec(org.osgl.inject.BeanSpec) Test(org.junit.Test)

Example 3 with BeanSpec

use of org.osgl.inject.BeanSpec in project actframework by actframework.

the class ReflectedJobInvoker method paramTypes.

private Class[] paramTypes() {
    List<BeanSpec> paramTypes = methodInfo.paramTypes();
    int sz = null == paramTypes ? 0 : paramTypes.size();
    Class[] ca = new Class[sz];
    for (int i = 0; i < sz; ++i) {
        BeanSpec spec = methodInfo.paramTypes().get(i);
        ca[i] = spec.rawType();
    }
    return ca;
}
Also used : BeanSpec(org.osgl.inject.BeanSpec)

Example 4 with BeanSpec

use of org.osgl.inject.BeanSpec in project actframework by actframework.

the class JsonDTOClassGenerator method typeDesc.

private static String typeDesc(BeanSpec spec) {
    String root = classDesc(spec.rawType());
    List<java.lang.reflect.Type> typeParams = spec.typeParams();
    if (typeParams.isEmpty()) {
        return root;
    }
    S.Buffer sb = S.newBuffer("<");
    for (java.lang.reflect.Type type : typeParams) {
        BeanSpec specx = BeanSpec.of(type, null, spec.injector());
        sb.append(typeDesc(specx));
    }
    sb.append(">");
    FastStr str = FastStr.of(root);
    str = str.take(str.length() - 1).append(sb.toString()).append(";");
    return str.toString();
}
Also used : FastStr(org.osgl.util.FastStr) S(org.osgl.util.S) BeanSpec(org.osgl.inject.BeanSpec)

Example 5 with BeanSpec

use of org.osgl.inject.BeanSpec in project actframework by actframework.

the class JsonDTOClassManager method extractBeanSpec.

private void extractBeanSpec(List<BeanSpec> beanSpecs, List<Field> fields, Class<?> host) {
    for (Field field : fields) {
        BeanSpec spec = null;
        Type genericType = field.getGenericType();
        if (genericType instanceof Class || genericType instanceof ParameterizedType) {
            spec = BeanSpec.of(field.getGenericType(), field.getDeclaredAnnotations(), field.getName(), injector);
        } else if (genericType instanceof TypeVariable) {
            // can determine type by field, check inject constructor parameter
            TypeVariable tv = (TypeVariable) genericType;
            Type[] bounds = tv.getBounds();
            if (bounds != null && bounds.length == 1) {
                Type bound = bounds[0];
                if (bound instanceof ParameterizedType || bound instanceof Class) {
                    Class<?> boundClass = BeanSpec.rawTypeOf(bound);
                    Constructor<?>[] ca = host.getConstructors();
                    CONSTRUCTORS: for (Constructor<?> c : ca) {
                        if (c.getAnnotation(Inject.class) != null) {
                            // check all param types
                            Type[] constructorParams = c.getGenericParameterTypes();
                            for (Type paramType : constructorParams) {
                                if (paramType instanceof ParameterizedType || paramType instanceof Class) {
                                    Class<?> paramClass = BeanSpec.rawTypeOf(paramType);
                                    if (boundClass.isAssignableFrom(paramClass)) {
                                        spec = BeanSpec.of(paramType, field.getDeclaredAnnotations(), field.getName(), injector);
                                        break CONSTRUCTORS;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (null == spec) {
            throw E.unexpected("Cannot determine bean spec of field: %s", field);
        }
        if (ParamValueLoaderService.providedButNotDbBind(spec, injector)) {
            continue;
        }
        String dbBindName = dbBindName(spec);
        if (null != dbBindName) {
            beanSpecs.add(BeanSpec.of(String.class, new Annotation[0], dbBindName, injector));
        } else {
            if (ParamValueLoaderService.providedButNotDbBind(spec, injector)) {
                return;
            }
            beanSpecs.add(spec);
        }
    }
}
Also used : Inject(javax.inject.Inject) BeanSpec(org.osgl.inject.BeanSpec) Annotation(java.lang.annotation.Annotation)

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