[weld-commits] Weld SVN: r6069 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Tue Mar 30 06:23:00 EDT 2010


Author: swd847
Date: 2010-03-30 06:22:59 -0400 (Tue, 30 Mar 2010)
New Revision: 6069

Modified:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
allow overriding of parameter types



Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -21,10 +21,10 @@
 
    private final List<AnnotatedParameter<X>> parameters;
 
-   protected AbstractNewAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType)
+   protected AbstractNewAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType, Map<Integer, Type> parameterTypeOverrides)
    {
       super(declaringType, member, memberType, annotations, genericType, null);
-      this.parameters = getAnnotatedParameters(this, parameterTypes, parameterAnnotations);
+      this.parameters = getAnnotatedParameters(this, parameterTypes, parameterAnnotations, parameterTypeOverrides);
    }
 
    public List<AnnotatedParameter<X>> getParameters()
@@ -38,7 +38,7 @@
 
    }  
    
-   private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractNewAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Map<Integer, AnnotationStore> parameterAnnotations)
+   private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractNewAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
    {
       List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
       int len = parameterTypes.length;
@@ -49,7 +49,12 @@
          {
             builder.addAll(parameterAnnotations.get(i));
          }
-         NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create());
+         Type over = null;
+         if (parameterTypeOverrides != null)
+         {
+            over = parameterTypeOverrides.get(i);
+         }
+         NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create(), over);
          parameters.add(p);
       }
       return parameters;

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -1,6 +1,7 @@
 package org.jboss.weld.extensions.util.annotated;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
 import java.util.Map;
 
 import javax.enterprise.inject.spi.AnnotatedConstructor;
@@ -13,9 +14,9 @@
 class NewAnnotatedConstructor<X> extends AbstractNewAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
 {
 
-   NewAnnotatedConstructor(NewAnnotatedType<X> type, Constructor<?> constructor, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations)
+   NewAnnotatedConstructor(NewAnnotatedType<X> type, Constructor<?> constructor, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> typeOverrides)
    {
-      super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), annotations, parameterAnnotations, null);
+      super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), annotations, parameterAnnotations, null, typeOverrides);
    }
 
 }

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -1,6 +1,7 @@
 package org.jboss.weld.extensions.util.annotated;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.Map;
 
 import javax.enterprise.inject.spi.AnnotatedMethod;
@@ -13,9 +14,9 @@
  */
 class NewAnnotatedMethod<X> extends AbstractNewAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
 {
-   NewAnnotatedMethod(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations)
+   NewAnnotatedMethod(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
    {
-      super(type, method, method.getReturnType(), method.getParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType());
+      super(type, method, method.getReturnType(), method.getParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
    }
 
 }

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -1,5 +1,7 @@
 package org.jboss.weld.extensions.util.annotated;
 
+import java.lang.reflect.Type;
+
 import javax.enterprise.inject.spi.AnnotatedCallable;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 
@@ -14,9 +16,9 @@
    private final int position;
    private final AnnotatedCallable<X> declaringCallable;
 
-   NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations)
+   NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations, Type typeOverride)
    {
-      super(type, annotations, null, null);
+      super(type, annotations, null, typeOverride);
       this.declaringCallable = declaringCallable;
       this.position = position;
    }

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -38,7 +38,7 @@
     * If annotation have been added to other methods as well we add them to
     * 
     */
-   NewAnnotatedType(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, AnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnotations, Map<Field, Type> fieldTypes)
+   NewAnnotatedType(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, AnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnotations, Map<Field, Type> fieldTypes, Map<Method, Map<Integer, Type>> methodParameterTypes, Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes)
    {
       super(clazz, typeAnnotations, null, null);
       this.javaClass = clazz;
@@ -48,7 +48,7 @@
       Set<Field> fset = new HashSet<Field>();
       for (Constructor<?> c : clazz.getConstructors())
       {
-         NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
+         NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), constructorParameterTypes.get(c));
          constructors.add(nc);
          cset.add(c);
       }
@@ -56,14 +56,14 @@
       {
          if (!cset.contains(c.getKey()))
          {
-            NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()));
+            NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()), constructorParameterTypes.get(c.getKey()));
             constructors.add(nc);
          }
       }
       this.methods = new HashSet<AnnotatedMethod<? super X>>();
       for (Method m : clazz.getMethods())
       {
-         NewAnnotatedMethod<X> met = new NewAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
+         NewAnnotatedMethod<X> met = new NewAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m));
          methods.add(met);
          mset.add(m);
       }
@@ -71,7 +71,7 @@
       {
          if (!mset.contains(c.getKey()))
          {
-            NewAnnotatedMethod<X> nc = new NewAnnotatedMethod<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()));
+            NewAnnotatedMethod<X> nc = new NewAnnotatedMethod<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
             methods.add(nc);
          }
       }

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java	2010-03-30 09:55:00 UTC (rev 6068)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java	2010-03-30 10:22:59 UTC (rev 6069)
@@ -40,6 +40,8 @@
    private Class<X> underlying;
 
    private Map<Field, Type> fieldTypes = new HashMap<Field, Type>();
+   private Map<Method, Map<Integer, Type>> methodParameterTypes = new HashMap<Method, Map<Integer, Type>>();
+   private Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer, Type>>();
 
    public NewAnnotatedTypeBuilder(Class<X> underlying)
    {
@@ -540,7 +542,7 @@
          }
       }
 
-      return new NewAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes);
+      return new NewAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
    }
 
    public void overrideFieldType(Field field, Type type)
@@ -548,4 +550,26 @@
       fieldTypes.put(field, type);
    }
 
+   public void overrideMethodParameterType(Method method, Type type, int position)
+   {
+      Map<Integer, Type> t = methodParameterTypes.get(method);
+      if (t == null)
+      {
+         t = new HashMap<Integer, Type>();
+         methodParameterTypes.put(method, t);
+      }
+      t.put(position, type);
+   }
+
+   public void overrideConstructorParameterType(Constructor<?> constructor, Type type, int position)
+   {
+      Map<Integer, Type> t = constructorParameterTypes.get(constructor);
+      if (t == null)
+      {
+         t = new HashMap<Integer, Type>();
+         constructorParameterTypes.put(constructor, t);
+      }
+      t.put(position, type);
+   }
+
 }



More information about the weld-commits mailing list