openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1818721 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/BeansDeployer.java test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java
Date Tue, 19 Dec 2017 21:11:58 GMT
Author: struberg
Date: Tue Dec 19 21:11:58 2017
New Revision: 1818721

URL: http://svn.apache.org/viewvc?rev=1818721&view=rev
Log:
OWB-1215 further improve producermethod specialisation logic

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1818721&r1=1818720&r2=1818721&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Tue Dec 19 21:11:58 2017
@@ -976,18 +976,6 @@ public class BeansDeployer
         List<ProducerMethodBean> producerMethodBeans = beans.stream()
             .filter(ProducerMethodBean.class::isInstance)
             .map(ProducerMethodBean.class::cast)
-            .sorted((e1, e2) ->
-                {
-                    if (e1.getBeanClass().isAssignableFrom(e2.getBeanClass()))
-                    {
-                        return 1;
-                    }
-                    else if (e1.equals(e2))
-                    {
-                        return 0;
-                    }
-                    return -1;
-                })
             .collect(Collectors.toList());
 
         checkSpecializedProducerMethodConditions(producerMethodBeans);
@@ -1000,10 +988,16 @@ public class BeansDeployer
                 continue;
             }
 
-            for (int j = i+1; j < producerMethodBeans.size(); j++)
+            for (int j = 0; j < producerMethodBeans.size(); j++)
             {
                 ProducerMethodBean<?> otherProducerMethodBean = producerMethodBeans.get(j);
 
+                if (i==j)
+                {
+                    // makes no sense to compare with ourselves
+                    continue;
+                }
+
                 if (!otherProducerMethodBean.isEnabled())
                 {
                     // already disabled
@@ -1026,13 +1020,6 @@ public class BeansDeployer
                         otherProducerMethodBean.setEnabled(false);
                     }
                 }
-                else
-                {
-                    // since all the producermethods are sorted we can stop
-                    // once we leave the 'block' of superclasses for a bean
-                    break;
-                }
-
             }
         }
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java?rev=1818721&r1=1818720&r2=1818721&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/managed/specialized/SpecializeDeactivationTest.java
Tue Dec 19 21:11:58 2017
@@ -70,10 +70,10 @@ public class SpecializeDeactivationTest
     @Test
     public void specializeProducers()
     {
-        startContainer(Arrays.<Class<?>>asList(Init.class, API.class, Prod1.class,
Prod2.class, Spe1.class),
-            Collections.<String>emptyList(), true);
+        startContainer(Arrays.asList(Init.class, API.class, Prod1.class, Prod2.class, Spe1.class,
Prod3.class, Prod4.class),
+            Collections.emptyList(), true);
 
-        assertEquals(2, init.init());
+        assertEquals(4, init.init());
         assertTrue(SpeImpl1.called);
         assertTrue(Impl2.called);
     }
@@ -83,6 +83,11 @@ public class SpecializeDeactivationTest
         void init();
     }
 
+    public interface API2
+    {
+        void init();
+    }
+
     public static class Prod1
     {
         @Produces
@@ -90,6 +95,32 @@ public class SpecializeDeactivationTest
         {
             return new Impl1();
         }
+
+        @Produces
+        public API2 api2()
+        {
+            return new Impl1();
+        }
+    }
+
+    public static class Prod3
+    {
+        @Produces
+        public API api1()
+        {
+            return new Impl1();
+        }
+
+    }
+
+    public static class Prod4
+    {
+        @Produces
+        public API api1()
+        {
+            return new Impl1();
+        }
+
     }
 
     public static class Spe1 extends Prod1
@@ -101,6 +132,14 @@ public class SpecializeDeactivationTest
         {
             return new SpeImpl1();
         }
+
+        @Produces
+        @Override
+        @Specializes
+        public API2 api2()
+        {
+            return new SpeImpl1();
+        }
     }
 
     public static class Prod2
@@ -110,9 +149,15 @@ public class SpecializeDeactivationTest
         {
             return new Impl2();
         }
+
+        @Produces
+        public API2 api2()
+        {
+            return new Impl2();
+        }
     }
 
-    public static class Impl1 implements API
+    public static class Impl1 implements API, API2
     {
         public static boolean called = false;
 
@@ -135,7 +180,7 @@ public class SpecializeDeactivationTest
         }
     }
 
-    public static class Impl2 implements API
+    public static class Impl2 implements API, API2
     {
         public static boolean called = false;
 



Mime
View raw message