/** * Illegal bean types are ignored except fo array and primitive types and unless {@link Typed} is used. * * @return the set of bean types from an annotated element */ public static Set<Type> getTypes(EnhancedAnnotated<?, ?> annotated) { // array and primitive types require special treatment if (annotated.getJavaClass().isArray() || annotated.getJavaClass().isPrimitive()) { return ImmutableSet.<Type>builder().addAll(annotated.getBaseType(), Object.class).build(); } else { if (annotated.isAnnotationPresent(Typed.class)) { return ImmutableSet.<Type>builder().addAll(getTypedTypes(Reflections.buildTypeMap(annotated.getTypeClosure()), annotated.getJavaClass(), annotated.getAnnotation(Typed.class))).build(); } else { if (annotated.getJavaClass().isInterface()) { return getLegalBeanTypes(annotated.getTypeClosure(), annotated, Object.class); } return getLegalBeanTypes(annotated.getTypeClosure(), annotated); } } }
public static <T, E> MergedStereotypes<T, E> of(EnhancedAnnotated<T, E> annotated, BeanManagerImpl manager) { return of(annotated.getMetaAnnotations(Stereotype.class), manager); }
public Type[] getActualTypeArguments() { return delegate().getActualTypeArguments(); }
/** * Initializes the name */ protected void initName(EnhancedAnnotated<T, ?> annotated) { boolean beanNameDefaulted = false; if (annotated.isAnnotationPresent(Named.class)) { String javaName = annotated.getAnnotation(Named.class).value(); if ("".equals(javaName)) { beanNameDefaulted = true; } else { this.name = javaName; return; } } if (beanNameDefaulted || (mergedStereotypes != null && mergedStereotypes.isBeanNameDefaulted())) { this.name = getDefaultName(annotated); } }
protected boolean initScopeFromStereotype() { Set<Annotation> possibleScopes = mergedStereotypes.getPossibleScopes(); if (possibleScopes.size() == 1) { this.scope = possibleScopes.iterator().next().annotationType(); return true; } else if (possibleScopes.size() > 1) { String stack; Class<?> declaringClass; if (annotated instanceof EnhancedAnnotatedMember) { EnhancedAnnotatedMember<?, ?, ?> member = (EnhancedAnnotatedMember<?, ?, ?>) annotated; declaringClass = member.getDeclaringType().getJavaClass(); stack = "\n at " + Formats.formatAsStackTraceElement(member.getJavaMember()); } else { declaringClass = annotated.getJavaClass(); stack = ""; } throw BeanLogger.LOG.multipleScopesFoundFromStereotypes(Formats.formatType(declaringClass, false), Formats.formatTypes(mergedStereotypes.getStereotypes(), false), possibleScopes, stack); } else { return false; } }
for (EnhancedAnnotatedType<?> clazz = weldClass; clazz != null; clazz = clazz.getEnhancedSuperclass()) { Set<Annotation> scopes = new HashSet<Annotation>(); scopes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class)); scopes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class)); validateScopeSet(scopes, annotated); if (scopes.size() == 1) { if (annotated.isAnnotationPresent(scopes.iterator().next().annotationType())) { this.scope = scopes.iterator().next().annotationType(); scopes.addAll(annotated.getMetaAnnotations(Scope.class)); scopes.addAll(annotated.getMetaAnnotations(NormalScope.class)); if (scopes.size() == 1) { this.scope = scopes.iterator().next().annotationType(); validateScopeSet(scopes, annotated); initScopeFromStereotype();
/** * Is alternative. * * @param annotated the annotated * @param mergedStereotypes merged stereotypes * @return true if alternative, false otherwise */ public static boolean isAlternative(EnhancedAnnotated<?, ?> annotated, MergedStereotypes<?, ?> mergedStereotypes) { return annotated.isAnnotationPresent(Alternative.class) || mergedStereotypes.isAlternative(); }
protected void initQualifiers(EnhancedAnnotated<?, ?> annotated) { initQualifiers(annotated.getMetaAnnotations(Qualifier.class)); }
public AbstractInferringInjectionPointAttributes(EnhancedAnnotated<?, ?> annotatedElement, String contextId, Bean<?> bean, Set<Annotation> qualifiers, Class<?> declaringComponentClass) { this.bean = BeanHolder.of(contextId, bean); this.qualifiers = qualifiers; if (bean == null) { this.typeAttribute = new NonContextualInjectionPointTypeAttribute(declaringComponentClass); } else { this.typeAttribute = new BeanInjectionPointTypeAttribute(); } this.delegate = annotatedElement.isAnnotationPresent(Delegate.class); }
public Class<T> getJavaClass() { return delegate().getJavaClass(); }
@Deprecated public Annotation[] getBindingsAsArray() { return delegate().getBindingsAsArray(); }
public Set<Type> getInterfaceClosure() { return delegate().getInterfaceClosure(); }
protected boolean initScopeFromStereotype() { Set<Annotation> possibleScopes = mergedStereotypes.getPossibleScopes(); if (possibleScopes.size() == 1) { this.scope = possibleScopes.iterator().next().annotationType(); return true; } else if (possibleScopes.size() > 1) { String stack; Class<?> declaringClass; if (annotated instanceof EnhancedAnnotatedMember) { EnhancedAnnotatedMember<?, ?, ?> member = (EnhancedAnnotatedMember<?, ?, ?>) annotated; declaringClass = member.getDeclaringType().getJavaClass(); stack = "\n at " + Formats.formatAsStackTraceElement(member.getJavaMember()); } else { declaringClass = annotated.getJavaClass(); stack = ""; } throw BeanLogger.LOG.multipleScopesFoundFromStereotypes(Formats.formatType(declaringClass, false), Formats.formatTypes(mergedStereotypes.getStereotypes(), false), possibleScopes, stack); } else { return false; } }
for (EnhancedAnnotatedType<?> clazz = weldClass; clazz != null; clazz = clazz.getEnhancedSuperclass()) { Set<Annotation> scopes = new HashSet<Annotation>(); scopes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class)); scopes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class)); validateScopeSet(scopes, annotated); if (scopes.size() == 1) { if (annotated.isAnnotationPresent(scopes.iterator().next().annotationType())) { this.scope = scopes.iterator().next().annotationType(); scopes.addAll(annotated.getMetaAnnotations(Scope.class)); scopes.addAll(annotated.getMetaAnnotations(NormalScope.class)); if (scopes.size() == 1) { this.scope = scopes.iterator().next().annotationType(); validateScopeSet(scopes, annotated); initScopeFromStereotype();
/** * Initializes the name */ protected void initName(EnhancedAnnotated<T, ?> annotated) { boolean beanNameDefaulted = false; if (annotated.isAnnotationPresent(Named.class)) { String javaName = annotated.getAnnotation(Named.class).value(); if ("".equals(javaName)) { beanNameDefaulted = true; } else { this.name = javaName; return; } } if (beanNameDefaulted || (mergedStereotypes != null && mergedStereotypes.isBeanNameDefaulted())) { this.name = getDefaultName(annotated); } }
/** * Is alternative. * * @param annotated the annotated * @param mergedStereotypes merged stereotypes * @return true if alternative, false otherwise */ public static boolean isAlternative(EnhancedAnnotated<?, ?> annotated, MergedStereotypes<?, ?> mergedStereotypes) { return annotated.isAnnotationPresent(Alternative.class) || mergedStereotypes.isAlternative(); }
protected void initQualifiers(EnhancedAnnotated<?, ?> annotated) { initQualifiers(annotated.getMetaAnnotations(Qualifier.class)); }
public AbstractInferringInjectionPointAttributes(EnhancedAnnotated<?, ?> annotatedElement, String contextId, Bean<?> bean, Set<Annotation> qualifiers, Class<?> declaringComponentClass) { this.bean = BeanHolder.of(contextId, bean); this.qualifiers = qualifiers; if (bean == null) { this.typeAttribute = new NonContextualInjectionPointTypeAttribute(declaringComponentClass); } else { this.typeAttribute = new BeanInjectionPointTypeAttribute(); } this.delegate = annotatedElement.isAnnotationPresent(Delegate.class); }
public Class<T> getJavaClass() { return delegate().getJavaClass(); }
@Deprecated public Annotation[] getBindingsAsArray() { return delegate().getBindingsAsArray(); }