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());
}
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());
}
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;
}
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();
}
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);
}
}
}
Aggregations