openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1432408 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation: AbstractBeanBuilder.java InterceptorBeanBuilder.java
Date Sat, 12 Jan 2013 11:24:11 GMT
Author: struberg
Date: Sat Jan 12 11:24:11 2013
New Revision: 1432408

URL: http://svn.apache.org/viewvc?rev=1432408&view=rev
Log:
OWB-344 improve removeOverriddenMethod

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1432408&r1=1432407&r2=1432408&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Sat Jan 12 11:24:11 2013
@@ -143,6 +143,68 @@ public abstract class AbstractBeanBuilde
         return hierarchy;
     }
 
+    /**
+     * Check if the given annotatedMethod overrides some previously defined AnnotatedMethods
+     * from a superclass and remove them if non-private.
+     *
+     *
+     * @param alreadyDefinedMethods the methods already calculated from the superclasses.
See {@link #getReverseClassHierarchy()}
+     * @param annotatedMethod the AnnotatedMethod to check for.
+     * @return <code>true</code> if a method was overridden and got removed,
<code>false</code> otherwise.
+     */
+    protected boolean removeOverriddenMethod(List<AnnotatedMethod> alreadyDefinedMethods,
AnnotatedMethod annotatedMethod)
+    {
+        String methodName = null;
+        Class<?>[] methodParameterTypes = null;
+
+        Iterator<AnnotatedMethod> it = alreadyDefinedMethods.iterator();
+        while (it.hasNext())
+        {
+            AnnotatedMethod alreadyDefined = it.next();
+
+            if (methodName == null)
+            {
+                methodName = annotatedMethod.getJavaMember().getName();
+                methodParameterTypes = annotatedMethod.getJavaMember().getParameterTypes();
+            }
+
+            // check method overrides
+            if (!Modifier.isPrivate(alreadyDefined.getJavaMember().getModifiers()))
+            {
+                // we only scan non-private methods, as private methods cannot get overridden.
+                if (methodName.equals(alreadyDefined.getJavaMember().getName()) &&
+                        methodParameterTypes.length == alreadyDefined.getJavaMember().getParameterTypes().length)
+                {
+                    boolean overridden = true;
+                    // same name and param length so we need to check if all the paramTypes
are equal.
+                    if (methodParameterTypes.length > 0)
+                    {
+                        Class<?>[] otherParamTypes = alreadyDefined.getJavaMember().getParameterTypes();
+
+                        for (int i = 0; i < otherParamTypes.length; i++)
+                        {
+                            if (!otherParamTypes[i].equals(methodParameterTypes[i]))
+                            {
+                                overridden = false;
+                                break;
+                            }
+                        }
+                    }
+
+                    if (overridden)
+                    {
+                        // then we need to remove this method
+                        it.remove();
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+
 
     /**
      * {@inheritDoc}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1432408&r1=1432407&r2=1432408&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
Sat Jan 12 11:24:11 2013
@@ -28,10 +28,8 @@ import javax.enterprise.inject.spi.Inter
 import javax.interceptor.AroundInvoke;
 
 import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -132,16 +130,18 @@ public abstract class InterceptorBeanBui
                     // PostConstruct
                     if (m.getAnnotation(PostConstruct.class) != null)
                     {
+                        checkSameClassInterceptors(postConstructMethods, m);
                         postConstructMethods.add(m); // add at last position
                     }
-                    checkMethodOverrides(postConstructMethods, clazz, m);
+                    removeOverriddenMethod(postConstructMethods, m);
 
                     // PreDestroy
                     if (m.getAnnotation(PreDestroy.class) != null)
                     {
+                        checkSameClassInterceptors(preDestroyMethods, m);
                         preDestroyMethods.add(m); // add at last position
                     }
-                    checkMethodOverrides(preDestroyMethods, clazz, m);
+                    removeOverriddenMethod(preDestroyMethods, m);
 
                 }
             }
@@ -162,69 +162,28 @@ public abstract class InterceptorBeanBui
     }
 
     /**
-     * Check if the given annotatedMethod overrides some previously defined interceptorMethods
-     * and remove them if non-private.
-     * This will also detect if there are multiple methods for the same InterceptionType
-     * in the same class
+     *
+     * @return
      */
-    private void checkMethodOverrides(List<AnnotatedMethod> alreadyDefinedMethods,
Class clazz, AnnotatedMethod annotatedMethod)
+    private void checkSameClassInterceptors(List<AnnotatedMethod> alreadyDefinedMethods,
AnnotatedMethod annotatedMethod)
     {
-        String methodName = null;
-        Class<?>[] methodParameterTypes = null;
-
-        Iterator<AnnotatedMethod> it = alreadyDefinedMethods.iterator();
-        while (it.hasNext())
+        Class clazz = null;
+        for (AnnotatedMethod alreadyDefined : alreadyDefinedMethods)
         {
-            AnnotatedMethod alreadyDefined = it.next();
-
-            if (methodName == null)
+            if (clazz == null)
             {
-                methodName = annotatedMethod.getJavaMember().getName();
-                methodParameterTypes = annotatedMethod.getJavaMember().getParameterTypes();
+                clazz = annotatedMethod.getDeclaringType().getJavaClass();
             }
 
             // check for same class -> Exception
             if (alreadyDefined.getDeclaringType().getJavaClass() ==  clazz)
             {
                 throw new WebBeansConfigurationException("Only one Interceptor of a certain
type is allowed per class, but multiple found in class "
-                                                         + annotatedMethod.getDeclaringType().getJavaClass().getName()
-                                                         + " methods: " + annotatedMethod.getJavaMember().toString()
-                                                         + " and " + alreadyDefined.getJavaMember().toString());
-            }
-
-            // check method overrides
-            if (!Modifier.isPrivate(alreadyDefined.getJavaMember().getModifiers()))
-            {
-                // we only scan non-private methods, as private methods cannot get overridden.
-                if (methodName.equals(alreadyDefined.getJavaMember().getName()) &&
-                    methodParameterTypes.length == alreadyDefined.getJavaMember().getParameterTypes().length)
-                {
-                    boolean overridden = true;
-                    // same name and param length so we need to check if all the paramTypes
are equal.
-                    if (methodParameterTypes.length > 0)
-                    {
-                        Class<?>[] otherParamTypes = alreadyDefined.getJavaMember().getParameterTypes();
-
-                        for (int i = 0; i < otherParamTypes.length; i++)
-                        {
-                            if (!otherParamTypes[i].equals(methodParameterTypes[i]))
-                            {
-                                overridden = false;
-                                break;
-                            }
-                        }
-                    }
-
-                    if (overridden)
-                    {
-                        // then we need to remove this method
-                        it.remove();
-                        continue;
-                    }
-                }
+                        + annotatedMethod.getDeclaringType().getJavaClass().getName()
+                        + " methods: " + annotatedMethod.getJavaMember().toString()
+                        + " and " + alreadyDefined.getJavaMember().toString());
             }
         }
-
     }
 
 



Mime
View raw message