Author: struberg
Date: Mon Jun 5 17:49:31 2017
New Revision: 1797679
URL: http://svn.apache.org/viewvc?rev=1797679&view=rev
Log:
OWB-1187 copy ct for Annotated.State
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedFieldConfiguratorImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedMethodConfiguratorImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedTypeConfiguratorImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedFieldConfiguratorImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedFieldConfiguratorImpl.java?rev=1797679&r1=1797678&r2=1797679&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedFieldConfiguratorImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedFieldConfiguratorImpl.java
Mon Jun 5 17:49:31 2017
@@ -23,29 +23,41 @@ import javax.enterprise.inject.spi.confi
import java.lang.annotation.Annotation;
import java.util.function.Predicate;
+import org.apache.webbeans.portable.AnnotatedFieldImpl;
+
public class AnnotatedFieldConfiguratorImpl<T> implements
AnnotatedFieldConfigurator<T>
{
+ private final AnnotatedFieldImpl<T> annotatedField;
+
+ public AnnotatedFieldConfiguratorImpl(AnnotatedFieldImpl<T> annotatedField)
+ {
+ this.annotatedField = annotatedField;
+ }
+
@Override
public AnnotatedField<T> getAnnotated()
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ return annotatedField;
}
@Override
public AnnotatedFieldConfigurator<T> add(Annotation annotation)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ annotatedField.addAnnotation(annotation);
+ return this;
}
@Override
public AnnotatedFieldConfigurator<T> remove(Predicate annotation)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ annotatedField.getAnnotations().removeIf(annotation);
+ return this;
}
@Override
public AnnotatedFieldConfigurator<T> removeAll()
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ annotatedField.getAnnotations().clear();
+ return this;
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedMethodConfiguratorImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedMethodConfiguratorImpl.java?rev=1797679&r1=1797678&r2=1797679&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedMethodConfiguratorImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedMethodConfiguratorImpl.java
Mon Jun 5 17:49:31 2017
@@ -54,13 +54,15 @@ public class AnnotatedMethodConfigurator
@Override
public AnnotatedMethodConfigurator<T> remove(Predicate annotation)
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ annotatedMethod.getAnnotations().removeIf(annotation);
+ return this;
}
@Override
public AnnotatedMethodConfigurator<T> removeAll()
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ annotatedMethod.getAnnotations().clear();
+ return this;
}
@Override
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedTypeConfiguratorImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedTypeConfiguratorImpl.java?rev=1797679&r1=1797678&r2=1797679&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedTypeConfiguratorImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/AnnotatedTypeConfiguratorImpl.java
Mon Jun 5 17:49:31 2017
@@ -19,6 +19,7 @@
package org.apache.webbeans.configurator;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.AnnotatedFieldImpl;
import org.apache.webbeans.portable.AnnotatedMethodImpl;
import org.apache.webbeans.portable.AnnotatedTypeImpl;
@@ -37,6 +38,7 @@ public class AnnotatedTypeConfiguratorIm
private final AnnotatedTypeImpl<T> annotatedType;
private Set<AnnotatedMethodConfigurator<? super T>>
annotatedMethodConfigurators;
+ private Set<AnnotatedFieldConfigurator<? super T>>
annotatedFieldConfigurators;
public AnnotatedTypeConfiguratorImpl(WebBeansContext webBeansContext,
AnnotatedType<T> originalAnnotatedType)
@@ -46,6 +48,10 @@ public class AnnotatedTypeConfiguratorIm
annotatedMethodConfigurators = annotatedType.getMethods().stream()
.map(m -> new
AnnotatedMethodConfiguratorImpl<>((AnnotatedMethodImpl<T>) m))
.collect(Collectors.toSet());
+
+ annotatedFieldConfigurators = annotatedType.getFields().stream()
+ .map(m -> new
AnnotatedFieldConfiguratorImpl<>((AnnotatedFieldImpl<T>) m))
+ .collect(Collectors.toSet());
}
@@ -85,7 +91,7 @@ public class AnnotatedTypeConfiguratorIm
@Override
public Set<AnnotatedFieldConfigurator<? super T>> fields()
{
- throw new UnsupportedOperationException("TODO implement CDI 2.0");
+ return annotatedFieldConfigurators;
}
@Override
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java?rev=1797679&r1=1797678&r2=1797679&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
Mon Jun 5 17:49:31 2017
@@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
@@ -108,19 +109,23 @@ public class AnnotatedTypeImpl<X>
* Copy constructor
*
* @param webBeansContext actual {@link WebBeansContext}
- * @param annotatedType to copy
+ * @param otherAnnotatedType to copy
*/
- public AnnotatedTypeImpl(WebBeansContext webBeansContext, AnnotatedType
annotatedType)
+ public AnnotatedTypeImpl(WebBeansContext webBeansContext, AnnotatedType
otherAnnotatedType)
{
- super(webBeansContext, annotatedType);
- this.annotatedClass = annotatedType.getJavaClass();
+ super(webBeansContext, otherAnnotatedType);
+ this.annotatedClass = otherAnnotatedType.getJavaClass();
//X TODO revisit!!
- if (annotatedType instanceof AnnotatedTypeImpl)
+ if (otherAnnotatedType instanceof AnnotatedTypeImpl)
{
- AnnotatedTypeImpl annotatedTypeImpl = (AnnotatedTypeImpl)
annotatedType;
+ AnnotatedTypeImpl annotatedTypeImpl = (AnnotatedTypeImpl)
otherAnnotatedType;
this.supertype = annotatedTypeImpl.supertype;
- this.state = annotatedTypeImpl.state;
+
+ if (annotatedTypeImpl.state != null)
+ {
+ this.state = new State(annotatedTypeImpl.state);
+ }
}
else
{
@@ -286,5 +291,23 @@ public class AnnotatedTypeImpl<X>
}
}
+
+ /**
+ * Copy ct
+ */
+ private State(State otherState)
+ {
+ constructors = otherState.constructors.stream()
+ .map(af -> new
AnnotatedConstructorImpl<>(getWebBeansContext(), af.getJavaMember(),
AnnotatedTypeImpl.this))
+ .collect(Collectors.toSet());
+
+ fields = otherState.fields.stream()
+ .map(af -> new AnnotatedFieldImpl<>(getWebBeansContext(),
af.getJavaMember(), AnnotatedTypeImpl.this))
+ .collect(Collectors.toSet());
+
+ methods = otherState.methods.stream()
+ .map(af -> new AnnotatedMethodImpl<>(getWebBeansContext(),
af.getJavaMember(), AnnotatedTypeImpl.this))
+ .collect(Collectors.toSet());
+ }
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java?rev=1797679&r1=1797678&r2=1797679&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/AnnotatedTypeConfiguratorImplTest.java
Mon Jun 5 17:49:31 2017
@@ -161,6 +161,34 @@ public class AnnotatedTypeConfiguratorIm
}, AnnotatedTypeConfigClass.class);
}
+ @Test
+ public void testAddAnnotationToField()
+ {
+ checkAnnotatedType(
+ pat ->
+ {
+ pat.configureAnnotatedType()
+ .filterFields(m ->
m.getJavaMember().getName().equals("field1"))
+ .findFirst()
+ .get()
+ .add(new TheQualifierLiteral("Field1"));
+ },
+ pba ->
+ {
+ Assert.assertTrue(pba.getAnnotated() instanceof AnnotatedType);
+ AnnotatedType<?> at = (AnnotatedType<?>) pba.getAnnotated();
+ Set<Annotation> annotations = at.getFields().stream()
+ .filter(m -> m.getJavaMember().getName().equals("field1"))
+ .findFirst()
+ .get().getAnnotations();
+ assertEquals(1, annotations.size());
+ Annotation ann = annotations.iterator().next();
+ assertEquals(TheQualifier.class, ann.annotationType());
+ assertEquals("Field1", ((TheQualifier) ann).value());
+
+ }, AnnotatedTypeConfigClass.class);
+ }
+
private void
checkAnnotatedType(Consumer<ProcessAnnotatedType<AnnotatedTypeConfigClass>>
typeConfigurator,
Consumer<ProcessBeanAttributes>
beanAttributesConsumer,