private static Class identifyWhichTypeThisCollectionHas( final Field field ){ final Typed annotation = field.getAnnotation( Typed.class ); return annotation.value()[0]; } }
private static void addApiTypes(final Collection<Type> clazzes, final Class<?> beanClass) { final Typed typed = beanClass.getAnnotation(Typed.class); if (typed == null || typed.value().length == 0) { Type current = beanClass; while (current != null && Object.class != current) { clazzes.add(current); // TODO: better loop current = Class.class.isInstance(current) ? Class.class.cast(current).getGenericSuperclass() : null; } } else { Collections.addAll(clazzes, typed.value()); } } }
private static Class<?>[] getBindingTypes( final Class<?> clazz ) { if ( HAS_TYPED ) { for ( Class<?> c = clazz; c != Object.class; c = c.getSuperclass() ) { final javax.enterprise.inject.Typed typed = c.getAnnotation( javax.enterprise.inject.Typed.class ); if ( null != typed ) { return typed.value().length > 0 ? typed.value() : c.getInterfaces(); } } } return null; } }
private static void addApiTypes(final Collection<Type> clazzes, final Class<?> beanClass) { final Typed typed = beanClass.getAnnotation(Typed.class); if (typed == null || typed.value().length == 0) { Class<?> current = beanClass; while (current != null && !Object.class.equals(current)) { clazzes.add(current); current = current.getSuperclass(); } } else { Collections.addAll(clazzes, typed.value()); } } }
private Set<Type> calcBeanTypes(Type implTpye) { Set<Type> beanTypes = Sets.newHashSet(); if (implTpye instanceof ParameterizedType) { beanTypes.add((ParameterizedType) implTpye); } else { Typed typedAnnotation = ((Class<?>) implTpye).getAnnotation(Typed.class); if (typedAnnotation != null) { for (Class<?> cls : typedAnnotation.value()) { beanTypes.add(cls); } } else { beanTypes.addAll(getTypeClasses((Class<?>) implTpye)); } } return beanTypes; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
/** * Bean types of a bean that uses the {@link Typed} annotation. */ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?> rawType, Typed typed) { Set<Type> types = new HashSet<Type>(); for (Class<?> specifiedClass : typed.value()) { Type tmp = typeClosure.get(specifiedClass); if (tmp != null) { types.add(tmp); } else { throw BeanLogger.LOG.typedClassNotInHierarchy(specifiedClass.getName(), rawType, Formats.formatTypes(typeClosure.values())); } } types.add(Object.class); return types; }
private Predicate<List<InjectableHandle>> getPathPredicate(final HasAnnotations annotated, final List<String> problems) { if (annotated.isAnnotationPresent(Typed.class)) { final Class<?>[] beanTypes = annotated.getAnnotation(Typed.class).value(); validateAssignableTypes(annotated, beanTypes, problems); return path -> Object.class.getName().equals(path.get(0)) || Arrays.stream(beanTypes) .anyMatch(beanType -> path.get(0).getType().getFullyQualifiedName().equals(beanType.getName())); } else { return ANY; } }
public static <T> ProvidableField from( Collection<Class<? extends Annotation>> qualifiers, final Field field ) { field.setAccessible( true ); final Typed Inject = field.getAnnotation( Typed.class ); final Class expectedClass = Inject != null ? Inject.value()[0] : field.getType(); return new SingleElementProvidableField<>( field, (Class<T>)expectedClass, createInjectionCondition( qualifiers, field ), new FieldProviderContext( qualifiers, field ) ); }
public static AbstractStatementBuilder getAssignableTypesArrayStmt(final Injectable injectable) { final Object[] assignableTypes = injectable.getAnnotatedObject() .flatMap(annotated -> Optional.ofNullable(annotated.getAnnotation(Typed.class))) .map(typedAnno -> typedAnno.value()) // Ensure that Object is an assignable type .map(beanTypes -> { if (Arrays.stream(beanTypes).anyMatch(type -> Object.class.equals(type))) { return (Object[]) beanTypes; } else { final Class<?>[] copyWithObject = Arrays.copyOf(beanTypes, beanTypes.length+1); copyWithObject[beanTypes.length] = Object.class; return (Object[]) copyWithObject; } }) .orElseGet(() -> getAllAssignableTypes(injectable.getInjectedType()).stream().filter(MetaClass::isPublic).toArray()); return newArray(Class.class).initialize(assignableTypes); }
private boolean containsAllSuperclassTypes(AnnotatedType<?> annotatedType, Class<?> superClass, Collection<AnnotatedType<?>> annotatedTypes) { Typed typed = annotatedType.getAnnotation(Typed.class); if (typed != null) { List<Class<?>> typeList = Arrays.asList(typed.value()); AnnotatedType<?> superType = getAnnotatedTypeForClass(annotatedTypes, superClass); if (superType != null) { Typed superClassTyped = superType.getAnnotation(Typed.class); Set<Type> superClassTypes; if (superClassTyped != null) { superClassTypes = new HashSet<>(Arrays.asList(superClassTyped.value())); } else { superClassTypes = superType.getTypeClosure(); // we can ignore Object.class in this case superClassTypes.remove(Object.class); } return typeList.containsAll(superClassTypes); } } return true; }
beanClass.isAnnotationPresent(Specializes.class) || (beanClass.isAnnotationPresent(Typed.class) && beanClass.getAnnotation(Typed.class).value().length == 0))
if (beanTypes != null) Class<?>[] typedTypes = beanTypes.value();
if (typed != null) Collections.addAll(foundTypes, typed.value());
if (typed != null) Collections.addAll(foundTypes, typed.value());
_typeClasses = fillTyped(baseTypes, typed.value());