private void introspectInjectClass( AnnotatedType<X> type, ArrayList<ConfigProgram> injectProgramList) { InjectManager cdiManager = getBeanManager(); for (Annotation ann : type.getAnnotations()) { Class<? extends Annotation> annType = ann.annotationType(); InjectionPointHandler handler = cdiManager.getInjectionPointHandler(annType); if (handler != null) { injectProgramList.add(new ClassHandlerProgram(ann, handler)); } } // ioc/123i for (Class<?> parentClass = type.getJavaClass().getSuperclass(); parentClass != null; parentClass = parentClass.getSuperclass()) { for (Annotation ann : parentClass.getAnnotations()) { Class<? extends Annotation> annType = ann.annotationType(); InjectionPointHandler handler = cdiManager.getInjectionPointHandler(annType); if (handler != null) { injectProgramList.add(new ClassHandlerProgram(ann, handler)); } } } }
/** * Generates a unique signature for an annotated type. Members without annotations are omitted to * reduce the length of the signature * * @param <X> * @param annotatedType * @return */ public static <X> String createTypeId(AnnotatedType<X> annotatedType) { return createTypeId( annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors()); }
/** * Read the {@link AnnotatedType}, creating a bean from the class and it's annotations. * * <p> * * <p>By default the bean lifecycle will wrap the result of calling {@link * BeanManager#createInjectionTarget(AnnotatedType)}. * * <p> * * <p>{@link BeanBuilder} does <em>not</em> support reading members of the class to create * producers or observer methods. * * @param type the type to read */ public BeanBuilder<T> readFromType(AnnotatedType<T> type) { this.beanClass = type.getJavaClass(); InjectionTarget<T> injectionTarget; if (!type.getJavaClass().isInterface()) { injectionTarget = beanManager.createInjectionTarget(type); } else { injectionTarget = new DummyInjectionTarget<T>(); } this.beanLifecycle = new DelegatingContextualLifecycle<T>(injectionTarget); this.injectionPoints = injectionTarget.getInjectionPoints(); this.qualifiers = new HashSet<Annotation>(); this.stereotypes = new HashSet<Class<? extends Annotation>>(); this.types = new HashSet<Type>(); for (Annotation annotation : type.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { this.qualifiers.add(annotation); } else if (beanManager.isScope(annotation.annotationType())) { this.scope = annotation.annotationType(); } else if (beanManager.isStereotype(annotation.annotationType())) { this.stereotypes.add(annotation.annotationType()); } if (annotation instanceof Named) { this.name = ((Named) annotation).value(); } if (annotation instanceof Alternative) { this.alternative = true; } } if (this.scope == null) { this.scope = Dependent.class; } for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass()) { this.types.add(c); } for (Class<?> i : type.getJavaClass().getInterfaces()) { this.types.add(i); } if (qualifiers.isEmpty()) { qualifiers.add(new DefaultLiteral()); } qualifiers.add(new AnyLiteral()); this.id = ImmutableBeanWrapper.class.getName() + ":" + Annotateds.createTypeId(type); return this; }
private UnbackedAnnotatedType( AnnotatedType<X> source, AnnotatedTypeIdentifier identifier, SharedObjectCache cache) { super(source.getBaseType(), source.getTypeClosure(), source.getAnnotations()); this.javaClass = source.getJavaClass(); ImmutableSet.Builder<AnnotatedConstructor<X>> constructors = ImmutableSet.builder(); for (AnnotatedConstructor<X> constructor : source.getConstructors()) { constructors.add(UnbackedAnnotatedConstructor.of(constructor, this, cache)); } this.constructors = constructors.build(); ImmutableSet.Builder<AnnotatedMethod<? super X>> methods = ImmutableSet.builder(); for (AnnotatedMethod<? super X> originalMethod : source.getMethods()) { methods.add(UnbackedAnnotatedMethod.of(originalMethod, this, cache)); } this.methods = methods.build(); ImmutableSet.Builder<AnnotatedField<? super X>> fields = ImmutableSet.builder(); for (AnnotatedField<? super X> originalField : source.getFields()) { fields.add(UnbackedAnnotatedField.of(originalField, this, cache)); } this.fields = fields.build(); this.identifier = identifier; }