openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1622509 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
Date Thu, 04 Sep 2014 16:26:36 GMT
Author: rmannibucau
Date: Thu Sep  4 16:26:36 2014
New Revision: 1622509

URL: http://svn.apache.org/r1622509
Log:
Fixes OWB-997 supporting generics in ProcessAnnotatedType observers using WithAnnotations

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java?rev=1622509&r1=1622508&r2=1622509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
Thu Sep  4 16:26:36 2014
@@ -27,6 +27,8 @@ import javax.enterprise.inject.spi.Defin
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.enterprise.inject.spi.WithAnnotations;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 public class ContainerEventObserverMethodImpl<T> extends ObserverMethodImpl<T>
 {
@@ -39,7 +41,12 @@ public class ContainerEventObserverMetho
         WithAnnotations withAnnotationsAnn = annotatedObservesParameter.getAnnotation(WithAnnotations.class);
         if (withAnnotationsAnn != null)
         {
-            if (annotatedObservesParameter.getBaseType().equals(ProcessAnnotatedType.class))
+            Type baseType = annotatedObservesParameter.getBaseType();
+            if (ParameterizedType.class.isInstance(baseType))
+            {
+                baseType = ParameterizedType.class.cast(baseType).getRawType();
+            }
+            if (baseType.equals(ProcessAnnotatedType.class))
             {
                 withAnnotations = withAnnotationsAnn.value();
             }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java?rev=1622509&r1=1622508&r2=1622509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
Thu Sep  4 16:26:36 2014
@@ -43,17 +43,20 @@ public class WithAnnotationTest extends 
     public void testWithAnnotation()
     {
         WithAnnotationExtension.scannedClasses = 0;
+        WithAnnotationExtension.one = 0;
 
         addExtension(new WithAnnotationExtension());
         startContainer(WithoutAnyAnnotation.class, WithAnnotatedClass.class, WithAnnotatedField.class,
WithAnnotatedMethod.class);
 
         Assert.assertEquals(3, WithAnnotationExtension.scannedClasses);
+        Assert.assertEquals(1, WithAnnotationExtension.one);
     }
 
 
     public static class WithAnnotationExtension implements Extension
     {
         public static int scannedClasses = 0;
+        public static int one = 0;
 
         public void processClassess(@Observes @WithAnnotations(MyAnnoation.class) ProcessAnnotatedType
pat)
         {
@@ -64,6 +67,11 @@ public class WithAnnotationTest extends 
         {
             throw new IllegalStateException("This observer must not get called by the container!");
         }
+
+        public void noIssueWithGenericsOWB997(@Observes @WithAnnotations(MyAnnoation.class)
ProcessAnnotatedType<WithAnnotatedClass> pat)
+        {
+            one++;
+        }
     }
 
     @Retention(RetentionPolicy.RUNTIME)



Mime
View raw message