/** * Compares two annotated elements to see if they have the same annotations * */ private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1, List<? extends AnnotatedParameter<?>> p2) { if (p1.size() != p2.size()) { return false; } for (int i = 0; i < p1.size(); ++i) { if (!compareAnnotated(p1.get(i), p2.get(i))) { return false; } } return true; }
/** * Creates a deterministic signature for a {@link Constructor}. * * @param constructor The constructor to generate the signature for * @param annotations The annotations to include in the signature * @param parameters The {@link AnnotatedParameter}s to include in the * signature */ public static <X> String createConstructorId(Constructor<X> constructor, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append(constructor.getDeclaringClass().getName()); builder.append('.'); builder.append(constructor.getName()); builder.append(createAnnotationCollectionId(annotations)); builder.append(createParameterListId(parameters)); return builder.toString(); }
GenericProducerField(Bean<T> originalBean, GenericIdentifier identifier, AnnotatedField<X> field, Set<Annotation> qualifiers, Set<Annotation> declaringBeanQualifiers, Class<? extends Annotation> scopeOverride, boolean alternative, Class<?> declaringBeanClass, BeanManager beanManager) { super(originalBean, identifier, qualifiers, declaringBeanQualifiers, scopeOverride, Annotateds.createFieldId(field), alternative, declaringBeanClass, beanManager); this.field = field; }
builder.append(createAnnotationCollectionId(annotations)); builder.append("{"); builder.append(createFieldId(field)); builder.append(SEPERATOR); for (AnnotatedMethod<? super X> method : sortedMethods) if (!method.getAnnotations().isEmpty() || hasMethodParameters(method)) builder.append(createCallableId(method)); builder.append(SEPERATOR); for (AnnotatedConstructor<? super X> constructor : sortedConstructors) if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor)) builder.append(createCallableId(constructor)); builder.append(SEPERATOR);
if (!compareAnnotated(t1, t2)) if (!compareAnnotatedField(f, fields.get(f.getJavaMember()))) if (!compareAnnotatedCallable(f, methods.get(f.getJavaMember()))) if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember())))
/** * <p> * Compare {@link AnnotatedCallable}s for equality. * </p> * * <p> * Two {@link AnnotatedCallable}s are considered equal if they have the same * underlying callable and annotations. * </p> */ public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2) { if (!m1.getJavaMember().equals(m2.getJavaMember())) { return false; } if (!compareAnnotated(m1, m2)) { return false; } return compareAnnotatedParameters(m1.getParameters(), m2.getParameters()); }
/** * Generates a deterministic signature for an {@link AnnotatedType}. Two * <code>AnnotatedType</code>s that have the same annotations and underlying * type will generate the same signature. * <p/> * This can be used to create a unique bean id for a passivation capable bean * that is added directly through the SPI. * * @param annotatedType The type to generate a signature for * @return A string representation of the annotated type */ public static <X> String createTypeId(AnnotatedType<X> annotatedType) { return createTypeId(annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors()); }
/** * Generates a unique string representation of a list of * {@link AnnotatedParameter}s. */ public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append("("); for (int i = 0; i < parameters.size(); ++i) { AnnotatedParameter<X> ap = parameters.get(i); builder.append(createParameterId(ap)); if (i + 1 != parameters.size()) { builder.append(','); } } builder.append(")"); return builder.toString(); }
/** * Creates a deterministic signature for a {@link Field}. * * @param field The field to generate the signature for * @param annotations The annotations to include in the signature */ public static <X> String createFieldId(Field field, Collection<Annotation> annotations) { StringBuilder builder = new StringBuilder(); builder.append(field.getDeclaringClass().getName()); builder.append('.'); builder.append(field.getName()); builder.append(createAnnotationCollectionId(annotations)); return builder.toString(); }
GenericProducerMethod(Bean<T> originalBean, GenericIdentifier identifier, AnnotatedMethod<X> method, AnnotatedMethod<X> disposerMethod, final Set<Annotation> qualifiers, final Set<Annotation> genericBeanQualifiers, Class<? extends Annotation> scopeOverride, boolean alternative, Class<?> declaringBeanClass, BeanManager beanManager) { super(originalBean, identifier, qualifiers, genericBeanQualifiers, scopeOverride, Annotateds.createCallableId(method), alternative, declaringBeanClass, beanManager); List<InjectionPoint> injectionPoints = createInjectionPoints(method, this, beanManager); List<InjectionPoint> wrappedInjectionPoints = new ArrayList<InjectionPoint>(); for (InjectionPoint injectionPoint : injectionPoints) { wrappedInjectionPoints.add(wrapInjectionPoint(injectionPoint, genericBeanQualifiers)); } this.producerMethod = new InjectableMethod<X>(method, wrappedInjectionPoints, beanManager); if (disposerMethod != null) { injectionPoints = createInjectionPoints(disposerMethod, this, beanManager); wrappedInjectionPoints = new ArrayList<InjectionPoint>(); for (InjectionPoint injectionPoint : injectionPoints) { wrappedInjectionPoints.add(wrapInjectionPoint(injectionPoint, genericBeanQualifiers)); } this.disposerMethod = new InjectableMethod<X>(disposerMethod, wrappedInjectionPoints, beanManager); } else { this.disposerMethod = null; } }
GenericManagedBean(Bean<T> originalBean, GenericIdentifier identifier, InjectionTarget<T> injectionTarget, AnnotatedType<T> type, Set<Annotation> qualifiers, Class<? extends Annotation> scopeOverride, Synthetic.Provider annotatedMemberSyntheticProvider, boolean alternative, Class<?> beanClass, BeanManager beanManager) { super(originalBean, qualifiers, identifier, Annotateds.createTypeId(type), alternative, beanClass, beanManager); this.injectionTarget = injectionTarget; this.injectedFields = new HashMap<AnnotatedField<? super T>, InjectionPoint>(); this.scopeOverride = scopeOverride; Set<Annotation> filteredQualifiers = new HashSet<Annotation>(getQualifiers()); filteredQualifiers.remove(AnyLiteral.INSTANCE); for (AnnotatedField<? super T> field : type.getFields()) { if (field.isAnnotationPresent(InjectGeneric.class)) { if (AnnotatedMember.class.isAssignableFrom(field.getJavaMember().getType())) { injectedFields.put(field, new ImmutableInjectionPoint(field, Collections.<Annotation> singleton(annotatedMemberSyntheticProvider.get(identifier)), this, false, false)); } else { injectedFields.put(field, new ImmutableInjectionPoint(field, filteredQualifiers, this, false, false)); } if (!field.getJavaMember().isAccessible()) { field.getJavaMember().setAccessible(true); } } } }
/** * Creates a string representation of an {@link AnnotatedParameter}. */ public static <X> String createParameterId(AnnotatedParameter<X> annotatedParameter) { return createParameterId(annotatedParameter.getBaseType(), annotatedParameter.getAnnotations()); }
/** * Creates a string representation of a given type and set of annotations. * */ public static <X> String createParameterId(Type type, Set<Annotation> annotations) { StringBuilder builder = new StringBuilder(); if (type instanceof Class<?>) { Class<?> c = (Class<?>) type; builder.append(c.getName()); } else { builder.append(type.toString()); } builder.append(createAnnotationCollectionId(annotations)); return builder.toString(); }
/** * Creates a deterministic signature for a {@link Method}. * * @param method The method to generate the signature for * @param annotations The annotations to include in the signature * @param parameters The {@link AnnotatedParameter}s to include in the * signature */ public static <X> String createMethodId(Method method, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append(method.getDeclaringClass().getName()); builder.append('.'); builder.append(method.getName()); builder.append(createAnnotationCollectionId(annotations)); builder.append(createParameterListId(parameters)); return builder.toString(); }
this.id = ImmutableBean.class.getName() + ":" + Annotateds.createTypeId(type); return this;
/** * Generates a deterministic signature for an {@link AnnotatedField}. Two * <code>AnnotatedField</code>s that have the same annotations and * underlying field will generate the same signature. */ public static <X> String createFieldId(AnnotatedField<X> field) { return createFieldId(field.getJavaMember(), field.getAnnotations()); }
/** * <p> * Compares {@link AnnotatedField}s for equality. * </p> * <p> * Two {@link AnnotatedField}s are considered equal if they have the same * underlying field and annotations. * </p> */ public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2) { if (!f1.getJavaMember().equals(f2.getJavaMember())) { return false; } return compareAnnotated(f1, f2); }
/** * Generates a deterministic signature for an {@link AnnotatedCallable}. Two * <code>AnnotatedCallable</code>s that have the same annotations and * underlying callable will generate the same signature. */ public static <X> String createCallableId(AnnotatedCallable<X> method) { StringBuilder builder = new StringBuilder(); builder.append(method.getJavaMember().getDeclaringClass().getName()); builder.append('.'); builder.append(method.getJavaMember().getName()); builder.append(createAnnotationCollectionId(method.getAnnotations())); builder.append(createParameterListId(method.getParameters())); return builder.toString(); }