Author: rmannibucau
Date: Tue Jun 6 08:05:07 2017
New Revision: 1797746
URL: http://svn.apache.org/viewvc?rev=1797746&view=rev
Log:
some work around @Repeatable
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
openwebbeans/trunk/webbeans-tck/testng-dev.xml
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1797746&r1=1797745&r2=1797746&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Tue Jun 6 08:05:07 2017
@@ -933,4 +933,27 @@ public final class AnnotationManager
}
}
+ public Method getRepeatableMethod(final Class<?> type)
+ {
+ final Method value;
+ try
+ {
+ value = type.getMethod("value");
+ }
+ catch (final NoSuchMethodException e)
+ {
+ return null;
+ }
+ if (!value.getReturnType().isArray())
+ {
+ return null;
+ }
+ final Class<?> componentType =
value.getReturnType().getComponentType();
+ final Repeatable repeatable =
componentType.getAnnotation(Repeatable.class);
+ if (repeatable == null || repeatable.value() != type)
+ {
+ return null;
+ }
+ return value;
+ }
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java?rev=1797746&r1=1797745&r2=1797746&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
Tue Jun 6 08:05:07 2017
@@ -55,6 +55,7 @@ import org.apache.webbeans.container.Ext
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.portable.AbstractAnnotated;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
@@ -232,7 +233,7 @@ public abstract class BeanAttributesBuil
}
}
- if (qualifiedTypes.contains(annotation.annotationType()))
+ if (qualifiedTypes.contains(annotation.annotationType()) &&
!isRepetable(annotated, annotation))
{
continue;
}
@@ -287,6 +288,14 @@ public abstract class BeanAttributesBuil
}
+ // we don't want to do the getRepeatableMethod() logic *again* if we can
but we can need for custom AT
+ private boolean isRepetable(final Annotated annotated, final Annotation
annotation)
+ {
+ return AbstractAnnotated.class.isInstance(annotated) ?
+
AbstractAnnotated.class.cast(annotated).getRepeatables().contains(annotation.annotationType())
:
+
webBeansContext.getAnnotationManager().getRepeatableMethod(annotation.annotationType())
!= null;
+ }
+
/**
* Returns true if any binding exist
*
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java?rev=1797746&r1=1797745&r2=1797746&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
Tue Jun 6 08:05:07 2017
@@ -19,11 +19,15 @@
package org.apache.webbeans.portable;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
import java.util.Set;
+import java.util.stream.Stream;
import javax.enterprise.inject.spi.Annotated;
@@ -31,12 +35,15 @@ import org.apache.webbeans.config.WebBea
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.GenericsUtil;
+import static java.util.Collections.singleton;
+import static java.util.stream.Collectors.toList;
+
/**
* Abstract implementation of the {@link Annotated} contract.
*
* @version $Rev$ $Date$
*/
-abstract class AbstractAnnotated implements Annotated
+public abstract class AbstractAnnotated implements Annotated
{
/**Base type of an annotated element*/
private final Type baseType;
@@ -45,7 +52,8 @@ abstract class AbstractAnnotated impleme
private Set<Type> typeClosures = null;
/**Set of annotations*/
- private Set<Annotation> annotations = new HashSet<Annotation>();
+ private Set<Annotation> annotations = new HashSet<>();
+ private Set<Class<?>> repeatables = new HashSet<>();
private final WebBeansContext webBeansContext;
@@ -79,7 +87,42 @@ abstract class AbstractAnnotated impleme
this.annotations.addAll(annotated.getAnnotations());
}
+ protected void buildRepeatableAnnotations(final Set<Annotation>
annotations)
+ {
+ if (annotations.isEmpty())
+ {
+ return;
+ }
+ final List<Annotation> repeatables = annotations.stream()
+ .map(a -> {
+ final Class<?> type = a.annotationType();
+ try
+ {
+ final Method repeatableMethod =
webBeansContext.getAnnotationManager().getRepeatableMethod(type);
+ if (repeatableMethod == null)
+ {
+ return null;
+ }
+ return (Annotation[]) repeatableMethod.invoke(a);
+ }
+ catch (final Exception e)
+ {
+ return null;
+ }
+ }).filter(Objects::nonNull)
+ .flatMap(Stream::of)
+ .collect(toList());
+ if (!repeatables.isEmpty())
+ {
+
this.repeatables.addAll(repeatables.stream().map(Annotation::annotationType).collect(toList()));
+ this.annotations.addAll(repeatables);
+ }
+ }
+ public Set<Class<?>> getRepeatables()
+ {
+ return repeatables;
+ }
/**
* Adds new annotation to set.
@@ -89,6 +132,7 @@ abstract class AbstractAnnotated impleme
public void addAnnotation(Annotation annotation)
{
annotations.add(annotation);
+ buildRepeatableAnnotations(singleton(annotation));
}
protected WebBeansContext getWebBeansContext()
@@ -105,6 +149,7 @@ abstract class AbstractAnnotated impleme
{
clearAnnotations();
Collections.addAll(this.annotations, annotations);
+ buildRepeatableAnnotations(this.annotations);
}
public void clearAnnotations()
Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1797746&r1=1797745&r2=1797746&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Tue Jun 6 08:05:07 2017
@@ -18,9 +18,7 @@
<suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
<test name="JSR-346 TCK">
<classes>
- <class
name="org.jboss.cdi.tck.tests.extensions.lifecycle.processBeanAttributes.specialization.VetoTest"
/>
- <class
name="org.jboss.cdi.tck.tests.implementation.simple.lifecycle.unproxyable.UnproxyableManagedBeanTest"
/>
- <class
name="org.jboss.cdi.tck.tests.context.passivating.broken.producer.field.managed.NonPassivationCapableProducerFieldTest"
/>
+ <class
name="org.jboss.cdi.tck.tests.definition.qualifier.repeatable.RepeatableQualifiersTest"
/>
<!--
<class
name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest" />
<class name="org.jboss.cdi.tck.tests.event.fires.FireEventTest" />