Search in sources :

Example 1 with Bean

use of com.blade.ioc.annotation.Bean in project blade by biezhi.

the class ClassDefineTest method testClassDefine.

@Test
public void testClassDefine() {
    ClassDefine classDefine = ClassDefine.create(BladeClassDefineType.class);
    int modifires = classDefine.getModifiers();
    Field[] fields = classDefine.getDeclaredFields();
    Bean bean = classDefine.getAnnotation(Bean.class);
    Annotation[] annotations = classDefine.getAnnotations();
    List<ClassDefine> interfaces = classDefine.getInterfaces();
    String name = classDefine.getName();
    String simpleName = classDefine.getSimpleName();
    ClassDefine superKlass = classDefine.getSuperKlass();
    Class<?> type = classDefine.getType();
    assertEquals(Modifier.PUBLIC, modifires);
    assertEquals(2, fields.length);
    assertNotNull(bean);
    assertEquals(1, annotations.length);
    assertEquals(0, interfaces.size());
    assertEquals("com.blade.types.BladeClassDefineType", name);
    assertEquals("BladeClassDefineType", simpleName);
    assertEquals(Object.class, superKlass.getType());
    assertEquals(BladeClassDefineType.class, type);
    assertEquals(false, classDefine.isAbstract());
    assertEquals(false, classDefine.isInterface());
    assertEquals(false, classDefine.isStatic());
    assertEquals(true, classDefine.isPublic());
    assertEquals(false, classDefine.isPrivate());
    assertEquals(false, classDefine.isProtected());
    assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
    assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
}
Also used : Field(java.lang.reflect.Field) ClassDefine(com.blade.ioc.bean.ClassDefine) BladeWebHookType(com.blade.types.BladeWebHookType) Annotation(java.lang.annotation.Annotation) Bean(com.blade.ioc.annotation.Bean) Test(org.junit.Test)

Example 2 with Bean

use of com.blade.ioc.annotation.Bean in project blade by biezhi.

the class SimpleIoc method addBean.

/**
 * Register @Bean marked objects
 */
@Override
public <T> T addBean(Class<T> type) {
    Bean beanAnnotation = type.getAnnotation(Bean.class);
    boolean isSingleton = null == beanAnnotation || beanAnnotation.singleton();
    if (isSingleton) {
        Object bean = put(type, true);
        return type.cast(bean);
    }
    return null;
}
Also used : Bean(com.blade.ioc.annotation.Bean)

Aggregations

Bean (com.blade.ioc.annotation.Bean)2 ClassDefine (com.blade.ioc.bean.ClassDefine)1 BladeWebHookType (com.blade.types.BladeWebHookType)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1