openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1305134 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/annotation/ main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/portable/ main/java/org/apache/webbe...
Date Sun, 25 Mar 2012 21:06:25 GMT
Author: struberg
Date: Sun Mar 25 21:06:25 2012
New Revision: 1305134

URL: http://svn.apache.org/viewvc?rev=1305134&view=rev
Log:
OWB-657 remove unused code parts and improve empty array inits

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/StartupPerformanceTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java

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=1305134&r1=1305133&r2=1305134&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
Sun Mar 25 21:06:25 2012
@@ -262,7 +262,7 @@ public final class AnnotationManager
                 return result;
             }
         }
-        result = new Annotation[0];
+        result = AnnotationUtil.EMPTY_ANNOTATION_ARRAY;
         return result;
     }
 
@@ -304,50 +304,6 @@ public final class AnnotationManager
         return a;
     }
 
-
-    /**
-     * If the bean extends generic class via Realizes
-     * annotation, realized based producer methods, fields and observer
-     * methods qualifier is
-     *
-     * <ul>
-     *  <li>Qualifiers on the definitions</li>
-     *  <li>Plus class qualifiers</li>
-     *  <li>Minus generic class qualifiers</li>
-     * </ul>
-     *
-     * @param clazz realized definition class
-     * @param anns binding annotations array
-     */
-    public Annotation[] getRealizesGenericAnnotations(Class<?> clazz, Annotation[]
anns)
-    {
-       Set<Annotation> setAnnots = new HashSet<Annotation>();
-
-        for(Annotation definedAnn : anns)
-        {
-            setAnnots.add(definedAnn);
-        }
-
-        Annotation[] genericReliazesAnns = getQualifierAnnotations(clazz.getSuperclass().getDeclaredAnnotations());
-
-        for(Annotation generic : genericReliazesAnns)
-        {
-            setAnnots.remove(generic);
-        }
-
-        genericReliazesAnns = getQualifierAnnotations(clazz.getDeclaredAnnotations());
-
-        for(Annotation generic : genericReliazesAnns)
-        {
-            setAnnots.add(generic);
-        }
-
-        Annotation[] annots = new Annotation[setAnnots.size()];
-        annots = setAnnots.toArray(annots);
-
-        return annots;
-    }
-
     public void checkQualifierConditions(Annotation... qualifierAnnots)
     {
         Set<Annotation> annSet = ArrayUtil.asSet(qualifierAnnots);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=1305134&r1=1305133&r2=1305134&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
Sun Mar 25 21:06:25 2012
@@ -106,9 +106,9 @@ public final class DefinitionUtil
         Annotation[] annots = clazz.getDeclaredAnnotations();
         
         //Looking for bean types
-        if(AnnotationUtil.hasAnnotation(annots, Typed.class))
+        Typed beanTypes = clazz.getAnnotation(Typed.class);
+        if(beanTypes != null)
         {
-            Typed beanTypes = AnnotationUtil.getAnnotation(annots, Typed.class);
             defineUserDefinedBeanTypes(bean, null, beanTypes);            
         }
         else
@@ -196,12 +196,11 @@ public final class DefinitionUtil
     {
         
         //Looking for bean types
-        if(AnnotationUtil.hasAnnotation(annots, Typed.class))
+        Typed beanTypes = AnnotationUtil.getAnnotation(annots, Typed.class);
+        if(beanTypes != null)
         {
-            Typed beanTypes = AnnotationUtil.getAnnotation(annots, Typed.class);
             defineUserDefinedBeanTypes(producerBean, type, beanTypes);
         }
-        
         else
         {
             defineNormalProducerMethodApi(producerBean, type);
@@ -219,7 +218,6 @@ public final class DefinitionUtil
         if (clazz != null && (clazz.isPrimitive() || clazz.isArray()))
         {
             types.add(clazz);
-
         }
         else
         {
@@ -711,7 +709,8 @@ public final class DefinitionUtil
             {
                 if (Modifier.isStatic(declaredMethod.getModifiers()))
                 {
-                    throw new WebBeansConfigurationException("Specializing producer method
: " + declaredMethod.getName() + " in class : " + clazz.getName()
+                    throw new WebBeansConfigurationException("Specializing producer method
: " + declaredMethod.getName()
+                                                             + " in class : " + clazz.getName()
                                                              + " can not be static");
                 }
 
@@ -1286,9 +1285,14 @@ public final class DefinitionUtil
     }
     
     private <X> void createProducerBeansFromAnnotatedType(InjectionTargetBean<X>
bean, Set<ProducerMethodBean<?>> producerComponents,
-                                                                 AnnotatedMethod<X>
annotatedMethod, Class<?> clazz, boolean isSpecializes)
+                                                          AnnotatedMethod<X> annotatedMethod,
Class<?> clazz, boolean isSpecializes)
     {
         Set<Annotation> annSet = annotatedMethod.getAnnotations();
+        if (annSet == null || annSet.isEmpty())
+        {
+            return;
+        }
+
         Annotation[] anns = annSet.toArray(new Annotation[annSet.size()]);
         
         List<AnnotatedParameter<X>> parameters = annotatedMethod.getParameters();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1305134&r1=1305133&r2=1305134&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Sun Mar 25 21:06:25 2012
@@ -1070,7 +1070,7 @@ public class BeanManagerImpl implements 
             }
         }
         
-        return AnnotationUtil.hasAnnotation(annotationType.getDeclaredAnnotations(), NormalScope.class);
+        return annotationType.getAnnotation(NormalScope.class) != null;
     }
     
     public boolean isPassivatingScope(Class<? extends Annotation> annotationType)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java?rev=1305134&r1=1305133&r2=1305134&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
Sun Mar 25 21:06:25 2012
@@ -115,12 +115,8 @@ public final class AnnotatedElementFacto
     public <X> AnnotatedType<X> newAnnotatedType(Class<X> annotatedClass)
     {
         Asserts.assertNotNull(annotatedClass, "annotatedClass is null");
-        AnnotatedType<X> annotatedType;
-        if(annotatedTypeCache.containsKey(annotatedClass))
-        {
-            annotatedType = (AnnotatedType<X>)annotatedTypeCache.get(annotatedClass);
-        }
-        else
+        AnnotatedType<X> annotatedType = (AnnotatedType<X>)annotatedTypeCache.get(annotatedClass);
+        if(annotatedType == null)
         {
             try
             {
@@ -131,8 +127,7 @@ public final class AnnotatedElementFacto
                 {
                     annotatedType = oldType;
                 }
-
-            } 
+            }
             catch (Exception e)
             {
                 if (e instanceof ClassNotFoundException || e instanceof ArrayStoreException)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1305134&r1=1305133&r2=1305134&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
Sun Mar 25 21:06:25 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.util;
 
-import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansException;
 
 import javax.enterprise.inject.Any;
@@ -29,9 +28,7 @@ import javax.enterprise.util.Nonbinding;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -195,40 +192,6 @@ public final class AnnotationUtil
         return result;
     }
 
-    public static Type[] getConstructorParameterGenericTypesWithGivenAnnotation(Constructor<?>
constructor, Class<? extends Annotation> clazz)
-    {
-        Asserts.assertNotNull(constructor, "constructor argument can not be null");
-        Asserts.nullCheckForClass(clazz);
-
-        List<Type> list = new ArrayList<Type>();
-        Type[] result;
-
-        Annotation[][] parameterAnns = constructor.getParameterAnnotations();
-        Type[] genericTypes = constructor.getGenericParameterTypes();
-
-        int i = 0;
-        for (Annotation[] parameters : parameterAnns)
-        {
-            for (Annotation param : parameters)
-            {
-                Class<? extends Annotation> btype = param.annotationType();
-                if (btype.equals(clazz))
-                {
-                    list.add(genericTypes[i]);
-                    break;
-                }
-            }
-
-            i++;
-
-        }
-
-        result = new Type[list.size()];
-        result = list.toArray(result);
-
-        return result;
-    }
-
     /**
      * Check given annotation exist in the multiple parameter of the given
      * method. Return true if exist false otherwise.
@@ -347,39 +310,6 @@ public final class AnnotationUtil
         return null;
     }
 
-    @Deprecated
-    public static <X> Annotation[] getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(AnnotatedMethod<X>
annotatedMethod, Class<? extends Annotation> clazz)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(annotatedMethod,
clazz);
-    }
-    
-    public static Class<?> getMethodFirstParameterTypeClazzWithAnnotation(Method method,
Class<? extends Annotation> clazz)
-    {
-        Type type = getMethodFirstParameterWithAnnotation(method, clazz);
-
-        if (type instanceof ParameterizedType)
-        {
-            return (Class<?>) ((ParameterizedType) type).getRawType();
-        }
-        else
-        {
-            return (Class<?>) type;
-        }
-    }
-
-    /**
-     * Gets the method first found parameter qualifiers.
-     *
-     * @param method method
-     * @param clazz checking annotation
-     * @return annotation array
-     */
-    @Deprecated
-    public static Annotation[] getMethodFirstParameterQualifierWithGivenAnnotation(Method
method, Class<? extends Annotation> clazz)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getMethodFirstParameterQualifierWithGivenAnnotation(method,
clazz);
-    }
-
     /**
      * Get the Type of the method parameter which has the given annotation
      * @param method which need to be scanned
@@ -469,41 +399,6 @@ public final class AnnotationUtil
         
         return null;
     }    
-    
-
-    /**
-     * Check given annotation cross ref exist in the any parameter of the given
-     * method. Return true if exist false otherwise.
-     * 
-     * @param method method
-     * @param clazz checking annotation
-     * @return true or false
-     */
-    public static boolean hasMethodParameterAnnotationCrossRef(Method method, Class<?
extends Annotation> clazz)
-    {
-        Asserts.assertNotNull(method, "Method argument can not be null");
-        Asserts.nullCheckForClass(clazz);
-
-        Annotation[][] parameterAnns = method.getParameterAnnotations();
-
-        for (Annotation[] parameters : parameterAnns)
-        {
-            for (Annotation param : parameters)
-            {
-                Annotation[] btype = getDeclaredAnnotations(param.annotationType());
-
-                for (Annotation b : btype)
-                {
-                    if (b.annotationType().equals(clazz))
-                    {
-                        return true;
-                    }
-                }
-            }
-
-        }
-        return false;
-    }
 
     /**
      * Checks if the given qualifiers are equal.
@@ -742,18 +637,6 @@ public final class AnnotationUtil
         return Collections.emptyList();
     }
 
-    /**
-     * Gets the array of qualifier annotations on the given array.
-     *
-     * @param annotations annotation array
-     * @return array containing qualifier anns
-     */
-    @Deprecated
-    public static Annotation[] getQualifierAnnotations(Annotation... annotations)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getQualifierAnnotations(annotations);
-    }
-
 
     /**
      * Gets array of methods that has parameter with given annotation type.
@@ -945,78 +828,6 @@ public final class AnnotationUtil
         return null;        
     }
 
-    /**
-     * Returns true if the annotation is defined in xml or annotated with
-     * {@link javax.interceptor.InterceptorBinding} false otherwise.
-     *
-     * @param clazz type of the annotation
-     * @return true if the annotation is defined in xml or annotated with
-     *         {@link javax.interceptor.InterceptorBinding} false otherwise
-     */
-    @Deprecated
-    public static boolean isInterceptorBindingAnnotation(Class<? extends Annotation>
clazz)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().isInterceptorBindingAnnotation(clazz);
-    }
-
-    /**
-     * Collect the interceptor bindings from an array of annotations, including
-     * transitively defined interceptor bindings.
-     * @param anns An array of annotations
-     * @return an array of interceptor binding annotations, including the input and any transitively
declared annotations
-     */
-    @Deprecated
-    public static Annotation[] getInterceptorBindingMetaAnnotations(Annotation[] anns)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getInterceptorBindingMetaAnnotations(anns);
-    }
-
-    @Deprecated
-    public static Annotation[] getStereotypeMetaAnnotations(Annotation[] anns)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getStereotypeMetaAnnotations(anns);
-    }
-
-    @Deprecated
-    public static boolean hasStereoTypeMetaAnnotation(Annotation[] anns)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().hasStereoTypeMetaAnnotation(anns);
-    }
-
-    /**
-     * Returns true if the annotation is defined in xml or annotated with
-     * {@link javax.enterprise.inject.Stereotype} false otherwise.
-     *
-     * @param clazz type of the annotation
-     * @return true if the annotation is defined in xml or annotated with
-     *         {@link javax.enterprise.inject.Stereotype} false otherwise
-     */
-    @Deprecated
-    public static boolean isStereoTypeAnnotation(Class<? extends Annotation> clazz)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().isStereoTypeAnnotation(clazz);
-    }
-
-    /**
-     * If the bean extends generic class via Realizes
-     * annotation, realized based producer methods, fields and observer
-     * methods qualifier is
-     *
-     * <ul>
-     *  <li>Qualifiers on the definitions</li>
-     *  <li>Plus class qualifiers</li>
-     *  <li>Minus generic class qualifiers</li>
-     * </ul>
-     *
-     * @param clazz realized definition class
-     * @param anns binding annotations array
-     */
-    @Deprecated
-    public static Annotation[] getRealizesGenericAnnotations(Class<?> clazz, Annotation[]
anns)
-    {
-        return WebBeansContext.getInstance().getAnnotationManager().getRealizesGenericAnnotations(clazz,
anns);
-    }
-
     public static Annotation[] getAnnotationsFromSet(Set<Annotation> set)
     {
         if(set != null)

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/StartupPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/StartupPerformanceTest.java?rev=1305134&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/StartupPerformanceTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/performance/StartupPerformanceTest.java
Sun Mar 25 21:06:25 2012
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.performance;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.contexts.session.common.PersonalDataBean;
+import org.apache.webbeans.newtests.injection.circular.beans.CircularApplicationScopedBean;
+import org.apache.webbeans.newtests.injection.circular.beans.CircularDependentScopedBean;
+import org.apache.webbeans.newtests.managed.instance.beans.InstanceInjectedComponent;
+import org.apache.webbeans.newtests.profields.beans.classproducer.MyProductBean;
+import org.apache.webbeans.newtests.profields.beans.classproducer.MyProductProducer;
+import org.apache.webbeans.newtests.profields.beans.classproducer.ProductInjectedBean;
+import org.apache.webbeans.newtests.promethods.beans.PersonProducerBean;
+import org.apache.webbeans.newtests.promethods.common.Person;
+import org.apache.webbeans.newtests.specalization.AdvancedPenProducer;
+import org.apache.webbeans.newtests.specalization.DefaultPenProducer;
+import org.apache.webbeans.newtests.specalization.Pen;
+import org.apache.webbeans.newtests.specalization.PremiumPenProducer;
+import org.apache.webbeans.test.component.CheckWithCheckPayment;
+import org.apache.webbeans.test.component.CheckWithMoneyPayment;
+import org.apache.webbeans.test.component.IPayment;
+import org.apache.webbeans.test.component.PaymentProcessorComponent;
+import org.junit.Test;
+
+/**
+ * Small unit test to help testing the startup performance.
+ * We just stuff lots of classes into it and check how it performs.
+ */
+public class StartupPerformanceTest extends AbstractUnitTest
+{
+    @Test
+    public void testPerformance()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(PaymentProcessorComponent.class);
+        beanClasses.add(InstanceInjectedComponent.class);
+        beanClasses.add(CheckWithCheckPayment.class);
+        beanClasses.add(CheckWithMoneyPayment.class);
+        beanClasses.add(IPayment.class);
+        beanClasses.add(ProductInjectedBean.class);
+        beanClasses.add(MyProductProducer.class);
+        beanClasses.add(MyProductBean.class);
+        beanClasses.add(Person.class);
+        beanClasses.add(PersonProducerBean.class);
+        beanClasses.add(Pen.class);
+        beanClasses.add(DefaultPenProducer.class);
+        beanClasses.add(AdvancedPenProducer.class);
+        beanClasses.add(PremiumPenProducer.class);
+        beanClasses.add(PersonalDataBean.class);
+        beanClasses.add(CircularDependentScopedBean.class);
+        beanClasses.add(CircularApplicationScopedBean.class);
+
+        startContainer(beanClasses, beanXmls);
+
+        // do nothing ...
+
+        shutDownContainer();
+    }
+}



Mime
View raw message