Weld SVN: r6205 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: bean/generic and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 19:54:14 -0400 (Thu, 29 Apr 2010)
New Revision: 6205
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
Log:
minor
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-04-29 23:53:43 UTC (rev 6204)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-04-29 23:54:14 UTC (rev 6205)
@@ -32,7 +32,7 @@
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
-import org.jboss.weld.extensions.util.ReflectionUtils;
+import org.jboss.weld.extensions.util.Reflections;
/**
* Class for constructing a new AnnotatedType. A new instance of builder must be
@@ -100,7 +100,7 @@
typeAnnotations.add(annotation);
}
- for (Field field : ReflectionUtils.getFields(underlyingType))
+ for (Field field : Reflections.getFields(underlyingType))
{
AnnotationBuilder annotationBuilder = new AnnotationBuilder();
fields.put(field, annotationBuilder);
@@ -111,7 +111,7 @@
}
}
- for (Method method : ReflectionUtils.getMethods(underlyingType))
+ for (Method method : Reflections.getMethods(underlyingType))
{
AnnotationBuilder annotationBuilder = new AnnotationBuilder();
method.setAccessible(true);
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29 23:53:43 UTC (rev 6204)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29 23:54:14 UTC (rev 6205)
@@ -16,7 +16,7 @@
*/
package org.jboss.weld.extensions.bean.generic;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getField;
+import static org.jboss.weld.extensions.util.Reflections.getField;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 23:53:43 UTC (rev 6204)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 23:54:14 UTC (rev 6205)
@@ -16,8 +16,8 @@
*/
package org.jboss.weld.extensions.core;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
+import static org.jboss.weld.extensions.util.Reflections.getAnnotationsWithMetatype;
+import static org.jboss.weld.extensions.util.Reflections.getMemberType;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29 23:53:43 UTC (rev 6204)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29 23:54:14 UTC (rev 6205)
@@ -1,201 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- * class that provides a way of retrieving all methods and fields from a class
- *
- * @author stuart
- *
- */
-public class ReflectionUtils
-{
-
- public static Set<Field> getFields(Class<?> clazz)
- {
- HashSet<Field> ret = new HashSet<Field>();
- Class<?> p = clazz;
- while (p != null && p != Object.class)
- {
- for (Field a : p.getDeclaredFields())
- {
- ret.add(a);
- }
- p = p.getSuperclass();
- }
- return ret;
- }
-
- public static Field getField(Class<?> parent, String name)
- {
- Class<?> p = parent;
- while (p != null && p != Object.class)
- {
- try
- {
- return p.getDeclaredField(name);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static <X> AnnotatedField<? super X> getField(AnnotatedType<X> annotatedType, Field field)
- {
- for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
- {
- if (annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass()) && annotatedField.getJavaMember().getName().equals(field.getName()))
- {
- return annotatedField;
- }
- }
- return null;
- }
-
- public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation> annotations, Class<? extends Annotation> metaAnnotationType)
- {
- Set<Annotation> set = new HashSet<Annotation>();
- for (Annotation annotation : annotations)
- {
- if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
- {
- set.add(annotation);
- }
- }
- return set;
- }
-
-
- public static boolean methodExists(Class<?> parent, String name)
- {
- Class<?> p = parent;
- while (p != null && p != Object.class)
- {
- for (Method m : p.getDeclaredMethods())
- {
- if (m.getName().equals(name))
- {
- return true;
- }
- }
- p = p.getSuperclass();
- }
- return false;
- }
-
- public static Set<Method> getMethods(Class<?> clazz)
- {
- HashSet<Method> ret = new HashSet<Method>();
- Class<?> p = clazz;
- while (p != null && p != Object.class)
- {
- for (Method a : p.getDeclaredMethods())
- {
- ret.add(a);
- }
- p = p.getSuperclass();
- }
- return ret;
- }
-
- public static Method getMethod(Class<?> parent, String name, Class<?>... args)
- {
- Class<?> p = parent;
- while (p != null && p != Object.class)
- {
- try
- {
- return p.getDeclaredMethod(name, args);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static Constructor<?> getConstructor(Class<?> parent, Class<?>... args)
- {
- Class<?> p = parent;
- while (p != null && p != Object.class)
- {
- try
- {
- return p.getDeclaredConstructor(args);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static Set<Constructor<?>> getConstructors(Class<?> clazz)
- {
- HashSet<Constructor<?>> ret = new HashSet<Constructor<?>>();
- Class<?> p = clazz;
- while (p != null && p != Object.class)
- {
- for (Constructor<?> c : p.getDeclaredConstructors())
- {
- ret.add(c);
- }
- p = p.getSuperclass();
- }
- return ret;
- }
-
- public static Class<?> getMemberType(Member member)
- {
- if (member instanceof Field)
- {
- return ((Field) member).getType();
- }
- else if (member instanceof Method)
- {
- return ((Method) member).getReturnType();
- }
- else if (member instanceof Constructor<?>)
- {
- return ((Constructor<?>) member).getDeclaringClass();
- }
- else
- {
- throw new UnsupportedOperationException("Cannot operate on a member of type " + member.getClass());
- }
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-04-29 23:54:14 UTC (rev 6205)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * class that provides a way of retrieving all methods and fields from a class
+ *
+ * @author stuart
+ *
+ */
+public class Reflections
+{
+
+ private Reflections() {}
+
+ public static Set<Field> getFields(Class<?> clazz)
+ {
+ HashSet<Field> ret = new HashSet<Field>();
+ Class<?> p = clazz;
+ while (p != null && p != Object.class)
+ {
+ for (Field a : p.getDeclaredFields())
+ {
+ ret.add(a);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Field getField(Class<?> parent, String name)
+ {
+ Class<?> p = parent;
+ while (p != null && p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredField(name);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static <X> AnnotatedField<? super X> getField(AnnotatedType<X> annotatedType, Field field)
+ {
+ for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
+ {
+ if (annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass()) && annotatedField.getJavaMember().getName().equals(field.getName()))
+ {
+ return annotatedField;
+ }
+ }
+ return null;
+ }
+
+ public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation> annotations, Class<? extends Annotation> metaAnnotationType)
+ {
+ Set<Annotation> set = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ set.add(annotation);
+ }
+ }
+ return set;
+ }
+
+
+ public static boolean methodExists(Class<?> parent, String name)
+ {
+ Class<?> p = parent;
+ while (p != null && p != Object.class)
+ {
+ for (Method m : p.getDeclaredMethods())
+ {
+ if (m.getName().equals(name))
+ {
+ return true;
+ }
+ }
+ p = p.getSuperclass();
+ }
+ return false;
+ }
+
+ public static Set<Method> getMethods(Class<?> clazz)
+ {
+ HashSet<Method> ret = new HashSet<Method>();
+ Class<?> p = clazz;
+ while (p != null && p != Object.class)
+ {
+ for (Method a : p.getDeclaredMethods())
+ {
+ ret.add(a);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Method getMethod(Class<?> parent, String name, Class<?>... args)
+ {
+ Class<?> p = parent;
+ while (p != null && p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredMethod(name, args);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static Constructor<?> getConstructor(Class<?> parent, Class<?>... args)
+ {
+ Class<?> p = parent;
+ while (p != null && p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredConstructor(args);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static Set<Constructor<?>> getConstructors(Class<?> clazz)
+ {
+ HashSet<Constructor<?>> ret = new HashSet<Constructor<?>>();
+ Class<?> p = clazz;
+ while (p != null && p != Object.class)
+ {
+ for (Constructor<?> c : p.getDeclaredConstructors())
+ {
+ ret.add(c);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Class<?> getMemberType(Member member)
+ {
+ if (member instanceof Field)
+ {
+ return ((Field) member).getType();
+ }
+ else if (member instanceof Method)
+ {
+ return ((Method) member).getReturnType();
+ }
+ else if (member instanceof Constructor<?>)
+ {
+ return ((Constructor<?>) member).getDeclaringClass();
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Cannot operate on a member of type " + member.getClass());
+ }
+ }
+
+}
14 years, 8 months
Weld SVN: r6204 - extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/lookup.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 19:53:43 -0400 (Thu, 29 Apr 2010)
New Revision: 6204
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/lookup/IdentifiableBeanExtension.java
Log:
minor
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/lookup/IdentifiableBeanExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/lookup/IdentifiableBeanExtension.java 2010-04-29 22:13:29 UTC (rev 6203)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/lookup/IdentifiableBeanExtension.java 2010-04-29 23:53:43 UTC (rev 6204)
@@ -26,36 +26,37 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
/**
- * extension that allows the AnnotatedType to be retrieved for a given bean
+ * extension that allows the AnnotatedType to be retrieved for a given bean
*
* This is hopefully a temporary workaround until a spec limitation is removed
*
* @author Stuart Douglas <stuart(a)baileyroberts.com.au>
- *
+ *
*/
public class IdentifiableBeanExtension implements Extension
{
Map<Object, AnnotatedType<?>> types = Collections.synchronizedMap(new WeakHashMap<Object, AnnotatedType<?>>(1000));
- public void processInjectionTarget(@Observes ProcessInjectionTarget<?> event)
+ public <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T> event)
{
boolean requiresId = false;
- for(Annotation a : event.getAnnotatedType().getAnnotations())
+ for (Annotation a : event.getAnnotatedType().getAnnotations())
{
- if(a.annotationType().isAnnotationPresent(RequiresIdentification.class))
+ if (a.annotationType().isAnnotationPresent(RequiresIdentification.class))
{
requiresId = true;
break;
}
}
- if(!requiresId)
+ if (!requiresId)
{
- for(AnnotatedMethod<?> m : event.getAnnotatedType().getMethods())
+ for (AnnotatedMethod<? super T> m : event.getAnnotatedType().getMethods())
{
- for(Annotation a : m.getAnnotations())
+ for (Annotation a : m.getAnnotations())
{
- if(a.annotationType().isAnnotationPresent(RequiresIdentification.class))
+ if (a.annotationType().isAnnotationPresent(RequiresIdentification.class))
{
requiresId = true;
break;
@@ -63,15 +64,15 @@
}
}
}
- if(requiresId)
+ if (requiresId)
{
- event.setInjectionTarget(new IdentifiableInjectionTarget(event.getInjectionTarget(), event.getAnnotatedType(),types));
+ event.setInjectionTarget(new IdentifiableInjectionTarget<T>(event.getInjectionTarget(), event.getAnnotatedType(), types));
}
}
-
+
public AnnotatedType<?> getAnnotatedType(Object instance)
{
return types.get(instance);
}
-
+
}
14 years, 8 months
Weld SVN: r6203 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: bean and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 18:13:29 -0400 (Thu, 29 Apr 2010)
New Revision: 6203
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
Log:
cleanup custom bean impl
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -182,6 +182,8 @@
}
private static final char SEPERATOR = ';';
+
+ private Annotateds() {}
/**
* Generates a unique signature for an annotated type. Members without
@@ -558,8 +560,4 @@
}
- private Annotateds()
- {
- }
-
}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java (from rev 6202, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,248 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.inject.Named;
+
+import org.jboss.weld.extensions.annotated.Annotateds;
+
+/**
+ * class that can build a bean from an AnnotatedType.
+ *
+ * @author stuart
+ *
+ */
+public class BeanBuilder<T>
+{
+
+ private final AnnotatedType<T> type;
+ private final BeanManager beanManager;
+ private InjectionTarget<T> injectionTarget;
+ private String name;
+ private Set<Annotation> qualifiers;
+ private Class<? extends Annotation> scope;
+ private Set<Class<? extends Annotation>> stereotypes;
+ private Set<Type> types = new HashSet<Type>();
+ private boolean alternative = false;
+ private boolean nullable = false;
+ private BeanLifecycle<T> beanLifecycle;
+ boolean passivationCapable;
+ private String id;
+
+ public BeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
+ {
+ this.type = type;
+ this.beanManager = beanManager;
+ }
+
+ public BeanBuilder<T> defineBeanFromAnnotatedType()
+ {
+ this.injectionTarget = beanManager.createInjectionTarget(type);
+ this.qualifiers = new HashSet<Annotation>();
+ this.stereotypes = new HashSet<Class<? extends Annotation>>();
+ for (Annotation annotation : type.getAnnotations())
+ {
+ if (beanManager.isQualifier(annotation.annotationType()))
+ {
+ this.qualifiers.add(annotation);
+ }
+ else if (beanManager.isScope(annotation.annotationType()))
+ {
+ this.scope = annotation.annotationType();
+ }
+ else if (beanManager.isStereotype(annotation.annotationType()))
+ {
+ this.stereotypes.add(annotation.annotationType());
+ }
+ if (annotation instanceof Named)
+ {
+ this.name = ((Named) annotation).value();
+ }
+ if (annotation instanceof Alternative)
+ {
+ this.alternative = true;
+ }
+ }
+ if (this.scope == null)
+ {
+ this.scope = Dependent.class;
+ }
+ for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass())
+ {
+ this.types.add(c);
+ }
+ for (Class<?> i : type.getJavaClass().getInterfaces())
+ {
+ this.types.add(i);
+ }
+ this.beanLifecycle = new BeanLifecycleImpl<T>();
+ this.id = BeanImpl.class.getName() + ":" + Annotateds.createTypeId(type);
+ return this;
+ }
+
+ public Bean<T> create()
+ {
+ if (!passivationCapable)
+ {
+ return new BeanImpl<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ }
+ return new PassivationCapableBeanImpl<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return injectionTarget;
+ }
+
+ public BeanBuilder<T> setInjectionTarget(InjectionTarget<T> injectionTarget)
+ {
+ this.injectionTarget = injectionTarget;
+ return this;
+ }
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public BeanBuilder<T> setQualifiers(Set<Annotation> qualifiers)
+ {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public BeanBuilder<T> setScope(Class<? extends Annotation> scope)
+ {
+ this.scope = scope;
+ return this;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return stereotypes;
+ }
+
+ public BeanBuilder<T> setStereotypes(Set<Class<? extends Annotation>> stereotypes)
+ {
+ this.stereotypes = stereotypes;
+ return this;
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public BeanBuilder<T> setTypes(Set<Type> types)
+ {
+ this.types = types;
+ return this;
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public BeanBuilder<T> setAlternative(boolean alternative)
+ {
+ this.alternative = alternative;
+ return this;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ public BeanBuilder<T> setNullable(boolean nullable)
+ {
+ this.nullable = nullable;
+ return this;
+ }
+
+ public BeanLifecycle<T> getBeanLifecycle()
+ {
+ return beanLifecycle;
+ }
+
+ public BeanBuilder<T> setBeanLifecycle(BeanLifecycle<T> beanLifecycle)
+ {
+ this.beanLifecycle = beanLifecycle;
+ return this;
+ }
+
+ public AnnotatedType<T> getType()
+ {
+ return type;
+ }
+
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public BeanBuilder<T> setName(String name)
+ {
+ this.name = name;
+ return this;
+ }
+
+ public boolean isPassivationCapable()
+ {
+ return passivationCapable;
+ }
+
+ public BeanBuilder<T> setPassivationCapable(boolean passivationCapable)
+ {
+ this.passivationCapable = passivationCapable;
+ return this;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public BeanBuilder<T> setId(String id)
+ {
+ this.id = id;
+ return this;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+/**
+ * An immutable bean.
+ *
+ * @author stuart
+ *
+ * @param <T>
+ */
+class BeanImpl<T> implements Bean<T>
+{
+ private final Class<?> beanClass;
+ private final InjectionTarget<T> injectionTarget;
+ private final String name;
+ private final Set<Annotation> qualifiers;
+ private final Class<? extends Annotation> scope;
+ private final Set<Class<? extends Annotation>> stereotypes;
+ private final Set<Type> types;
+ private final boolean alternative;
+ private final boolean nullable;
+ private final BeanLifecycle<T> beanLifecycle;
+
+ BeanImpl(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ {
+ this.beanClass = beanClass;
+ this.injectionTarget = injectionTarget;
+ this.name = name;
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.scope = scope;
+ this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
+ this.types = new HashSet<Type>(types);
+ this.alternative = alternative;
+ this.nullable = nullable;
+ this.beanLifecycle = beanLifecycle;
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return injectionTarget.getInjectionPoints();
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return injectionTarget;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.unmodifiableSet(qualifiers);
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.unmodifiableSet(stereotypes);
+ }
+
+ public Set<Type> getTypes()
+ {
+ return Collections.unmodifiableSet(types);
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ public T create(CreationalContext<T> arg0)
+ {
+ return beanLifecycle.create(this, arg0);
+ }
+
+ public void destroy(T arg0, CreationalContext<T> arg1)
+ {
+ beanLifecycle.destroy(this, arg0, arg1);
+ }
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
+ }
+
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -27,8 +27,8 @@
*/
public interface BeanLifecycle<T>
{
- public T create(CustomBean<T> bean, CreationalContext<T> arg0);
+ public T create(BeanImpl<T> bean, CreationalContext<T> arg0);
- public void destroy(CustomBean<T> bean, T arg0, CreationalContext<T> arg1);
+ public void destroy(BeanImpl<T> bean, T arg0, CreationalContext<T> arg1);
}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.bean;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+public class BeanLifecycleImpl<T> implements BeanLifecycle<T>
+{
+
+ public BeanLifecycleImpl() {}
+
+ public T create(BeanImpl<T> bean, CreationalContext<T> creationalContext)
+ {
+ T instance = bean.getInjectionTarget().produce(creationalContext);
+ bean.getInjectionTarget().inject(instance, creationalContext);
+ bean.getInjectionTarget().postConstruct(instance);
+ return instance;
+ }
+
+ public void destroy(BeanImpl<T> bean, T instance, CreationalContext<T> creationalContext)
+ {
+ try
+ {
+ bean.getInjectionTarget().preDestroy(instance);
+ creationalContext.release();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-
-/**
- * An immutable bean.
- *
- * @author stuart
- *
- * @param <T>
- */
-public class CustomBean<T> implements Bean<T>
-{
- final Class<?> beanClass;
- final InjectionTarget<T> injectionTarget;
- final String name;
- final Set<Annotation> qualifiers;
- final Class<? extends Annotation> scope;
- final Set<Class<? extends Annotation>> stereotypes;
- final Set<Type> types;
- final boolean alternative;
- final boolean nullable;
- final BeanLifecycle<T> beanLifecycle;
-
- CustomBean(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
- {
- this.beanClass = beanClass;
- this.injectionTarget = injectionTarget;
- this.name = name;
- this.qualifiers = new HashSet<Annotation>(qualifiers);
- this.scope = scope;
- this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
- this.types = new HashSet<Type>(types);
- this.alternative = alternative;
- this.nullable = nullable;
- this.beanLifecycle = beanLifecycle;
- }
-
- public Class<?> getBeanClass()
- {
- return beanClass;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return injectionTarget.getInjectionPoints();
- }
-
- public InjectionTarget<T> getInjectionTarget()
- {
- return injectionTarget;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return Collections.unmodifiableSet(qualifiers);
- }
-
- public Class<? extends Annotation> getScope()
- {
- return scope;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return Collections.unmodifiableSet(stereotypes);
- }
-
- public Set<Type> getTypes()
- {
- return Collections.unmodifiableSet(types);
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public boolean isNullable()
- {
- return nullable;
- }
-
- public T create(CreationalContext<T> arg0)
- {
- return beanLifecycle.create(this, arg0);
- }
-
- public void destroy(T arg0, CreationalContext<T> arg1)
- {
- beanLifecycle.destroy(this, arg0, arg1);
- }
-
- @Override
- public String toString()
- {
- return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,242 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Named;
-
-import org.jboss.weld.extensions.annotated.Annotateds;
-
-/**
- * class that can build a bean from an AnnotatedType.
- *
- * @author stuart
- *
- */
-public class CustomBeanBuilder<T>
-{
-
- final AnnotatedType<T> type;
- final BeanManager beanManager;
- InjectionTarget<T> injectionTarget;
- String name;
- Set<Annotation> qualifiers;
- Class<? extends Annotation> scope;
- Set<Class<? extends Annotation>> stereotypes;
- Set<Type> types = new HashSet<Type>();
- boolean alternative = false;
- boolean nullable = false;
- BeanLifecycle<T> beanLifecycle;
- boolean passivationCapable;
- String id;
-
- public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
- {
- this(type, beanManager, beanManager.createInjectionTarget(type));
- }
-
- public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager, InjectionTarget<T> injectionTarget)
- {
- this.type = type;
- this.beanManager = beanManager;
- this.injectionTarget = injectionTarget;
- qualifiers = new HashSet<Annotation>();
- stereotypes = new HashSet<Class<? extends Annotation>>();
- for (Annotation a : type.getAnnotations())
- {
- if (beanManager.isQualifier(a.annotationType()))
- {
- qualifiers.add(a);
- }
- else if (beanManager.isScope(a.annotationType()))
- {
- scope = a.annotationType();
- }
- else if (beanManager.isStereotype(a.annotationType()))
- {
- stereotypes.add(a.annotationType());
- }
- if (a instanceof Named)
- {
- Named n = (Named) a;
- name = n.value();
- }
- if (a instanceof Alternative)
- {
- alternative = true;
- }
- }
- if (scope == null)
- {
- scope = Dependent.class;
- }
-
- Class<?> c = type.getJavaClass();
- do
- {
- types.add(c);
- c = c.getSuperclass();
- }
- while (c != null);
- for (Class<?> i : type.getJavaClass().getInterfaces())
- {
- types.add(i);
- }
- beanLifecycle = new SimpleBeanLifecycle<T>(type.getJavaClass(), beanManager);
- id = CustomBean.class.getName() + ":" + Annotateds.createTypeId(type);
- }
-
- public Bean<T> build()
- {
- if (!passivationCapable)
- {
- return new CustomBean<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
- }
- return new PassivationCapableCustomBean<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
-
- }
-
- public InjectionTarget<T> getInjectionTarget()
- {
- return injectionTarget;
- }
-
- public void setInjectionTarget(InjectionTarget<T> injectionTarget)
- {
- this.injectionTarget = injectionTarget;
- }
- public Set<Annotation> getQualifiers()
- {
- return qualifiers;
- }
-
- public void setQualifiers(Set<Annotation> qualifiers)
- {
- this.qualifiers = qualifiers;
- }
-
- public Class<? extends Annotation> getScope()
- {
- return scope;
- }
-
- public void setScope(Class<? extends Annotation> scope)
- {
- this.scope = scope;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return stereotypes;
- }
-
- public void setStereotypes(Set<Class<? extends Annotation>> stereotypes)
- {
- this.stereotypes = stereotypes;
- }
-
- public Set<Type> getTypes()
- {
- return types;
- }
-
- public void setTypes(Set<Type> types)
- {
- this.types = types;
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public void setAlternative(boolean alternative)
- {
- this.alternative = alternative;
- }
-
- public boolean isNullable()
- {
- return nullable;
- }
-
- public void setNullable(boolean nullable)
- {
- this.nullable = nullable;
- }
-
- public BeanLifecycle<T> getBeanLifecycle()
- {
- return beanLifecycle;
- }
-
- public void setBeanLifecycle(BeanLifecycle<T> beanLifecycle)
- {
- this.beanLifecycle = beanLifecycle;
- }
-
- public AnnotatedType<T> getType()
- {
- return type;
- }
-
- public BeanManager getBeanManager()
- {
- return beanManager;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public boolean isPassivationCapable()
- {
- return passivationCapable;
- }
-
- public void setPassivationCapable(boolean passivationCapable)
- {
- this.passivationCapable = passivationCapable;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,148 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-/**
- * implementation of InjectionPoint that can be used by other extensions
- *
- * @author stuart
- *
- */
-public class CustomInjectionPoint implements InjectionPoint
-{
-
- public CustomInjectionPoint(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
- {
- this.annotated = field;
- this.member = field.getJavaMember();
- this.qualifiers = new HashSet<Annotation>(qualifiers);
- this.type = field.getJavaMember().getGenericType();
- this.trans = trans;
- this.delegate = delegate;
- this.bean = bean;
- }
-
- public CustomInjectionPoint(AnnotatedField<?> field, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
- {
- this.annotated = field;
- this.member = field.getJavaMember();
- this.qualifiers = new HashSet<Annotation>();
- this.type = field.getJavaMember().getGenericType();
- this.trans = trans;
- this.delegate = delegate;
- this.bean = bean;
- for (Annotation a : field.getAnnotations())
- {
- if (beanManager.isQualifier(a.annotationType()))
- {
- qualifiers.add(a);
- }
- }
- }
-
- public CustomInjectionPoint(AnnotatedParameter<?> param, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
- {
- this.annotated = param;
- this.member = param.getDeclaringCallable().getJavaMember();
- this.qualifiers = new HashSet<Annotation>(qualifiers);
- this.trans = trans;
- this.delegate = delegate;
- this.bean = bean;
- this.type = param.getBaseType();
- }
-
- public CustomInjectionPoint(AnnotatedParameter<?> param, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
- {
- this.annotated = param;
- this.member = param.getDeclaringCallable().getJavaMember();
- this.qualifiers = new HashSet<Annotation>();
- this.trans = trans;
- this.delegate = delegate;
- this.bean = bean;
- this.type = param.getBaseType();
- for (Annotation a : annotated.getAnnotations())
- {
- if (beanManager.isQualifier(a.annotationType()))
- {
- qualifiers.add(a);
- }
- }
- }
-
- private final Annotated annotated;
-
- private final Member member;
-
- private final Bean<?> bean;
-
- private final Set<Annotation> qualifiers;
-
- private final Type type;
-
- private final boolean trans;
-
- private final boolean delegate;
-
- public Annotated getAnnotated()
- {
- return annotated;
- }
-
- public Bean<?> getBean()
- {
- return bean;
- }
-
- public Member getMember()
- {
- return member;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return qualifiers;
- }
-
- public Type getType()
- {
- return type;
- }
-
- public boolean isDelegate()
- {
- return delegate;
- }
-
- public boolean isTransient()
- {
- return trans;
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * A simple implementation of InjectionPoint
+ *
+ * @author stuart
+ *
+ */
+public class InjectionPointImpl implements InjectionPoint
+{
+
+ public InjectionPointImpl(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.type = field.getJavaMember().getGenericType();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ }
+
+ public InjectionPointImpl(AnnotatedField<?> field, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = field;
+ this.member = field.getJavaMember();
+ this.qualifiers = new HashSet<Annotation>();
+ this.type = field.getJavaMember().getGenericType();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ for (Annotation a : field.getAnnotations())
+ {
+ if (beanManager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ }
+
+ public InjectionPointImpl(AnnotatedParameter<?> param, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = param;
+ this.member = param.getDeclaringCallable().getJavaMember();
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ this.type = param.getBaseType();
+ }
+
+ public InjectionPointImpl(AnnotatedParameter<?> param, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+ {
+ this.annotated = param;
+ this.member = param.getDeclaringCallable().getJavaMember();
+ this.qualifiers = new HashSet<Annotation>();
+ this.trans = trans;
+ this.delegate = delegate;
+ this.bean = bean;
+ this.type = param.getBaseType();
+ for (Annotation a : annotated.getAnnotations())
+ {
+ if (beanManager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ }
+
+ private final Annotated annotated;
+
+ private final Member member;
+
+ private final Bean<?> bean;
+
+ private final Set<Annotation> qualifiers;
+
+ private final Type type;
+
+ private final boolean trans;
+
+ private final boolean delegate;
+
+ public Annotated getAnnotated()
+ {
+ return annotated;
+ }
+
+ public Bean<?> getBean()
+ {
+ return bean;
+ }
+
+ public Member getMember()
+ {
+ return member;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public boolean isDelegate()
+ {
+ return delegate;
+ }
+
+ public boolean isTransient()
+ {
+ return trans;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+public class PassivationCapableBeanImpl<T> extends BeanImpl<T> implements PassivationCapable
+{
+ private final String id;
+
+ PassivationCapableBeanImpl(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ {
+ super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ this.id = id;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.PassivationCapable;
-
-public class PassivationCapableCustomBean<T> extends CustomBean<T> implements PassivationCapable
-{
- final String id;
-
- PassivationCapableCustomBean(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
- {
- super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
- this.id = id;
- }
-
- public String getId()
- {
- return id;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.bean;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.BeanManager;
-
-public class SimpleBeanLifecycle<T> implements BeanLifecycle<T>
-{
- final Class<T> type;
- final BeanManager beanManager;
-
- public SimpleBeanLifecycle(Class<T> type, BeanManager beanManager)
- {
- this.type = type;
- this.beanManager = beanManager;
- }
-
- public T create(CustomBean<T> bean, CreationalContext<T> creationalContext)
- {
- T instance = bean.getInjectionTarget().produce(creationalContext);
- bean.getInjectionTarget().inject(instance, creationalContext);
- bean.getInjectionTarget().postConstruct(instance);
- return instance;
- }
-
- public void destroy(CustomBean<T> bean, T instance, CreationalContext<T> creationalContext)
- {
- try
- {
- bean.getInjectionTarget().preDestroy(instance);
- creationalContext.release();
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
-}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -44,7 +44,7 @@
import javax.inject.Inject;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.bean.BeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
public class GenericExtension implements Extension
@@ -245,8 +245,8 @@
InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, conc);
- CustomBeanBuilder<X> beanBuilder = new CustomBeanBuilder<X>(newAnnotatedType, beanManager, it);
- return beanBuilder.build();
+ BeanBuilder<X> beanBuilder = new BeanBuilder<X>(newAnnotatedType, beanManager).defineBeanFromAnnotatedType().setInjectionTarget(it);
+ return beanBuilder.create();
}
public SyntheticQualifier getQualifierForGeneric(Annotation a)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 22:13:29 UTC (rev 6203)
@@ -43,7 +43,7 @@
import org.jboss.weld.extensions.annotated.MemberAnnotationRedefiner;
import org.jboss.weld.extensions.annotated.Parameter;
import org.jboss.weld.extensions.annotated.ParameterAnnotationRedefiner;
-import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.bean.BeanBuilder;
import org.jboss.weld.extensions.core.Exact.ExactLiteral;
/**
@@ -173,7 +173,7 @@
annotatedTypeBuilder.addToClass(ann);
}
AnnotatedType<X> construtsAnnotatedType = builder.create();
- additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType, beanManager).build());
+ additionalBeans.add(new BeanBuilder<X>(construtsAnnotatedType, beanManager).create());
}
}
}
14 years, 8 months
Weld SVN: r6202 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: annotated and 5 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 17:51:53 -0400 (Thu, 29 Apr 2010)
New Revision: 6202
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedCallableImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedConstructorImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedFieldImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMemberImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMethodImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedParameterImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationStore.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/MemberAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Parameter.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/ParameterAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeClosureBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/log/LoggerProducer.java
Log:
cleanup annotated
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated (from rev 6201, extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedCallableImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedCallableImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedCallableImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedConstructorImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedConstructorImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedConstructorImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedFieldImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedFieldImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedFieldImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMemberImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMemberImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMemberImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMethodImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMethodImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedMethodImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedParameterImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedParameterImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedParameterImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Type;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeImpl.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -0,0 +1,565 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Utilities for working with {@link Annotated}s.
+ *
+ * Includes utilities to check the equality of {@link Annotated} instances, and
+ * to create unique ids for {@link Annotated} instances.
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ */
+public class Annotateds
+{
+
+ /**
+ * Does the first stage of comparing AnnoatedCallables, however it cannot
+ * compare the method parameters
+ */
+ private static class AnnotatedCallableComparator<T> implements Comparator<AnnotatedCallable<? super T>>
+ {
+
+ public int compare(AnnotatedCallable<? super T> arg0, AnnotatedCallable<? super T> arg1)
+ {
+ // compare the names first
+ int result = (arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName()));
+ if (result != 0)
+ {
+ return result;
+ }
+ result = arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ result = arg0.getParameters().size() - arg1.getParameters().size();
+ return result;
+ }
+
+ }
+
+ private static class AnnotatedMethodComparator<T> implements Comparator<AnnotatedMethod<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedMethod<? super T>> instance()
+ {
+ return new AnnotatedMethodComparator<T>();
+ }
+
+ private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
+
+ public int compare(AnnotatedMethod<? super T> arg0, AnnotatedMethod<? super T> arg1)
+ {
+ int result = callableComparator.compare(arg0, arg1);
+ if (result != 0)
+ {
+ return result;
+ }
+ for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
+ {
+ Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
+ Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
+ result = p0.getName().compareTo(p1.getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ }
+ return 0;
+ }
+
+ }
+
+ private static class AnnotatedConstructorComparator<T> implements Comparator<AnnotatedConstructor<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedConstructor<? super T>> instance()
+ {
+ return new AnnotatedConstructorComparator<T>();
+ }
+
+ private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
+
+ public int compare(AnnotatedConstructor<? super T> arg0, AnnotatedConstructor<? super T> arg1)
+ {
+ int result = callableComparator.compare(arg0, arg1);
+ if (result != 0)
+ {
+ return result;
+ }
+ for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
+ {
+ Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
+ Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
+ result = p0.getName().compareTo(p1.getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ }
+ return 0;
+ }
+
+ }
+
+ private static class AnnotatedFieldComparator<T> implements Comparator<AnnotatedField<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedField<? super T>> instance()
+ {
+ return new AnnotatedFieldComparator<T>();
+ }
+
+ public int compare(AnnotatedField<? super T> arg0, AnnotatedField<? super T> arg1)
+ {
+ if (arg0.getJavaMember().getName().equals(arg1.getJavaMember().getName()))
+ {
+ return arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
+ }
+ return arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName());
+ }
+
+ }
+
+ private static class AnnotationComparator implements Comparator<Annotation>
+ {
+
+ public static final Comparator<Annotation> INSTANCE = new AnnotationComparator();
+
+ public int compare(Annotation arg0, Annotation arg1)
+ {
+ return arg0.annotationType().getName().compareTo(arg1.annotationType().getName());
+ }
+ }
+
+ private static class MethodComparator implements Comparator<Method>
+ {
+
+ public static final Comparator<Method> INSTANCE = new MethodComparator();
+
+ public int compare(Method arg0, Method arg1)
+ {
+ return arg0.getName().compareTo(arg1.getName());
+ }
+ }
+
+ private static final char SEPERATOR = ';';
+
+ /**
+ * Generates a unique signature for an annotated type. Members without
+ * annotations are omitted to reduce the length of the signature
+ *
+ * @param <X>
+ * @param annotatedType
+ * @return
+ */
+ public static <X> String createTypeId(AnnotatedType<X> annotatedType)
+ {
+ return createTypeId(annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors());
+ }
+
+ /**
+ * Generates a unique signature for a concrete class
+ *
+ * @param <X>
+ * @param annotatedType
+ * @return
+ */
+ public static <X> String createTypeId(Class<X> clazz, Collection<Annotation> annotations, Collection<AnnotatedMethod<? super X>> methods, Collection<AnnotatedField<? super X>> fields, Collection<AnnotatedConstructor<X>> constructors)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(clazz.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append("{");
+
+ // now deal with the fields
+ List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
+ sortedFields.addAll(fields);
+ Collections.sort(sortedFields, AnnotatedFieldComparator.<X> instance());
+ for (AnnotatedField<? super X> field : sortedFields)
+ {
+ if (!field.getAnnotations().isEmpty())
+ {
+ builder.append(createFieldId(field));
+ builder.append(SEPERATOR);
+ }
+ }
+
+ // methods
+ List<AnnotatedMethod<? super X>> sortedMethods = new ArrayList<AnnotatedMethod<? super X>>();
+ sortedMethods.addAll(methods);
+ Collections.sort(sortedMethods, AnnotatedMethodComparator.<X> instance());
+ for (AnnotatedMethod<? super X> method : sortedMethods)
+ {
+ if (!method.getAnnotations().isEmpty() || hasMethodParameters(method))
+ {
+ builder.append(createCallableId(method));
+ builder.append(SEPERATOR);
+ }
+ }
+
+ // constructors
+ List<AnnotatedConstructor<? super X>> sortedConstructors = new ArrayList<AnnotatedConstructor<? super X>>();
+ sortedConstructors.addAll(constructors);
+ Collections.sort(sortedConstructors, AnnotatedConstructorComparator.<X> instance());
+ for (AnnotatedConstructor<? super X> constructor : sortedConstructors)
+ {
+ if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor))
+ {
+ builder.append(createCallableId(constructor));
+ builder.append(SEPERATOR);
+ }
+ }
+ builder.append("}");
+
+ return builder.toString();
+ }
+
+ private static <X> boolean hasMethodParameters(AnnotatedCallable<X> callable)
+ {
+ for (AnnotatedParameter<X> parameter : callable.getParameters())
+ {
+ if (!parameter.getAnnotations().isEmpty())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String createAnnotationCollectionId(Collection<Annotation> annotations)
+ {
+ if (annotations.isEmpty())
+ {
+ return "";
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append('[');
+
+ List<Annotation> annotationList = new ArrayList<Annotation>(annotations.size());
+ annotationList.addAll(annotations);
+ Collections.sort(annotationList, AnnotationComparator.INSTANCE);
+
+ for (Annotation a : annotationList)
+ {
+ builder.append('@');
+ builder.append(a.annotationType().getName());
+ builder.append('(');
+ Method[] declaredMethods = a.annotationType().getDeclaredMethods();
+ List<Method> methods = new ArrayList<Method>(declaredMethods.length);
+ for (Method m : declaredMethods)
+ {
+ methods.add(m);
+ }
+ Collections.sort(methods, MethodComparator.INSTANCE);
+
+ for (int i = 0; i < methods.size(); ++i)
+ {
+ Method method = methods.get(i);
+ try
+ {
+ Object value = method.invoke(a);
+ builder.append(method.getName());
+ builder.append('=');
+ builder.append(value.toString());
+ }
+ catch (NullPointerException e)
+ {
+ throw new RuntimeException("NullPointerException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RuntimeException("IllegalArgumentException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException("IllegalAccessException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RuntimeException("InvocationTargetException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ if (i + 1 != methods.size())
+ {
+ builder.append(',');
+ }
+ }
+ builder.append(')');
+ }
+ builder.append(']');
+ return builder.toString();
+ }
+
+ public static <X> String createFieldId(AnnotatedField<X> field)
+ {
+ return createFieldId(field.getJavaMember(), field.getAnnotations());
+ }
+
+ public static <X> String createFieldId(Field field, Collection<Annotation> annotations)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(field.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(field.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ return builder.toString();
+ }
+
+ public static <X> String createCallableId(AnnotatedCallable<X> method)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(method.getJavaMember().getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(method.getJavaMember().getName());
+ builder.append(createAnnotationCollectionId(method.getAnnotations()));
+ builder.append(createParameterListId(method.getParameters()));
+ return builder.toString();
+ }
+
+ public static <X> String createMethodId(Method method, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(method.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(method.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append(createParameterListId(parameters));
+ return builder.toString();
+ }
+
+ public static <X> String createConstructorId(Constructor<X> constructor, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(constructor.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(constructor.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append(createParameterListId(parameters));
+ return builder.toString();
+ }
+
+ public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("(");
+ for (int i = 0; i < parameters.size(); ++i)
+ {
+ AnnotatedParameter<X> ap = parameters.get(i);
+ builder.append(createParameterId(ap));
+ if (i + 1 != parameters.size())
+ {
+ builder.append(',');
+ }
+ }
+ builder.append(")");
+ return builder.toString();
+ }
+
+ public static <X> String createParameterId(AnnotatedParameter<X> annotatedParameter)
+ {
+ return createParameterId(annotatedParameter.getBaseType(), annotatedParameter.getAnnotations());
+ }
+
+ public static <X> String createParameterId(Type type, Set<Annotation> annotations)
+ {
+ StringBuilder builder = new StringBuilder();
+ if (type instanceof Class<?>)
+ {
+ Class<?> c = (Class<?>) type;
+ builder.append(c.getName());
+ }
+ else
+ {
+ builder.append(type.toString());
+ }
+ builder.append(createAnnotationCollectionId(annotations));
+ return builder.toString();
+ }
+
+ /**
+ * compares two annotated elemetes to see if they have the same annotations
+ *
+ * @param a1
+ * @param a2
+ * @return
+ */
+ private static boolean compareAnnotated(Annotated a1, Annotated a2)
+ {
+ return a1.getAnnotations().equals(a2.getAnnotations());
+ }
+
+ /**
+ * compares two annotated elements to see if they have the same annotations
+ *
+ */
+ private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1, List<? extends AnnotatedParameter<?>> p2)
+ {
+ if (p1.size() != p2.size())
+ {
+ return false;
+ }
+ for (int i = 0; i < p1.size(); ++i)
+ {
+ if (!compareAnnotated(p1.get(i), p2.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
+ {
+ if (!f1.getJavaMember().equals(f2.getJavaMember()))
+ {
+ return false;
+ }
+ return compareAnnotated(f1, f2);
+ }
+
+ public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
+ {
+ if (!m1.getJavaMember().equals(m2.getJavaMember()))
+ {
+ return false;
+ }
+ if (!compareAnnotated(m1, m2))
+ {
+ return false;
+ }
+ return compareAnnotatedParameters(m1.getParameters(), m2.getParameters());
+ }
+
+ /**
+ * Compares two annotated types and returns true if they are the same
+ */
+ public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2)
+ {
+ if (!t1.getJavaClass().equals(t2.getJavaClass()))
+ {
+ return false;
+ }
+ if (!compareAnnotated(t1, t2))
+ {
+ return false;
+ }
+
+ if (t1.getFields().size() != t2.getFields().size())
+ {
+ return false;
+ }
+ Map<Field, AnnotatedField<?>> fields = new HashMap<Field, AnnotatedField<?>>();
+ for (AnnotatedField<?> f : t2.getFields())
+ {
+ fields.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedField<?> f : t1.getFields())
+ {
+ if (fields.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedField(f, fields.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ if (t1.getMethods().size() != t2.getMethods().size())
+ {
+ return false;
+ }
+ Map<Method, AnnotatedMethod<?>> methods = new HashMap<Method, AnnotatedMethod<?>>();
+ for (AnnotatedMethod<?> f : t2.getMethods())
+ {
+ methods.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedMethod<?> f : t1.getMethods())
+ {
+ if (methods.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedCallable(f, methods.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ if (t1.getConstructors().size() != t2.getConstructors().size())
+ {
+ return false;
+ }
+ Map<Constructor<?>, AnnotatedConstructor<?>> constructors = new HashMap<Constructor<?>, AnnotatedConstructor<?>>();
+ for (AnnotatedConstructor<?> f : t2.getConstructors())
+ {
+ constructors.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedConstructor<?> f : t1.getConstructors())
+ {
+ if (constructors.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ private Annotateds()
+ {
+ }
+
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationBuilder.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationRedefiner.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationStore.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotationStore.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
import java.util.Collections;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/MemberAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/MemberAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/MemberAnnotationRedefiner.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Parameter.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/Parameter.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Parameter.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Member;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/ParameterAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/ParameterAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/ParameterAnnotationRedefiner.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeAnnotationRedefiner.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -1,4 +1,4 @@
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.annotation.Annotation;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeClosureBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/TypeClosureBuilder.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.weld.extensions.annotatedType;
+package org.jboss.weld.extensions.annotated;
import java.lang.reflect.Type;
import java.util.HashSet;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -29,7 +29,7 @@
import javax.enterprise.inject.spi.InjectionTarget;
import javax.inject.Named;
-import org.jboss.weld.extensions.util.AnnotatedTypeUtils;
+import org.jboss.weld.extensions.annotated.Annotateds;
/**
* class that can build a bean from an AnnotatedType.
@@ -107,7 +107,7 @@
types.add(i);
}
beanLifecycle = new SimpleBeanLifecycle<T>(type.getJavaClass(), beanManager);
- id = CustomBean.class.getName() + ":" + AnnotatedTypeUtils.createTypeId(type);
+ id = CustomBean.class.getName() + ":" + Annotateds.createTypeId(type);
}
public Bean<T> build()
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -43,7 +43,7 @@
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.inject.Inject;
-import org.jboss.weld.extensions.annotatedType.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -38,11 +38,11 @@
import javax.inject.Named;
import javax.inject.Qualifier;
-import org.jboss.weld.extensions.annotatedType.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.annotatedType.AnnotationBuilder;
-import org.jboss.weld.extensions.annotatedType.MemberAnnotationRedefiner;
-import org.jboss.weld.extensions.annotatedType.Parameter;
-import org.jboss.weld.extensions.annotatedType.ParameterAnnotationRedefiner;
+import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.annotated.AnnotationBuilder;
+import org.jboss.weld.extensions.annotated.MemberAnnotationRedefiner;
+import org.jboss.weld.extensions.annotated.Parameter;
+import org.jboss.weld.extensions.annotated.ParameterAnnotationRedefiner;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.core.Exact.ExactLiteral;
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/log/LoggerProducer.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/log/LoggerProducer.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/log/LoggerProducer.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -32,7 +32,7 @@
* @author David Allen
*
*/
-public class LoggerProducer
+class LoggerProducer
{
@Produces
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java 2010-04-29 21:41:13 UTC (rev 6201)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java 2010-04-29 21:51:53 UTC (rev 6202)
@@ -1,564 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedCallable;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- * Class that can take an AnnotatedType and return a unique string
- * representation of that type
- *
- * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
- */
-public class AnnotatedTypeUtils
-{
-
- /**
- * Does the first stage of comparing AnnoatedCallables, however it cannot
- * compare the method parameters
- */
- private static class AnnotatedCallableComparator<T> implements Comparator<AnnotatedCallable<? super T>>
- {
-
- public int compare(AnnotatedCallable<? super T> arg0, AnnotatedCallable<? super T> arg1)
- {
- // compare the names first
- int result = (arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName()));
- if (result != 0)
- {
- return result;
- }
- result = arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
- if (result != 0)
- {
- return result;
- }
- result = arg0.getParameters().size() - arg1.getParameters().size();
- return result;
- }
-
- }
-
- private static class AnnotatedMethodComparator<T> implements Comparator<AnnotatedMethod<? super T>>
- {
-
- public static <T> Comparator<AnnotatedMethod<? super T>> instance()
- {
- return new AnnotatedMethodComparator<T>();
- }
-
- private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
-
- public int compare(AnnotatedMethod<? super T> arg0, AnnotatedMethod<? super T> arg1)
- {
- int result = callableComparator.compare(arg0, arg1);
- if (result != 0)
- {
- return result;
- }
- for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
- {
- Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
- Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
- result = p0.getName().compareTo(p1.getName());
- if (result != 0)
- {
- return result;
- }
- }
- return 0;
- }
-
- }
-
- private static class AnnotatedConstructorComparator<T> implements Comparator<AnnotatedConstructor<? super T>>
- {
-
- public static <T> Comparator<AnnotatedConstructor<? super T>> instance()
- {
- return new AnnotatedConstructorComparator<T>();
- }
-
- private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
-
- public int compare(AnnotatedConstructor<? super T> arg0, AnnotatedConstructor<? super T> arg1)
- {
- int result = callableComparator.compare(arg0, arg1);
- if (result != 0)
- {
- return result;
- }
- for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
- {
- Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
- Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
- result = p0.getName().compareTo(p1.getName());
- if (result != 0)
- {
- return result;
- }
- }
- return 0;
- }
-
- }
-
- private static class AnnotatedFieldComparator<T> implements Comparator<AnnotatedField<? super T>>
- {
-
- public static <T> Comparator<AnnotatedField<? super T>> instance()
- {
- return new AnnotatedFieldComparator<T>();
- }
-
- public int compare(AnnotatedField<? super T> arg0, AnnotatedField<? super T> arg1)
- {
- if (arg0.getJavaMember().getName().equals(arg1.getJavaMember().getName()))
- {
- return arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
- }
- return arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName());
- }
-
- }
-
- private static class AnnotationComparator implements Comparator<Annotation>
- {
-
- public static final Comparator<Annotation> INSTANCE = new AnnotationComparator();
-
- public int compare(Annotation arg0, Annotation arg1)
- {
- return arg0.annotationType().getName().compareTo(arg1.annotationType().getName());
- }
- }
-
- private static class MethodComparator implements Comparator<Method>
- {
-
- public static final Comparator<Method> INSTANCE = new MethodComparator();
-
- public int compare(Method arg0, Method arg1)
- {
- return arg0.getName().compareTo(arg1.getName());
- }
- }
-
- private static final char SEPERATOR = ';';
-
- /**
- * Generates a unique signature for an annotated type. Members without
- * annotations are omitted to reduce the length of the signature
- *
- * @param <X>
- * @param annotatedType
- * @return
- */
- public static <X> String createTypeId(AnnotatedType<X> annotatedType)
- {
- return createTypeId(annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors());
- }
-
- /**
- * Generates a unique signature for a concrete class
- *
- * @param <X>
- * @param annotatedType
- * @return
- */
- public static <X> String createTypeId(Class<X> clazz, Collection<Annotation> annotations, Collection<AnnotatedMethod<? super X>> methods, Collection<AnnotatedField<? super X>> fields, Collection<AnnotatedConstructor<X>> constructors)
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append(clazz.getName());
- builder.append(createAnnotationCollectionId(annotations));
- builder.append("{");
-
- // now deal with the fields
- List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
- sortedFields.addAll(fields);
- Collections.sort(sortedFields, AnnotatedFieldComparator.<X> instance());
- for (AnnotatedField<? super X> field : sortedFields)
- {
- if (!field.getAnnotations().isEmpty())
- {
- builder.append(createFieldId(field));
- builder.append(SEPERATOR);
- }
- }
-
- // methods
- List<AnnotatedMethod<? super X>> sortedMethods = new ArrayList<AnnotatedMethod<? super X>>();
- sortedMethods.addAll(methods);
- Collections.sort(sortedMethods, AnnotatedMethodComparator.<X> instance());
- for (AnnotatedMethod<? super X> method : sortedMethods)
- {
- if (!method.getAnnotations().isEmpty() || hasMethodParameters(method))
- {
- builder.append(createCallableId(method));
- builder.append(SEPERATOR);
- }
- }
-
- // constructors
- List<AnnotatedConstructor<? super X>> sortedConstructors = new ArrayList<AnnotatedConstructor<? super X>>();
- sortedConstructors.addAll(constructors);
- Collections.sort(sortedConstructors, AnnotatedConstructorComparator.<X> instance());
- for (AnnotatedConstructor<? super X> constructor : sortedConstructors)
- {
- if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor))
- {
- builder.append(createCallableId(constructor));
- builder.append(SEPERATOR);
- }
- }
- builder.append("}");
-
- return builder.toString();
- }
-
- private static <X> boolean hasMethodParameters(AnnotatedCallable<X> callable)
- {
- for (AnnotatedParameter<X> parameter : callable.getParameters())
- {
- if (!parameter.getAnnotations().isEmpty())
- {
- return true;
- }
- }
- return false;
- }
-
- private static String createAnnotationCollectionId(Collection<Annotation> annotations)
- {
- if (annotations.isEmpty())
- {
- return "";
- }
-
- StringBuilder builder = new StringBuilder();
- builder.append('[');
-
- List<Annotation> annotationList = new ArrayList<Annotation>(annotations.size());
- annotationList.addAll(annotations);
- Collections.sort(annotationList, AnnotationComparator.INSTANCE);
-
- for (Annotation a : annotationList)
- {
- builder.append('@');
- builder.append(a.annotationType().getName());
- builder.append('(');
- Method[] declaredMethods = a.annotationType().getDeclaredMethods();
- List<Method> methods = new ArrayList<Method>(declaredMethods.length);
- for (Method m : declaredMethods)
- {
- methods.add(m);
- }
- Collections.sort(methods, MethodComparator.INSTANCE);
-
- for (int i = 0; i < methods.size(); ++i)
- {
- Method method = methods.get(i);
- try
- {
- Object value = method.invoke(a);
- builder.append(method.getName());
- builder.append('=');
- builder.append(value.toString());
- }
- catch (NullPointerException e)
- {
- throw new RuntimeException("NullPointerException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
- }
- catch (IllegalArgumentException e)
- {
- throw new RuntimeException("IllegalArgumentException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException("IllegalAccessException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new RuntimeException("InvocationTargetException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
- }
- if (i + 1 != methods.size())
- {
- builder.append(',');
- }
- }
- builder.append(')');
- }
- builder.append(']');
- return builder.toString();
- }
-
- public static <X> String createFieldId(AnnotatedField<X> field)
- {
- return createFieldId(field.getJavaMember(), field.getAnnotations());
- }
-
- public static <X> String createFieldId(Field field, Collection<Annotation> annotations)
- {
- StringBuilder builder = new StringBuilder();
- builder.append(field.getDeclaringClass().getName());
- builder.append('.');
- builder.append(field.getName());
- builder.append(createAnnotationCollectionId(annotations));
- return builder.toString();
- }
-
- public static <X> String createCallableId(AnnotatedCallable<X> method)
- {
- StringBuilder builder = new StringBuilder();
- builder.append(method.getJavaMember().getDeclaringClass().getName());
- builder.append('.');
- builder.append(method.getJavaMember().getName());
- builder.append(createAnnotationCollectionId(method.getAnnotations()));
- builder.append(createParameterListId(method.getParameters()));
- return builder.toString();
- }
-
- public static <X> String createMethodId(Method method, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
- {
- StringBuilder builder = new StringBuilder();
- builder.append(method.getDeclaringClass().getName());
- builder.append('.');
- builder.append(method.getName());
- builder.append(createAnnotationCollectionId(annotations));
- builder.append(createParameterListId(parameters));
- return builder.toString();
- }
-
- public static <X> String createConstructorId(Constructor<X> constructor, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
- {
- StringBuilder builder = new StringBuilder();
- builder.append(constructor.getDeclaringClass().getName());
- builder.append('.');
- builder.append(constructor.getName());
- builder.append(createAnnotationCollectionId(annotations));
- builder.append(createParameterListId(parameters));
- return builder.toString();
- }
-
- public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters)
- {
- StringBuilder builder = new StringBuilder();
- builder.append("(");
- for (int i = 0; i < parameters.size(); ++i)
- {
- AnnotatedParameter<X> ap = parameters.get(i);
- builder.append(createParameterId(ap));
- if (i + 1 != parameters.size())
- {
- builder.append(',');
- }
- }
- builder.append(")");
- return builder.toString();
- }
-
- public static <X> String createParameterId(AnnotatedParameter<X> annotatedParameter)
- {
- return createParameterId(annotatedParameter.getBaseType(), annotatedParameter.getAnnotations());
- }
-
- public static <X> String createParameterId(Type type, Set<Annotation> annotations)
- {
- StringBuilder builder = new StringBuilder();
- if (type instanceof Class<?>)
- {
- Class<?> c = (Class<?>) type;
- builder.append(c.getName());
- }
- else
- {
- builder.append(type.toString());
- }
- builder.append(createAnnotationCollectionId(annotations));
- return builder.toString();
- }
-
- /**
- * compares two annotated elemetes to see if they have the same annotations
- *
- * @param a1
- * @param a2
- * @return
- */
- private static boolean compareAnnotated(Annotated a1, Annotated a2)
- {
- return a1.getAnnotations().equals(a2.getAnnotations());
- }
-
- /**
- * compares two annotated elements to see if they have the same annotations
- *
- */
- private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1, List<? extends AnnotatedParameter<?>> p2)
- {
- if (p1.size() != p2.size())
- {
- return false;
- }
- for (int i = 0; i < p1.size(); ++i)
- {
- if (!compareAnnotated(p1.get(i), p2.get(i)))
- {
- return false;
- }
- }
- return true;
- }
-
- public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
- {
- if (!f1.getJavaMember().equals(f2.getJavaMember()))
- {
- return false;
- }
- return compareAnnotated(f1, f2);
- }
-
- public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
- {
- if (!m1.getJavaMember().equals(m2.getJavaMember()))
- {
- return false;
- }
- if(!compareAnnotated(m1, m2))
- {
- return false;
- }
- return compareAnnotatedParameters(m1.getParameters(), m2.getParameters());
- }
-
- /**
- * Compares two annotated types and returns true if they are the same
- */
- public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2)
- {
- if (!t1.getJavaClass().equals(t2.getJavaClass()))
- {
- return false;
- }
- if (!compareAnnotated(t1, t2))
- {
- return false;
- }
-
- if (t1.getFields().size() != t2.getFields().size())
- {
- return false;
- }
- Map<Field, AnnotatedField<?>> fields = new HashMap<Field, AnnotatedField<?>>();
- for (AnnotatedField<?> f : t2.getFields())
- {
- fields.put(f.getJavaMember(), f);
- }
- for (AnnotatedField<?> f : t1.getFields())
- {
- if (fields.containsKey(f.getJavaMember()))
- {
- if (!compareAnnotatedField(f, fields.get(f.getJavaMember())))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
-
- if (t1.getMethods().size() != t2.getMethods().size())
- {
- return false;
- }
- Map<Method, AnnotatedMethod<?>> methods = new HashMap<Method, AnnotatedMethod<?>>();
- for (AnnotatedMethod<?> f : t2.getMethods())
- {
- methods.put(f.getJavaMember(), f);
- }
- for (AnnotatedMethod<?> f : t1.getMethods())
- {
- if (methods.containsKey(f.getJavaMember()))
- {
- if (!compareAnnotatedCallable(f, methods.get(f.getJavaMember())))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- if (t1.getConstructors().size() != t2.getConstructors().size())
- {
- return false;
- }
- Map<Constructor<?>, AnnotatedConstructor<?>> constructors = new HashMap<Constructor<?>, AnnotatedConstructor<?>>();
- for (AnnotatedConstructor<?> f : t2.getConstructors())
- {
- constructors.put(f.getJavaMember(), f);
- }
- for (AnnotatedConstructor<?> f : t1.getConstructors())
- {
- if (constructors.containsKey(f.getJavaMember()))
- {
- if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember())))
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- return true;
-
- }
-
-
- private AnnotatedTypeUtils()
- {
- }
-
-}
14 years, 8 months
Weld SVN: r6201 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: annotatedType and 3 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 17:41:13 -0400 (Thu, 29 Apr 2010)
New Revision: 6201
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedCallableImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedConstructorImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedFieldImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMemberImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMethodImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedParameterImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/MemberAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/Parameter.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/ParameterAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedCallable.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedElement.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedMember.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedConstructor.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedField.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedMethod.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedParameter.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedType.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
Log:
cleanup annotated
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated)
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedCallable.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedCallable.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.enterprise.inject.spi.AnnotatedCallable;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedCallable<X, Y extends Member> extends AbstractNewAnnotatedMember<X, Y> implements AnnotatedCallable<X>
-{
-
- private final List<AnnotatedParameter<X>> parameters;
-
- protected AbstractNewAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType, Map<Integer, Type> parameterTypeOverrides)
- {
- super(declaringType, member, memberType, annotations, genericType, null);
- this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, parameterTypeOverrides);
- }
-
- public List<AnnotatedParameter<X>> getParameters()
- {
- return Collections.unmodifiableList(parameters);
- }
-
- public AnnotatedParameter<X> getParameter(int index)
- {
- return parameters.get(index);
-
- }
-
- private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractNewAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
- {
- List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
- int len = parameterTypes.length;
- for (int i = 0; i < len; ++i)
- {
- AnnotationBuilder builder = new AnnotationBuilder();
- if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
- {
- builder.addAll(parameterAnnotations.get(i));
- }
- Type over = null;
- if (parameterTypeOverrides != null)
- {
- over = parameterTypeOverrides.get(i);
- }
- NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
- parameters.add(p);
- }
- return parameters;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedElement.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedElement.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Annotated;
-
-/**
- * The base class for all New Annotated types.
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedElement implements Annotated
-{
-
- private final Type type;
- private final Set<Type> typeClosure;
- private final AnnotationStore annotations;
-
- protected AbstractNewAnnotatedElement(Class<?> type, AnnotationStore annotations, Type genericType, Type overridenType)
- {
-
- if (overridenType == null)
- {
- this.typeClosure = new TypeClosureBuilder().add(type).getTypes();
- if (genericType != null)
- {
- typeClosure.add(genericType);
- this.type = genericType;
- }
- else
- {
- this.type = type;
- }
- }
- else
- {
- this.type = overridenType;
- this.typeClosure = Collections.singleton(overridenType);
- }
-
-
- if (annotations == null)
- {
- this.annotations = new AnnotationStore();
- }
- else
- {
- this.annotations = annotations;
- }
- }
-
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
- {
- return annotations.getAnnotation(annotationType);
- }
-
- public Set<Annotation> getAnnotations()
- {
- return annotations.getAnnotations();
- }
-
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
- {
- return annotations.isAnnotationPresent(annotationType);
- }
-
- public Set<Type> getTypeClosure()
- {
- return new HashSet<Type>(typeClosure);
- }
-
- public Type getBaseType()
- {
- return type;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedMember.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AbstractNewAnnotatedMember.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedMember;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedMember<X, M extends Member> extends AbstractNewAnnotatedElement implements AnnotatedMember<X>
-{
- private final AnnotatedType<X> declaringType;
- private final M javaMember;
-
- protected AbstractNewAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, AnnotationStore annotations, Type genericType, Type overridenType)
- {
- super(memberType, annotations, genericType, overridenType);
- this.declaringType = declaringType;
- this.javaMember = member;
- }
-
- public AnnotatedType<X> getDeclaringType()
- {
- return declaringType;
- }
-
- public M getJavaMember()
- {
- return javaMember;
- }
-
- public boolean isStatic()
- {
- return Modifier.isStatic(javaMember.getModifiers());
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedCallableImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedCallableImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedCallableImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedCallableImpl<X, Y extends Member> extends AnnotatedMemberImpl<X, Y> implements AnnotatedCallable<X>
+{
+
+ private final List<AnnotatedParameter<X>> parameters;
+
+ protected AnnotatedCallableImpl(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType, Map<Integer, Type> parameterTypeOverrides)
+ {
+ super(declaringType, member, memberType, annotations, genericType, null);
+ this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, parameterTypeOverrides);
+ }
+
+ public List<AnnotatedParameter<X>> getParameters()
+ {
+ return Collections.unmodifiableList(parameters);
+ }
+
+ public AnnotatedParameter<X> getParameter(int index)
+ {
+ return parameters.get(index);
+
+ }
+
+ private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+ {
+ List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+ int len = parameterTypes.length;
+ for (int i = 0; i < len; ++i)
+ {
+ AnnotationBuilder builder = new AnnotationBuilder();
+ if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+ {
+ builder.addAll(parameterAnnotations.get(i));
+ }
+ Type over = null;
+ if (parameterTypeOverrides != null)
+ {
+ over = parameterTypeOverrides.get(i);
+ }
+ AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
+ parameters.add(p);
+ }
+ return parameters;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedConstructorImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedConstructorImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedConstructorImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedConstructorImpl<X> extends AnnotatedCallableImpl<X, Constructor<X>> implements AnnotatedConstructor<X>
+{
+
+ AnnotatedConstructorImpl(AnnotatedTypeImpl<X> type, Constructor<?> constructor, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> typeOverrides)
+ {
+
+ super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides);
+ }
+
+ private static Type[] getGenericArray(Constructor<?> constructor)
+ {
+ Type[] genericTypes = constructor.getGenericParameterTypes();
+ // for inner classes genericTypes and parameterTypes can be different
+ // length, this is a hack to fix this.
+ // TODO: investigate this behavior further, on different JVM's and
+ // compilers
+ if (genericTypes.length + 1 == constructor.getParameterTypes().length)
+ {
+ genericTypes = new Type[constructor.getGenericParameterTypes().length + 1];
+ genericTypes[0] = constructor.getParameterTypes()[0];
+ for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i)
+ {
+ genericTypes[i + 1] = constructor.getGenericParameterTypes()[i];
+ }
+ }
+ return genericTypes;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedFieldImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedFieldImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedFieldImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedFieldImpl<X> extends AnnotatedMemberImpl<X, Field> implements AnnotatedField<X>
+{
+
+ AnnotatedFieldImpl(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations, Type overridenType)
+ {
+ super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType);
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+
+/**
+ * The base class for all New Annotated types.
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedImpl implements Annotated
+{
+
+ private final Type type;
+ private final Set<Type> typeClosure;
+ private final AnnotationStore annotations;
+
+ protected AnnotatedImpl(Class<?> type, AnnotationStore annotations, Type genericType, Type overridenType)
+ {
+
+ if (overridenType == null)
+ {
+ this.typeClosure = new TypeClosureBuilder().add(type).getTypes();
+ if (genericType != null)
+ {
+ typeClosure.add(genericType);
+ this.type = genericType;
+ }
+ else
+ {
+ this.type = type;
+ }
+ }
+ else
+ {
+ this.type = overridenType;
+ this.typeClosure = Collections.singleton(overridenType);
+ }
+
+
+ if (annotations == null)
+ {
+ this.annotations = new AnnotationStore();
+ }
+ else
+ {
+ this.annotations = annotations;
+ }
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return annotations.getAnnotation(annotationType);
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return annotations.getAnnotations();
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return annotations.isAnnotationPresent(annotationType);
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return new HashSet<Type>(typeClosure);
+ }
+
+ public Type getBaseType()
+ {
+ return type;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMemberImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMemberImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMemberImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedMemberImpl<X, M extends Member> extends AnnotatedImpl implements AnnotatedMember<X>
+{
+ private final AnnotatedType<X> declaringType;
+ private final M javaMember;
+
+ protected AnnotatedMemberImpl(AnnotatedType<X> declaringType, M member, Class<?> memberType, AnnotationStore annotations, Type genericType, Type overridenType)
+ {
+ super(memberType, annotations, genericType, overridenType);
+ this.declaringType = declaringType;
+ this.javaMember = member;
+ }
+
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return declaringType;
+ }
+
+ public M getJavaMember()
+ {
+ return javaMember;
+ }
+
+ public boolean isStatic()
+ {
+ return Modifier.isStatic(javaMember.getModifiers());
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMethodImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMethodImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedMethodImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedMethodImpl<X> extends AnnotatedCallableImpl<X, Method> implements AnnotatedMethod<X>
+{
+ AnnotatedMethodImpl(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+ {
+ super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedParameterImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedParameterImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedParameterImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedParameterImpl<X> extends AnnotatedImpl implements AnnotatedParameter<X>
+{
+
+ private final int position;
+ private final AnnotatedCallable<X> declaringCallable;
+
+ AnnotatedParameterImpl(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations, Type genericType, Type typeOverride)
+ {
+ super(type, annotations, genericType, typeOverride);
+ this.declaringCallable = declaringCallable;
+ this.position = position;
+ }
+
+ public AnnotatedCallable<X> getDeclaringCallable()
+ {
+ return declaringCallable;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeBuilder.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeBuilder.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,525 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+import org.jboss.weld.extensions.util.ReflectionUtils;
+
+/**
+ * Class for constructing a new AnnotatedType. A new instance of builder must be
+ * used for each annotated type.
+ *
+ * In can either be created with no annotations, or the annotations can be read
+ * from the underlying class or an AnnotatedType
+ *
+ * @author Stuart Douglas
+ * @author Pete Muir
+ *
+ */
+public class AnnotatedTypeBuilder<X>
+{
+
+
+ public static <X> AnnotatedTypeBuilder<X> newInstance(Class<X> underlying)
+ {
+ return new AnnotatedTypeBuilder<X>(underlying);
+ }
+
+ public static <X> AnnotatedTypeBuilder<X> newInstance(AnnotatedType<X> underlying)
+ {
+ return new AnnotatedTypeBuilder<X>(underlying);
+ }
+
+ private final Class<X> underlyingType;
+ private final AnnotationBuilder typeAnnotations;
+
+ private final Map<Constructor<?>, AnnotationBuilder> constructors;
+ private final Map<Constructor<?>, Map<Integer, AnnotationBuilder>> constructorParameters;
+ private Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes;
+
+ private final Map<Field, AnnotationBuilder> fields;
+ private final Map<Field, Type> fieldTypes;
+
+ private final Map<Method, AnnotationBuilder> methods;
+ private final Map<Method, Map<Integer, AnnotationBuilder>> methodParameters;
+ private final Map<Method, Map<Integer, Type>> methodParameterTypes;
+
+ protected AnnotatedTypeBuilder(Class<X> underlyingType)
+ {
+ this.underlyingType = underlyingType;
+ this.typeAnnotations = new AnnotationBuilder();
+ this.constructors = new HashMap<Constructor<?>, AnnotationBuilder>();
+ this.constructorParameters = new HashMap<Constructor<?>, Map<Integer,AnnotationBuilder>>();
+ this.constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer,Type>>();
+ this.fields = new HashMap<Field, AnnotationBuilder>();
+ this.fieldTypes = new HashMap<Field, Type>();
+ this.methods = new HashMap<Method, AnnotationBuilder>();
+ this.methodParameters = new HashMap<Method, Map<Integer,AnnotationBuilder>>();
+ this.methodParameterTypes = new HashMap<Method, Map<Integer,Type>>();
+ }
+
+ protected AnnotatedTypeBuilder(AnnotatedType<X> underlyingType)
+ {
+ this(underlyingType.getJavaClass());
+
+ }
+
+ public AnnotatedTypeBuilder<X> readAnnotationsFromUnderlyingType()
+ {
+ for (Annotation annotation : underlyingType.getAnnotations())
+ {
+ typeAnnotations.add(annotation);
+ }
+
+ for (Field field : ReflectionUtils.getFields(underlyingType))
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ fields.put(field, annotationBuilder);
+ field.setAccessible(true);
+ for (Annotation annotation : field.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ }
+
+ for (Method method : ReflectionUtils.getMethods(underlyingType))
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ method.setAccessible(true);
+ methods.put(method, annotationBuilder);
+ for (Annotation annotation : method.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ Map<Integer, AnnotationBuilder> parameters = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(method, parameters);
+ for (int i = 0; i < method.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
+ parameters.put(i, parameterAnnotationBuilder);
+ for (Annotation annotation : method.getParameterAnnotations()[i])
+ {
+ parameterAnnotationBuilder.add(annotation);
+ }
+ }
+ }
+
+ for (Constructor<?> constructor : underlyingType.getDeclaredConstructors())
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ constructor.setAccessible(true);
+ constructors.put(constructor, annotationBuilder);
+ for (Annotation annotation : constructor.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put(constructor, mparams);
+ for (int i = 0; i < constructor.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
+ mparams.put(i, parameterAnnotationBuilder);
+ for (Annotation annotation : constructor.getParameterAnnotations()[i])
+ {
+ parameterAnnotationBuilder.add(annotation);
+ }
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToClass(Annotation annotation)
+ {
+ typeAnnotations.add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotation)
+ {
+ typeAnnotations.remove(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToField(Field field, Annotation annotation)
+ {
+ if (fields.get(field) == null)
+ {
+ fields.put(field, new AnnotationBuilder());
+ }
+ fields.get(field).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> annotation)
+ {
+ if (fields.get(field) != null)
+ {
+ fields.get(field).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToMethod(Method method, Annotation annotation)
+ {
+ if (methods.get(method) == null)
+ {
+ methods.put(method, new AnnotationBuilder());
+ }
+ methods.get(method).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> annotation)
+ {
+ if (methods.get(method) != null)
+ {
+ methods.get(method).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToMethodParameter(Method method, int position, Annotation annotation)
+ {
+ if (!methods.containsKey(method))
+ {
+ methods.put(method, new AnnotationBuilder());
+ }
+ if (methodParameters.get(method) == null)
+ {
+ methodParameters.put(method, new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (methodParameters.get(method).get(position) == null)
+ {
+ methodParameters.get(method).put(position, new AnnotationBuilder());
+ }
+ methodParameters.get(method).get(position).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromMethodParameter(Method method, int position, Class<? extends Annotation> annotation)
+ {
+ if (methodParameters.get(method) != null)
+ {
+ if (methodParameters.get(method).get(position) != null)
+ {
+ methodParameters.get(method).get(position).remove(annotation);
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation annotation)
+ {
+ if (constructors.get(constructor) == null)
+ {
+ constructors.put(constructor, new AnnotationBuilder());
+ }
+ constructors.get(constructor).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromConstructor(Constructor<?> constructor, Class<? extends Annotation> annotation)
+ {
+ if (constructors.get(constructor) != null)
+ {
+ constructors.get(constructor).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int position, Annotation annotation)
+ {
+ if (!constructors.containsKey(constructor))
+ {
+ constructors.put(constructor, new AnnotationBuilder());
+ }
+ if (constructorParameters.get(constructor) == null)
+ {
+ constructorParameters.put(constructor, new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (constructorParameters.get(constructor).get(position) == null)
+ {
+ constructorParameters.get(constructor).put(position, new AnnotationBuilder());
+ }
+ constructorParameters.get(constructor).get(position).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int position, Class<? extends Annotation> annotation)
+ {
+ if (constructorParameters.get(constructor) != null)
+ {
+ if (constructorParameters.get(constructor).get(position) != null)
+ {
+ constructorParameters.get(constructor).get(position).remove(annotation);
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> annotation)
+ {
+ removeFromClass(annotation);
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ field.getValue().remove(annotation);
+ }
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ method.getValue().remove(annotation);
+ if (methodParameters.get(method.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : methodParameters.get(method.getKey()).entrySet())
+ {
+ parameter.getValue().remove(annotation);
+ }
+ }
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ constructor.getValue().remove(annotation);
+ if (constructorParameters.get(constructor.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : constructorParameters.get(constructor.getKey()).entrySet())
+ {
+ parameter.getValue().remove(annotation);
+ }
+ }
+ }
+ return this;
+ }
+
+ public <T extends Annotation> AnnotatedTypeBuilder<X> redefineMemberParameters(Class<T> annotationType, ParameterAnnotationRedefiner<T> redefinition)
+ {
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ if (methodParameters.get(method.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : methodParameters.get(method.getKey()).entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(method.getKey(), parameter.getKey()), parameter.getValue());
+ }
+ }
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ if (constructorParameters.get(constructor.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : constructorParameters.get(constructor.getKey()).entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(constructor.getKey(), parameter.getKey()), parameter.getValue());
+ }
+ }
+ }
+ return this;
+ }
+
+ public <T extends Annotation> AnnotatedTypeBuilder<X> redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T> redefinition)
+ {
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, field.getKey(), field.getValue());
+ }
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, method.getKey(), method.getValue());
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, constructor.getKey(), constructor.getValue());
+ }
+ return this;
+ }
+
+ protected <T extends Annotation, A> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T, A> redefinition, A annotated, AnnotationBuilder builder)
+ {
+ if (builder.isAnnotationPresent(annotationType))
+ {
+ builder.remove(annotationType);
+ T redefinedAnnotation = redefinition.redefine(builder.getAnnotation(annotationType), annotated, builder);
+ if (redefinedAnnotation != null)
+ {
+ builder.add(redefinedAnnotation);
+ }
+ }
+ }
+
+ /**
+ * merges the annotations from an existing AnnotatedType. If they both have
+ * the same annotation on an element overwriteExisting determines which one
+ * to keep
+ *
+ * @param type
+ * @param overwriteExisting
+ * @return
+ */
+ public AnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
+ {
+ mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
+ for (AnnotatedField<? super X> field : type.getFields())
+ {
+ if (fields.get(field.getJavaMember()) == null)
+ {
+ fields.put(field.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(field, overwriteExisting, fields.get(field.getJavaMember()));
+ }
+ for (AnnotatedMethod<? super X> method : type.getMethods())
+ {
+ if (methods.get(method.getJavaMember()) == null)
+ {
+ methods.put(method.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(method, overwriteExisting, methods.get(method.getJavaMember()));
+ for (AnnotatedParameter<? super X> p : method.getParameters())
+ {
+ if (methodParameters.get(method.getJavaMember()) == null)
+ {
+ methodParameters.put(method.getJavaMember(), new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (methodParameters.get(method.getJavaMember()).get(p.getPosition()) == null)
+ {
+ methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, methodParameters.get(method.getJavaMember()).get(p.getPosition()));
+ }
+ }
+ for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
+ {
+ if (constructors.get(constructor.getJavaMember()) == null)
+ {
+ constructors.put(constructor.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(constructor, overwriteExisting, constructors.get(constructor.getJavaMember()));
+ for (AnnotatedParameter<? super X> p : constructor.getParameters())
+ {
+ if (constructorParameters.get(constructor.getJavaMember()) == null)
+ {
+ constructorParameters.put(constructor.getJavaMember(), new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()) == null)
+ {
+ constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
+ }
+ }
+ return this;
+ }
+
+ protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations)
+ {
+ for (Annotation annotation : annotated.getAnnotations())
+ {
+ if (typeAnnotations.getAnnotation(annotation.annotationType()) != null)
+ {
+ if (overwriteExisting)
+ {
+ typeAnnotations.remove(annotation.annotationType());
+ typeAnnotations.add(annotation);
+ }
+ }
+ else
+ {
+ typeAnnotations.add(annotation);
+ }
+ }
+ }
+
+ public AnnotatedType<X> create()
+ {
+ Map<Constructor<?>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<?>, Map<Integer, AnnotationStore>>();
+ Map<Constructor<?>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<?>, AnnotationStore>();
+ Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer, AnnotationStore>>();
+ Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
+ Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
+
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ fieldAnnotations.put(field.getKey(), field.getValue().create());
+ }
+
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ methodAnnotations.put(method.getKey(), method.getValue().create());
+ }
+ for (Entry<Method, Map<Integer, AnnotationBuilder>> parameters : methodParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ methodParameterAnnnotations.put(parameters.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet())
+ {
+ parameterAnnotations.put(parameter.getKey(), parameter.getValue().create());
+ }
+ }
+
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ constructorAnnotations.put(constructor.getKey(), constructor.getValue().create());
+ }
+ for (Entry<Constructor<?>, Map<Integer, AnnotationBuilder>> parameters : constructorParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ constructorParameterAnnnotations.put(parameters.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet())
+ {
+ parameterAnnotations.put(parameter.getKey(), parameter.getValue().create());
+ }
+ }
+
+ return new AnnotatedTypeImpl<X>(underlyingType, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
+ }
+
+ public void overrideFieldType(Field field, Type type)
+ {
+ fieldTypes.put(field, type);
+ }
+
+ public void overrideMethodParameterType(Method method, Type type, int position)
+ {
+ if (methodParameterTypes.get(method) == null)
+ {
+ methodParameterTypes.put(method, new HashMap<Integer, Type>());
+ }
+ methodParameterTypes.get(method).put(position, type);
+ }
+
+ public void overrideConstructorParameterType(Constructor<?> constructor, Type type, int position)
+ {
+ if (constructorParameterTypes.get(constructor) == null)
+ {
+ constructorParameterTypes.put(constructor, new HashMap<Integer, Type>());
+ }
+ constructorParameterTypes.get(constructor).put(position, type);
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotatedTypeImpl.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * AnnotatedType implementation for adding beans in the BeforeBeanDiscovery
+ * event
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedTypeImpl<X> extends AnnotatedImpl implements AnnotatedType<X>
+{
+
+ private final Set<AnnotatedConstructor<X>> constructors;
+ private final Set<AnnotatedField<? super X>> fields;
+ private final Set<AnnotatedMethod<? super X>> methods;
+
+ private final Class<X> javaClass;
+
+ /**
+ * We make sure that there is a NewAnnotatedMember for every public
+ * method/field/constructor
+ *
+ * If annotation have been added to other methods as well we add them to
+ *
+ */
+ AnnotatedTypeImpl(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<?>, AnnotationStore> constructorAnnotations, Map<Constructor<?>, 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;
+ this.constructors = new HashSet<AnnotatedConstructor<X>>();
+ Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
+ Set<Method> mset = new HashSet<Method>();
+ Set<Field> fset = new HashSet<Field>();
+ for (Constructor<?> c : clazz.getConstructors())
+ {
+ AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), constructorParameterTypes.get(c));
+ constructors.add(nc);
+ cset.add(c);
+ }
+ for (Entry<Constructor<?>, AnnotationStore> c : constructorAnnotations.entrySet())
+ {
+ if (!cset.contains(c.getKey()))
+ {
+ AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<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())
+ {
+ AnnotatedMethodImpl<X> met = new AnnotatedMethodImpl<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m));
+ methods.add(met);
+ mset.add(m);
+ }
+ for (Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
+ {
+ if (!mset.contains(c.getKey()))
+ {
+ AnnotatedMethodImpl<X> nc = new AnnotatedMethodImpl<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
+ methods.add(nc);
+ }
+ }
+ this.fields = new HashSet<AnnotatedField<? super X>>();
+ for (Field f : clazz.getFields())
+ {
+ AnnotatedField<X> b = new AnnotatedFieldImpl<X>(this, f, fieldAnnotations.get(f), fieldTypes.get(f));
+ fields.add(b);
+ fset.add(f);
+ }
+ for (Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
+ {
+ if (!fset.contains(e.getKey()))
+ {
+ fields.add(new AnnotatedFieldImpl<X>(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey())));
+ }
+ }
+ }
+
+ public Set<AnnotatedConstructor<X>> getConstructors()
+ {
+ return Collections.unmodifiableSet(constructors);
+ }
+
+ public Set<AnnotatedField<? super X>> getFields()
+ {
+ return Collections.unmodifiableSet(fields);
+ }
+
+ public Class<X> getJavaClass()
+ {
+ return javaClass;
+ }
+
+ public Set<AnnotatedMethod<? super X>> getMethods()
+ {
+ return Collections.unmodifiableSet(methods);
+ }
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,94 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class AnnotationBuilder
-{
- private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
- private Set<Annotation> annotationSet = new HashSet<Annotation>();
-
- public AnnotationBuilder add(Annotation a)
- {
- annotationSet.add(a);
- annotationMap.put(a.annotationType(), a);
- return this;
- }
-
- public void remove(Class<? extends Annotation> a)
- {
- Iterator<Annotation> it = annotationSet.iterator();
- while (it.hasNext())
- {
- Annotation an = it.next();
- if (a.isAssignableFrom(an.annotationType()))
- {
- it.remove();
- }
- }
- annotationMap.remove(a);
- }
-
- public AnnotationStore create()
- {
- return new AnnotationStore(annotationMap, annotationSet);
- }
-
- public AnnotationBuilder addAll(Set<Annotation> annotations)
- {
- for (Annotation annotation : annotations)
- {
- add(annotation);
- }
- return this;
- }
-
- public AnnotationBuilder addAll(AnnotationStore annotations)
- {
- for (Annotation annotation : annotations.getAnnotations())
- {
- add(annotation);
- }
- return this;
- }
-
- public AnnotationBuilder addAll(AnnotatedElement element)
- {
- for (Annotation a : element.getAnnotations())
- {
- add(a);
- }
- return this;
- }
-
- public <T extends Annotation> T getAnnotation(Class<T> anType)
- {
- return (T) annotationMap.get(anType);
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class AnnotationBuilder
+{
+ private final HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ private final Set<Annotation> annotationSet = new HashSet<Annotation>();
+
+ public AnnotationBuilder add(Annotation annotation)
+ {
+ annotationSet.add(annotation);
+ annotationMap.put(annotation.annotationType(), annotation);
+ return this;
+ }
+
+ public void remove(Class<? extends Annotation> annotation)
+ {
+ Iterator<Annotation> it = annotationSet.iterator();
+ while (it.hasNext())
+ {
+ Annotation an = it.next();
+ if (annotation.isAssignableFrom(an.annotationType()))
+ {
+ it.remove();
+ }
+ }
+ annotationMap.remove(annotation);
+ }
+
+ AnnotationStore create()
+ {
+ return new AnnotationStore(annotationMap, annotationSet);
+ }
+
+ public AnnotationBuilder addAll(Set<Annotation> annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public AnnotationBuilder addAll(AnnotationStore annotations)
+ {
+ for (Annotation annotation : annotations.getAnnotations())
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public AnnotationBuilder addAll(AnnotatedElement element)
+ {
+ for (Annotation a : element.getAnnotations())
+ {
+ add(a);
+ }
+ return this;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> anType)
+ {
+ return (T) annotationMap.get(anType);
+ }
+
+ public boolean isAnnotationPresent(Class<?> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+
+ @Override
+ public String toString()
+ {
+ return annotationSet.toString();
+ }
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,24 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-
-public interface AnnotationRedefiner<X extends Annotation>
-{
- public X redefine(X annotation, AnnotationBuilder annotations);
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java (from rev 6196, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+
+public interface AnnotationRedefiner<T extends Annotation, A>
+{
+ public T redefine(T annotation, A annotated, AnnotationBuilder annotations);
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class AnnotationStore
-{
-
- private final HashMap<Class<? extends Annotation>, Annotation> annotationMap;
- private final Set<Annotation> annotationSet;
-
- AnnotationStore(HashMap<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
- {
- this.annotationMap = annotationMap;
- this.annotationSet = annotationSet;
- }
-
- AnnotationStore()
- {
- this.annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
- this.annotationSet = new HashSet<Annotation>();
- }
-
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
- {
- return annotationType.cast(annotationMap.get(annotationType));
- }
-
- public Set<Annotation> getAnnotations()
- {
- return Collections.unmodifiableSet(annotationSet);
- }
-
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
- {
- return annotationMap.containsKey(annotationType);
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/AnnotationStore.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotationStore
+{
+
+ private final HashMap<Class<? extends Annotation>, Annotation> annotationMap;
+ private final Set<Annotation> annotationSet;
+
+ AnnotationStore(HashMap<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
+ {
+ this.annotationMap = annotationMap;
+ this.annotationSet = annotationSet;
+ }
+
+ AnnotationStore()
+ {
+ this.annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ this.annotationSet = new HashSet<Annotation>();
+ }
+
+ <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return annotationType.cast(annotationMap.get(annotationType));
+ }
+
+ Set<Annotation> getAnnotations()
+ {
+ return Collections.unmodifiableSet(annotationSet);
+ }
+
+ boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/MemberAnnotationRedefiner.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/MemberAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/MemberAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,9 @@
+package org.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+public interface MemberAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Member>
+{
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedConstructor.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedConstructor.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.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;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedConstructor<X> extends AbstractNewAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
-{
-
- 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(), getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides);
- }
-
- private static Type[] getGenericArray(Constructor<?> constructor)
- {
- Type[] genericTypes = constructor.getGenericParameterTypes();
- // for inner classes genericTypes and parameterTypes can be different
- // length, this is a hack to fix this.
- // TODO: investigate this behaviour further, on different JVM's and
- // compilers
- if (genericTypes.length + 1 == constructor.getParameterTypes().length)
- {
- genericTypes = new Type[constructor.getGenericParameterTypes().length + 1];
- genericTypes[0] = constructor.getParameterTypes()[0];
- for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i)
- {
- genericTypes[i + 1] = constructor.getGenericParameterTypes()[i];
- }
- }
- return genericTypes;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedField.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedField.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedField<X> extends AbstractNewAnnotatedMember<X, Field> implements AnnotatedField<X>
-{
-
- NewAnnotatedField(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations, Type overridenType)
- {
- super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType);
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedMethod.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedMethod.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.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;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedMethod<X> extends AbstractNewAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
-{
- NewAnnotatedMethod(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
- {
- super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedParameter.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedParameter.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedCallable;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedParameter<X> extends AbstractNewAnnotatedElement implements AnnotatedParameter<X>
-{
-
- private final int position;
- private final AnnotatedCallable<X> declaringCallable;
-
- NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations, Type genericType, Type typeOverride)
- {
- super(type, annotations, genericType, typeOverride);
- this.declaringCallable = declaringCallable;
- this.position = position;
- }
-
- public AnnotatedCallable<X> getDeclaringCallable()
- {
- return declaringCallable;
- }
-
- public int getPosition()
- {
- return position;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedType.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedType.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- * AnnotatedType implementation for adding beans in the BeforeBeanDiscovery
- * event
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedType<X> extends AbstractNewAnnotatedElement implements AnnotatedType<X>
-{
-
- private final Set<AnnotatedConstructor<X>> constructors;
- private final Set<AnnotatedField<? super X>> fields;
- private final Set<AnnotatedMethod<? super X>> methods;
-
- private final Class<X> javaClass;
-
- /**
- * We make sure that there is a NewAnnotatedMember for every public
- * method/field/constructor
- *
- * 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, Map<Method, Map<Integer, Type>> methodParameterTypes, Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes)
- {
- super(clazz, typeAnnotations, null, null);
- this.javaClass = clazz;
- this.constructors = new HashSet<AnnotatedConstructor<X>>();
- Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
- Set<Method> mset = new HashSet<Method>();
- 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), constructorParameterTypes.get(c));
- constructors.add(nc);
- cset.add(c);
- }
- for (Entry<Constructor<X>, AnnotationStore> c : constructorAnnotations.entrySet())
- {
- if (!cset.contains(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), methodParameterTypes.get(m));
- methods.add(met);
- mset.add(m);
- }
- for (Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
- {
- if (!mset.contains(c.getKey()))
- {
- NewAnnotatedMethod<X> nc = new NewAnnotatedMethod<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
- methods.add(nc);
- }
- }
- this.fields = new HashSet<AnnotatedField<? super X>>();
- for (Field f : clazz.getFields())
- {
- NewAnnotatedField<X> b = new NewAnnotatedField<X>(this, f, fieldAnnotations.get(f), fieldTypes.get(f));
- fields.add(b);
- fset.add(f);
- }
- for (Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
- {
- if (!fset.contains(e.getKey()))
- {
- fields.add(new NewAnnotatedField<X>(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey())));
- }
- }
- }
-
- public Set<AnnotatedConstructor<X>> getConstructors()
- {
- return Collections.unmodifiableSet(constructors);
- }
-
- public Set<AnnotatedField<? super X>> getFields()
- {
- return Collections.unmodifiableSet(fields);
- }
-
- public Class<X> getJavaClass()
- {
- return javaClass;
- }
-
- public Set<AnnotatedMethod<? super X>> getMethods()
- {
- return Collections.unmodifiableSet(methods);
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/NewAnnotatedTypeBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,591 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-import org.jboss.weld.extensions.util.ReflectionUtils;
-
-/**
- * Class for constructing a new AnnotatedType. A new instance of builder must be
- * used for each annotated type.
- *
- * In can either be created with no annotations, or the annotations can be read
- * from the underlying class or an AnnotatedType
- *
- * @author Stuart Douglas
- * @author Pete Muir
- *
- */
-public class NewAnnotatedTypeBuilder<X>
-{
- private Map<Field, AnnotationBuilder> fields = new HashMap<Field, AnnotationBuilder>();
- private Map<Method, AnnotationBuilder> methods = new HashMap<Method, AnnotationBuilder>();
- private Map<Method, Map<Integer, AnnotationBuilder>> methodParameters = new HashMap<Method, Map<Integer, AnnotationBuilder>>();
- private Map<Constructor<X>, AnnotationBuilder> constructors = new HashMap<Constructor<X>, AnnotationBuilder>();
- private Map<Constructor<X>, Map<Integer, AnnotationBuilder>> constructorParameters = new HashMap<Constructor<X>, Map<Integer, AnnotationBuilder>>();
- private AnnotationBuilder typeAnnotations = new AnnotationBuilder();
- 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)
- {
- this(underlying, false);
- }
-
- public NewAnnotatedTypeBuilder(Class<X> underlying, boolean readAnnotations)
- {
- this.underlying = underlying;
- if (readAnnotations)
- {
- for (Annotation a : underlying.getAnnotations())
- {
- typeAnnotations.add(a);
- }
-
- for (Field f : ReflectionUtils.getFields(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f, ab);
- for (Annotation a : f.getAnnotations())
- {
- ab.add(a);
- }
- }
-
- for (Method m : ReflectionUtils.getMethods(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- for (Constructor m : underlying.getConstructors())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- }
- }
-
- public NewAnnotatedTypeBuilder(AnnotatedType<X> type)
- {
- this.underlying = type.getJavaClass();
- for (Annotation a : type.getAnnotations())
- {
- typeAnnotations.add(a);
- }
-
- for (AnnotatedField<? super X> f : type.getFields())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f.getJavaMember(), ab);
- for (Annotation a : f.getAnnotations())
- {
- ab.add(a);
- }
- }
-
- for (AnnotatedMethod<? super X> m : type.getMethods())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m.getJavaMember(), ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
- {
- mab.add(a);
- }
- }
- }
-
- for (AnnotatedConstructor<X> m : type.getConstructors())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m.getJavaMember(), ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
- {
- mab.add(a);
- }
- }
- }
-
- }
-
- public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
- {
- typeAnnotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotation)
- {
- typeAnnotations.remove(annotation);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
- {
- AnnotationBuilder annotations = fields.get(field);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- fields.put(field, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = fields.get(field);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
- {
- AnnotationBuilder annotations = methods.get(method);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- methods.put(method, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = methods.get(method);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
- {
- if (!methods.containsKey(method))
- {
- methods.put(method, new AnnotationBuilder());
- }
- Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
- if (anmap == null)
- {
- anmap = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(method, anmap);
- }
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- anmap.put(parameter, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromMethodParameter(Method method, int parameter, Class<? extends Annotation> a)
- {
- Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
- if (anmap != null)
- {
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
- {
- AnnotationBuilder annotations = constructors.get(constructor);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- constructors.put(constructor, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromConstructor(Constructor<?> constructor, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = constructors.get(constructor);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
- {
- if (!constructors.containsKey(constructor))
- {
- constructors.put(constructor, new AnnotationBuilder());
- }
- Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
- if (anmap == null)
- {
- anmap = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(constructor, anmap);
- }
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- anmap.put(parameter, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int parameter, Class<? extends Annotation> a)
- {
- Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
- if (anmap != null)
- {
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> a)
- {
- removeFromClass(a);
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- e.getValue().remove(a);
- }
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- e.getValue().remove(a);
- Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- p.getValue().remove(a);
- }
- }
- }
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- e.getValue().remove(a);
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- p.getValue().remove(a);
- }
- }
- }
- return this;
- }
-
- public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefine(Class<T> annotationType, AnnotationRedefiner<T> redefinition)
- {
- redefineAnnotationBuilder(annotationType, redefinition, typeAnnotations);
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
- }
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
- Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
- }
- }
- }
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
- }
- }
- }
- return this;
- }
-
- protected <T extends Annotation> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T> redefinition, AnnotationBuilder builder)
- {
- T an = builder.getAnnotation(annotationType);
- if(an != null)
- {
- builder.remove(annotationType);
- T newAn = redefinition.redefine(an, builder);
- if (newAn != null)
- {
- builder.add(newAn);
- }
- }
- }
-
- /**
- * merges the annotations from an existing AnnoatedType. If they both have the same annotation
- * on an element overwriteExisting determines which one to keep
- * @param type
- * @param overwriteExisting
- * @return
- */
- public NewAnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
- {
- mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
- for (AnnotatedField<? super X> field : type.getFields())
- {
- AnnotationBuilder ans = fields.get(field.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- fields.put(field.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(field, overwriteExisting, ans);
- }
- for (AnnotatedMethod<? super X> method : type.getMethods())
- {
- AnnotationBuilder ans = methods.get(method.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- methods.put(method.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(method, overwriteExisting, ans);
- for (AnnotatedParameter<? super X> p : method.getParameters())
- {
- Map<Integer, AnnotationBuilder> params = methodParameters.get(method.getJavaMember());
- if (params == null)
- {
- params = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(method.getJavaMember(), params);
- }
- AnnotationBuilder builder = params.get(p.getPosition());
- if(builder == null)
- {
- builder = new AnnotationBuilder();
- params.put(p.getPosition(), builder);
- }
- mergeAnnotationsOnElement(p, overwriteExisting, builder);
- }
- }
- for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
- {
- AnnotationBuilder ans = constructors.get(constructor.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- constructors.put((Constructor) constructor.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(constructor, overwriteExisting, ans);
- for (AnnotatedParameter<? super X> p : constructor.getParameters())
- {
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(constructor.getJavaMember());
- if (params == null)
- {
- params = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put((Constructor) constructor.getJavaMember(), params);
- }
- AnnotationBuilder builder = params.get(p.getPosition());
- if (builder == null)
- {
- builder = new AnnotationBuilder();
- params.put(p.getPosition(), builder);
- }
- mergeAnnotationsOnElement(p, overwriteExisting, builder);
- }
- }
- return this;
- }
-
- protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations)
- {
- for (Annotation a : annotated.getAnnotations())
- {
- if (typeAnnotations.getAnnotation(a.annotationType()) != null)
- {
- if (overwriteExisting)
- {
- typeAnnotations.remove(a.annotationType());
- typeAnnotations.add(a);
- }
- }
- else
- {
- typeAnnotations.add(a);
- }
- }
- }
-
- public AnnotatedType<X> create()
- {
- Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,AnnotationStore>>();
- Map<Constructor<X>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, AnnotationStore>();
- Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer,AnnotationStore>>();
- Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
- Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
-
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- fieldAnnotations.put(e.getKey(), e.getValue().create());
- }
-
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- methodAnnotations.put(e.getKey(), e.getValue().create());
- }
- for (Entry<Method, Map<Integer, AnnotationBuilder>> e : methodParameters.entrySet())
- {
- Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
- methodParameterAnnnotations.put(e.getKey(), parameterAnnotations);
- for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
- {
- parameterAnnotations.put(pe.getKey(), pe.getValue().create());
- }
- }
-
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- constructorAnnotations.put(e.getKey(), e.getValue().create());
- }
- for (Entry<Constructor<X>, Map<Integer, AnnotationBuilder>> e : constructorParameters.entrySet())
- {
- Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
- constructorParameterAnnnotations.put(e.getKey(), parameterAnnotations);
- for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
- {
- parameterAnnotations.put(pe.getKey(), pe.getValue().create());
- }
- }
-
- return new NewAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
- }
-
- public void overrideFieldType(Field field, Type type)
- {
- 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);
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/Parameter.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/Parameter.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/Parameter.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,51 @@
+package org.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Member;
+
+public class Parameter
+{
+
+ private final Member declaringMember;
+ private final int position;
+
+ Parameter(Member declaringMember, int position)
+ {
+ this.declaringMember = declaringMember;
+ this.position = position;
+ }
+
+ public Member getDeclaringMember()
+ {
+ return declaringMember;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 1;
+ hash = hash * 31 + declaringMember.hashCode();
+ hash = hash * 31 + Integer.valueOf(position).hashCode();
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Parameter)
+ {
+ Parameter that = (Parameter) obj;
+ return this.getDeclaringMember().equals(that.getDeclaringMember()) && this.getPosition() == that.getPosition();
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/ParameterAnnotationRedefiner.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/ParameterAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/ParameterAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,8 @@
+package org.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+
+public interface ParameterAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Parameter>
+{
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeAnnotationRedefiner.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeAnnotationRedefiner.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,8 @@
+package org.jboss.weld.extensions.annotatedType;
+
+import java.lang.annotation.Annotation;
+
+public interface TypeAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Class<?>>
+{
+
+}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java 2010-04-28 16:45:31 UTC (rev 6191)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * A type closure builder
- *
- * @author Stuart Douglas
- *
- */
-class TypeClosureBuilder
-{
-
- final Set<Type> types = new HashSet<Type>();
-
- public TypeClosureBuilder add(Type type)
- {
- types.add(type);
- return this;
- }
-
- public TypeClosureBuilder add(Class<?> beanType)
- {
- Class<?> c = beanType;
- do
- {
- types.add(c);
- c = c.getSuperclass();
- }
- while (c != null);
- for (Class<?> i : beanType.getInterfaces())
- {
- types.add(i);
- }
- return this;
- }
-
- public TypeClosureBuilder addInterfaces(Class<?> beanType)
- {
- for (Class<?> i : beanType.getInterfaces())
- {
- types.add(i);
- }
- return this;
- }
-
- public Set<Type> getTypes()
- {
- return types;
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotatedType/TypeClosureBuilder.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.annotatedType;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A type closure builder
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TypeClosureBuilder
+{
+
+ private final Set<Type> types;
+
+ TypeClosureBuilder()
+ {
+ this.types = new HashSet<Type>();
+ }
+
+ TypeClosureBuilder add(Type type)
+ {
+ types.add(type);
+ return this;
+ }
+
+ TypeClosureBuilder add(Class<?> beanType)
+ {
+ for (Class<?> c = beanType; c != Object.class && c != null; c = c.getSuperclass())
+ {
+ types.add(c);
+ }
+ for (Class<?> i : beanType.getInterfaces())
+ {
+ types.add(i);
+ }
+ return this;
+ }
+
+ TypeClosureBuilder addInterfaces(Class<?> beanType)
+ {
+ for (Class<?> i : beanType.getInterfaces())
+ {
+ types.add(i);
+ }
+ return this;
+ }
+
+ Set<Type> getTypes()
+ {
+ return types;
+ }
+
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:36:09 UTC (rev 6200)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -43,9 +43,9 @@
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.inject.Inject;
+import org.jboss.weld.extensions.annotatedType.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.annotated.AnnotatedTypeBuilder;
public class GenericExtension implements Extension
{
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:36:09 UTC (rev 6200)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:41:13 UTC (rev 6201)
@@ -38,13 +38,13 @@
import javax.inject.Named;
import javax.inject.Qualifier;
+import org.jboss.weld.extensions.annotatedType.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.annotatedType.AnnotationBuilder;
+import org.jboss.weld.extensions.annotatedType.MemberAnnotationRedefiner;
+import org.jboss.weld.extensions.annotatedType.Parameter;
+import org.jboss.weld.extensions.annotatedType.ParameterAnnotationRedefiner;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.core.Exact.ExactLiteral;
-import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
-import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
-import org.jboss.weld.extensions.util.annotated.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.util.annotated.Parameter;
-import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
/**
* Extension to install the "core" extensions. Core extensions are those that
14 years, 8 months
Weld SVN: r6200 - in extensions/trunk: src/main/java/org/jboss/weld/extensions/bean/generic and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 17:36:09 -0400 (Thu, 29 Apr 2010)
New Revision: 6200
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.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/NewAnnotatedField.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
Modified:
extensions/trunk/pom.xml
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java
Log:
cleanup annotated
Modified: extensions/trunk/pom.xml
===================================================================
--- extensions/trunk/pom.xml 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/pom.xml 2010-04-29 21:36:09 UTC (rev 6200)
@@ -59,7 +59,7 @@
<properties>
<weld.api.version>1.0-SP1</weld.api.version>
- <weld.core.version>1.0.1-Final</weld.core.version>
+ <weld.core.version>1.0.1-SNAPSHOT</weld.core.version>
<slf4j.version>1.5.10</slf4j.version>
<testng.version>5.12.1</testng.version>
<jboss.test.harness.version>1.1.0-CR3</jboss.test.harness.version>
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -45,7 +45,7 @@
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.jboss.weld.extensions.util.annotated.AnnotatedTypeBuilder;
public class GenericExtension implements Extension
{
@@ -162,7 +162,7 @@
{
SyntheticQualifier newQualifier = getQualifierForGeneric(conc);
- NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
+ AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlyingType();
builder.addToClass(newQualifier);
for (AnnotatedField<? super X> f : at.getFields())
{
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -42,7 +42,7 @@
import org.jboss.weld.extensions.core.Exact.ExactLiteral;
import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.jboss.weld.extensions.util.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.util.annotated.Parameter;
import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
@@ -74,7 +74,7 @@
return;
}
- NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
+ AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlyingType();
// support for @Named packages
Package pkg = pat.getAnnotatedType().getJavaClass().getPackage();
@@ -157,7 +157,7 @@
{
if (constructor.isAnnotationPresent(Constructs.class))
{
- NewAnnotatedTypeBuilder<X> annotatedTypeBuilder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
+ AnnotatedTypeBuilder<X> annotatedTypeBuilder = AnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlyingType();
// remove class-level @Named annotation
annotatedTypeBuilder.removeFromClass(Named.class);
// remove bean constructors annotated @Inject
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.enterprise.inject.spi.AnnotatedCallable;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedCallable<X, Y extends Member> extends AbstractNewAnnotatedMember<X, Y> implements AnnotatedCallable<X>
-{
-
- private final List<AnnotatedParameter<X>> parameters;
-
- protected AbstractNewAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType, Map<Integer, Type> parameterTypeOverrides)
- {
- super(declaringType, member, memberType, annotations, genericType, null);
- this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, parameterTypeOverrides);
- }
-
- public List<AnnotatedParameter<X>> getParameters()
- {
- return Collections.unmodifiableList(parameters);
- }
-
- public AnnotatedParameter<X> getParameter(int index)
- {
- return parameters.get(index);
-
- }
-
- private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractNewAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
- {
- List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
- int len = parameterTypes.length;
- for (int i = 0; i < len; ++i)
- {
- AnnotationBuilder builder = new AnnotationBuilder();
- if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
- {
- builder.addAll(parameterAnnotations.get(i));
- }
- Type over = null;
- if (parameterTypeOverrides != null)
- {
- over = parameterTypeOverrides.get(i);
- }
- NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
- parameters.add(p);
- }
- return parameters;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Annotated;
-
-/**
- * The base class for all New Annotated types.
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedElement implements Annotated
-{
-
- private final Type type;
- private final Set<Type> typeClosure;
- private final AnnotationStore annotations;
-
- protected AbstractNewAnnotatedElement(Class<?> type, AnnotationStore annotations, Type genericType, Type overridenType)
- {
-
- if (overridenType == null)
- {
- this.typeClosure = new TypeClosureBuilder().add(type).getTypes();
- if (genericType != null)
- {
- typeClosure.add(genericType);
- this.type = genericType;
- }
- else
- {
- this.type = type;
- }
- }
- else
- {
- this.type = overridenType;
- this.typeClosure = Collections.singleton(overridenType);
- }
-
-
- if (annotations == null)
- {
- this.annotations = new AnnotationStore();
- }
- else
- {
- this.annotations = annotations;
- }
- }
-
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
- {
- return annotations.getAnnotation(annotationType);
- }
-
- public Set<Annotation> getAnnotations()
- {
- return annotations.getAnnotations();
- }
-
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
- {
- return annotations.isAnnotationPresent(annotationType);
- }
-
- public Set<Type> getTypeClosure()
- {
- return new HashSet<Type>(typeClosure);
- }
-
- public Type getBaseType()
- {
- return type;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedMember;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-abstract class AbstractNewAnnotatedMember<X, M extends Member> extends AbstractNewAnnotatedElement implements AnnotatedMember<X>
-{
- private final AnnotatedType<X> declaringType;
- private final M javaMember;
-
- protected AbstractNewAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, AnnotationStore annotations, Type genericType, Type overridenType)
- {
- super(memberType, annotations, genericType, overridenType);
- this.declaringType = declaringType;
- this.javaMember = member;
- }
-
- public AnnotatedType<X> getDeclaringType()
- {
- return declaringType;
- }
-
- public M getJavaMember()
- {
- return javaMember;
- }
-
- public boolean isStatic()
- {
- return Modifier.isStatic(javaMember.getModifiers());
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedCallableImpl<X, Y extends Member> extends AnnotatedMemberImpl<X, Y> implements AnnotatedCallable<X>
+{
+
+ private final List<AnnotatedParameter<X>> parameters;
+
+ protected AnnotatedCallableImpl(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, Type[] genericTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Type genericType, Map<Integer, Type> parameterTypeOverrides)
+ {
+ super(declaringType, member, memberType, annotations, genericType, null);
+ this.parameters = getAnnotatedParameters(this, parameterTypes, genericTypes, parameterAnnotations, parameterTypeOverrides);
+ }
+
+ public List<AnnotatedParameter<X>> getParameters()
+ {
+ return Collections.unmodifiableList(parameters);
+ }
+
+ public AnnotatedParameter<X> getParameter(int index)
+ {
+ return parameters.get(index);
+
+ }
+
+ private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+ {
+ List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+ int len = parameterTypes.length;
+ for (int i = 0; i < len; ++i)
+ {
+ AnnotationBuilder builder = new AnnotationBuilder();
+ if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+ {
+ builder.addAll(parameterAnnotations.get(i));
+ }
+ Type over = null;
+ if (parameterTypeOverrides != null)
+ {
+ over = parameterTypeOverrides.get(i);
+ }
+ AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
+ parameters.add(p);
+ }
+ return parameters;
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedCallableImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.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;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedConstructorImpl<X> extends AnnotatedCallableImpl<X, Constructor<X>> implements AnnotatedConstructor<X>
+{
+
+ AnnotatedConstructorImpl(AnnotatedTypeImpl<X> type, Constructor<?> constructor, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> typeOverrides)
+ {
+
+ super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides);
+ }
+
+ private static Type[] getGenericArray(Constructor<?> constructor)
+ {
+ Type[] genericTypes = constructor.getGenericParameterTypes();
+ // for inner classes genericTypes and parameterTypes can be different
+ // length, this is a hack to fix this.
+ // TODO: investigate this behavior further, on different JVM's and
+ // compilers
+ if (genericTypes.length + 1 == constructor.getParameterTypes().length)
+ {
+ genericTypes = new Type[constructor.getGenericParameterTypes().length + 1];
+ genericTypes[0] = constructor.getParameterTypes()[0];
+ for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i)
+ {
+ genericTypes[i + 1] = constructor.getGenericParameterTypes()[i];
+ }
+ }
+ return genericTypes;
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedConstructorImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedFieldImpl<X> extends AnnotatedMemberImpl<X, Field> implements AnnotatedField<X>
+{
+
+ AnnotatedFieldImpl(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations, Type overridenType)
+ {
+ super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType);
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedFieldImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+
+/**
+ * The base class for all New Annotated types.
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedImpl implements Annotated
+{
+
+ private final Type type;
+ private final Set<Type> typeClosure;
+ private final AnnotationStore annotations;
+
+ protected AnnotatedImpl(Class<?> type, AnnotationStore annotations, Type genericType, Type overridenType)
+ {
+
+ if (overridenType == null)
+ {
+ this.typeClosure = new TypeClosureBuilder().add(type).getTypes();
+ if (genericType != null)
+ {
+ typeClosure.add(genericType);
+ this.type = genericType;
+ }
+ else
+ {
+ this.type = type;
+ }
+ }
+ else
+ {
+ this.type = overridenType;
+ this.typeClosure = Collections.singleton(overridenType);
+ }
+
+
+ if (annotations == null)
+ {
+ this.annotations = new AnnotationStore();
+ }
+ else
+ {
+ this.annotations = annotations;
+ }
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return annotations.getAnnotation(annotationType);
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return annotations.getAnnotations();
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return annotations.isAnnotationPresent(annotationType);
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return new HashSet<Type>(typeClosure);
+ }
+
+ public Type getBaseType()
+ {
+ return type;
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AnnotatedMemberImpl<X, M extends Member> extends AnnotatedImpl implements AnnotatedMember<X>
+{
+ private final AnnotatedType<X> declaringType;
+ private final M javaMember;
+
+ protected AnnotatedMemberImpl(AnnotatedType<X> declaringType, M member, Class<?> memberType, AnnotationStore annotations, Type genericType, Type overridenType)
+ {
+ super(memberType, annotations, genericType, overridenType);
+ this.declaringType = declaringType;
+ this.javaMember = member;
+ }
+
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return declaringType;
+ }
+
+ public M getJavaMember()
+ {
+ return javaMember;
+ }
+
+ public boolean isStatic()
+ {
+ return Modifier.isStatic(javaMember.getModifiers());
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMemberImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.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;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedMethodImpl<X> extends AnnotatedCallableImpl<X, Method> implements AnnotatedMethod<X>
+{
+ AnnotatedMethodImpl(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
+ {
+ super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedMethodImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedParameterImpl<X> extends AnnotatedImpl implements AnnotatedParameter<X>
+{
+
+ private final int position;
+ private final AnnotatedCallable<X> declaringCallable;
+
+ AnnotatedParameterImpl(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations, Type genericType, Type typeOverride)
+ {
+ super(type, annotations, genericType, typeOverride);
+ this.declaringCallable = declaringCallable;
+ this.position = position;
+ }
+
+ public AnnotatedCallable<X> getDeclaringCallable()
+ {
+ return declaringCallable;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedParameterImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java (from rev 6196, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,525 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+import org.jboss.weld.extensions.util.ReflectionUtils;
+
+/**
+ * Class for constructing a new AnnotatedType. A new instance of builder must be
+ * used for each annotated type.
+ *
+ * In can either be created with no annotations, or the annotations can be read
+ * from the underlying class or an AnnotatedType
+ *
+ * @author Stuart Douglas
+ * @author Pete Muir
+ *
+ */
+public class AnnotatedTypeBuilder<X>
+{
+
+
+ public static <X> AnnotatedTypeBuilder<X> newInstance(Class<X> underlying)
+ {
+ return new AnnotatedTypeBuilder<X>(underlying);
+ }
+
+ public static <X> AnnotatedTypeBuilder<X> newInstance(AnnotatedType<X> underlying)
+ {
+ return new AnnotatedTypeBuilder<X>(underlying);
+ }
+
+ private final Class<X> underlyingType;
+ private final AnnotationBuilder typeAnnotations;
+
+ private final Map<Constructor<?>, AnnotationBuilder> constructors;
+ private final Map<Constructor<?>, Map<Integer, AnnotationBuilder>> constructorParameters;
+ private Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes;
+
+ private final Map<Field, AnnotationBuilder> fields;
+ private final Map<Field, Type> fieldTypes;
+
+ private final Map<Method, AnnotationBuilder> methods;
+ private final Map<Method, Map<Integer, AnnotationBuilder>> methodParameters;
+ private final Map<Method, Map<Integer, Type>> methodParameterTypes;
+
+ protected AnnotatedTypeBuilder(Class<X> underlyingType)
+ {
+ this.underlyingType = underlyingType;
+ this.typeAnnotations = new AnnotationBuilder();
+ this.constructors = new HashMap<Constructor<?>, AnnotationBuilder>();
+ this.constructorParameters = new HashMap<Constructor<?>, Map<Integer,AnnotationBuilder>>();
+ this.constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer,Type>>();
+ this.fields = new HashMap<Field, AnnotationBuilder>();
+ this.fieldTypes = new HashMap<Field, Type>();
+ this.methods = new HashMap<Method, AnnotationBuilder>();
+ this.methodParameters = new HashMap<Method, Map<Integer,AnnotationBuilder>>();
+ this.methodParameterTypes = new HashMap<Method, Map<Integer,Type>>();
+ }
+
+ protected AnnotatedTypeBuilder(AnnotatedType<X> underlyingType)
+ {
+ this(underlyingType.getJavaClass());
+
+ }
+
+ public AnnotatedTypeBuilder<X> readAnnotationsFromUnderlyingType()
+ {
+ for (Annotation annotation : underlyingType.getAnnotations())
+ {
+ typeAnnotations.add(annotation);
+ }
+
+ for (Field field : ReflectionUtils.getFields(underlyingType))
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ fields.put(field, annotationBuilder);
+ field.setAccessible(true);
+ for (Annotation annotation : field.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ }
+
+ for (Method method : ReflectionUtils.getMethods(underlyingType))
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ method.setAccessible(true);
+ methods.put(method, annotationBuilder);
+ for (Annotation annotation : method.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ Map<Integer, AnnotationBuilder> parameters = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(method, parameters);
+ for (int i = 0; i < method.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
+ parameters.put(i, parameterAnnotationBuilder);
+ for (Annotation annotation : method.getParameterAnnotations()[i])
+ {
+ parameterAnnotationBuilder.add(annotation);
+ }
+ }
+ }
+
+ for (Constructor<?> constructor : underlyingType.getDeclaredConstructors())
+ {
+ AnnotationBuilder annotationBuilder = new AnnotationBuilder();
+ constructor.setAccessible(true);
+ constructors.put(constructor, annotationBuilder);
+ for (Annotation annotation : constructor.getAnnotations())
+ {
+ annotationBuilder.add(annotation);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put(constructor, mparams);
+ for (int i = 0; i < constructor.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
+ mparams.put(i, parameterAnnotationBuilder);
+ for (Annotation annotation : constructor.getParameterAnnotations()[i])
+ {
+ parameterAnnotationBuilder.add(annotation);
+ }
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToClass(Annotation annotation)
+ {
+ typeAnnotations.add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotation)
+ {
+ typeAnnotations.remove(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToField(Field field, Annotation annotation)
+ {
+ if (fields.get(field) == null)
+ {
+ fields.put(field, new AnnotationBuilder());
+ }
+ fields.get(field).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> annotation)
+ {
+ if (fields.get(field) != null)
+ {
+ fields.get(field).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToMethod(Method method, Annotation annotation)
+ {
+ if (methods.get(method) == null)
+ {
+ methods.put(method, new AnnotationBuilder());
+ }
+ methods.get(method).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> annotation)
+ {
+ if (methods.get(method) != null)
+ {
+ methods.get(method).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToMethodParameter(Method method, int position, Annotation annotation)
+ {
+ if (!methods.containsKey(method))
+ {
+ methods.put(method, new AnnotationBuilder());
+ }
+ if (methodParameters.get(method) == null)
+ {
+ methodParameters.put(method, new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (methodParameters.get(method).get(position) == null)
+ {
+ methodParameters.get(method).put(position, new AnnotationBuilder());
+ }
+ methodParameters.get(method).get(position).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromMethodParameter(Method method, int position, Class<? extends Annotation> annotation)
+ {
+ if (methodParameters.get(method) != null)
+ {
+ if (methodParameters.get(method).get(position) != null)
+ {
+ methodParameters.get(method).get(position).remove(annotation);
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation annotation)
+ {
+ if (constructors.get(constructor) == null)
+ {
+ constructors.put(constructor, new AnnotationBuilder());
+ }
+ constructors.get(constructor).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromConstructor(Constructor<?> constructor, Class<? extends Annotation> annotation)
+ {
+ if (constructors.get(constructor) != null)
+ {
+ constructors.get(constructor).remove(annotation);
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int position, Annotation annotation)
+ {
+ if (!constructors.containsKey(constructor))
+ {
+ constructors.put(constructor, new AnnotationBuilder());
+ }
+ if (constructorParameters.get(constructor) == null)
+ {
+ constructorParameters.put(constructor, new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (constructorParameters.get(constructor).get(position) == null)
+ {
+ constructorParameters.get(constructor).put(position, new AnnotationBuilder());
+ }
+ constructorParameters.get(constructor).get(position).add(annotation);
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int position, Class<? extends Annotation> annotation)
+ {
+ if (constructorParameters.get(constructor) != null)
+ {
+ if (constructorParameters.get(constructor).get(position) != null)
+ {
+ constructorParameters.get(constructor).get(position).remove(annotation);
+ }
+ }
+ return this;
+ }
+
+ public AnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> annotation)
+ {
+ removeFromClass(annotation);
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ field.getValue().remove(annotation);
+ }
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ method.getValue().remove(annotation);
+ if (methodParameters.get(method.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : methodParameters.get(method.getKey()).entrySet())
+ {
+ parameter.getValue().remove(annotation);
+ }
+ }
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ constructor.getValue().remove(annotation);
+ if (constructorParameters.get(constructor.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : constructorParameters.get(constructor.getKey()).entrySet())
+ {
+ parameter.getValue().remove(annotation);
+ }
+ }
+ }
+ return this;
+ }
+
+ public <T extends Annotation> AnnotatedTypeBuilder<X> redefineMemberParameters(Class<T> annotationType, ParameterAnnotationRedefiner<T> redefinition)
+ {
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ if (methodParameters.get(method.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : methodParameters.get(method.getKey()).entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(method.getKey(), parameter.getKey()), parameter.getValue());
+ }
+ }
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ if (constructorParameters.get(constructor.getKey()) != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> parameter : constructorParameters.get(constructor.getKey()).entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(constructor.getKey(), parameter.getKey()), parameter.getValue());
+ }
+ }
+ }
+ return this;
+ }
+
+ public <T extends Annotation> AnnotatedTypeBuilder<X> redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T> redefinition)
+ {
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, field.getKey(), field.getValue());
+ }
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, method.getKey(), method.getValue());
+ }
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, constructor.getKey(), constructor.getValue());
+ }
+ return this;
+ }
+
+ protected <T extends Annotation, A> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T, A> redefinition, A annotated, AnnotationBuilder builder)
+ {
+ if (builder.isAnnotationPresent(annotationType))
+ {
+ builder.remove(annotationType);
+ T redefinedAnnotation = redefinition.redefine(builder.getAnnotation(annotationType), annotated, builder);
+ if (redefinedAnnotation != null)
+ {
+ builder.add(redefinedAnnotation);
+ }
+ }
+ }
+
+ /**
+ * merges the annotations from an existing AnnotatedType. If they both have
+ * the same annotation on an element overwriteExisting determines which one
+ * to keep
+ *
+ * @param type
+ * @param overwriteExisting
+ * @return
+ */
+ public AnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
+ {
+ mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
+ for (AnnotatedField<? super X> field : type.getFields())
+ {
+ if (fields.get(field.getJavaMember()) == null)
+ {
+ fields.put(field.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(field, overwriteExisting, fields.get(field.getJavaMember()));
+ }
+ for (AnnotatedMethod<? super X> method : type.getMethods())
+ {
+ if (methods.get(method.getJavaMember()) == null)
+ {
+ methods.put(method.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(method, overwriteExisting, methods.get(method.getJavaMember()));
+ for (AnnotatedParameter<? super X> p : method.getParameters())
+ {
+ if (methodParameters.get(method.getJavaMember()) == null)
+ {
+ methodParameters.put(method.getJavaMember(), new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (methodParameters.get(method.getJavaMember()).get(p.getPosition()) == null)
+ {
+ methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, methodParameters.get(method.getJavaMember()).get(p.getPosition()));
+ }
+ }
+ for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
+ {
+ if (constructors.get(constructor.getJavaMember()) == null)
+ {
+ constructors.put(constructor.getJavaMember(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(constructor, overwriteExisting, constructors.get(constructor.getJavaMember()));
+ for (AnnotatedParameter<? super X> p : constructor.getParameters())
+ {
+ if (constructorParameters.get(constructor.getJavaMember()) == null)
+ {
+ constructorParameters.put(constructor.getJavaMember(), new HashMap<Integer, AnnotationBuilder>());
+ }
+ if (constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()) == null)
+ {
+ constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
+ }
+ }
+ return this;
+ }
+
+ protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations)
+ {
+ for (Annotation annotation : annotated.getAnnotations())
+ {
+ if (typeAnnotations.getAnnotation(annotation.annotationType()) != null)
+ {
+ if (overwriteExisting)
+ {
+ typeAnnotations.remove(annotation.annotationType());
+ typeAnnotations.add(annotation);
+ }
+ }
+ else
+ {
+ typeAnnotations.add(annotation);
+ }
+ }
+ }
+
+ public AnnotatedType<X> create()
+ {
+ Map<Constructor<?>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<?>, Map<Integer, AnnotationStore>>();
+ Map<Constructor<?>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<?>, AnnotationStore>();
+ Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer, AnnotationStore>>();
+ Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
+ Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
+
+ for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
+ {
+ fieldAnnotations.put(field.getKey(), field.getValue().create());
+ }
+
+ for (Entry<Method, AnnotationBuilder> method : methods.entrySet())
+ {
+ methodAnnotations.put(method.getKey(), method.getValue().create());
+ }
+ for (Entry<Method, Map<Integer, AnnotationBuilder>> parameters : methodParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ methodParameterAnnnotations.put(parameters.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet())
+ {
+ parameterAnnotations.put(parameter.getKey(), parameter.getValue().create());
+ }
+ }
+
+ for (Entry<Constructor<?>, AnnotationBuilder> constructor : constructors.entrySet())
+ {
+ constructorAnnotations.put(constructor.getKey(), constructor.getValue().create());
+ }
+ for (Entry<Constructor<?>, Map<Integer, AnnotationBuilder>> parameters : constructorParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ constructorParameterAnnnotations.put(parameters.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet())
+ {
+ parameterAnnotations.put(parameter.getKey(), parameter.getValue().create());
+ }
+ }
+
+ return new AnnotatedTypeImpl<X>(underlyingType, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
+ }
+
+ public void overrideFieldType(Field field, Type type)
+ {
+ fieldTypes.put(field, type);
+ }
+
+ public void overrideMethodParameterType(Method method, Type type, int position)
+ {
+ if (methodParameterTypes.get(method) == null)
+ {
+ methodParameterTypes.put(method, new HashMap<Integer, Type>());
+ }
+ methodParameterTypes.get(method).put(position, type);
+ }
+
+ public void overrideConstructorParameterType(Constructor<?> constructor, Type type, int position)
+ {
+ if (constructorParameterTypes.get(constructor) == null)
+ {
+ constructorParameterTypes.put(constructor, new HashMap<Integer, Type>());
+ }
+ constructorParameterTypes.get(constructor).put(position, type);
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * AnnotatedType implementation for adding beans in the BeforeBeanDiscovery
+ * event
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotatedTypeImpl<X> extends AnnotatedImpl implements AnnotatedType<X>
+{
+
+ private final Set<AnnotatedConstructor<X>> constructors;
+ private final Set<AnnotatedField<? super X>> fields;
+ private final Set<AnnotatedMethod<? super X>> methods;
+
+ private final Class<X> javaClass;
+
+ /**
+ * We make sure that there is a NewAnnotatedMember for every public
+ * method/field/constructor
+ *
+ * If annotation have been added to other methods as well we add them to
+ *
+ */
+ AnnotatedTypeImpl(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<?>, AnnotationStore> constructorAnnotations, Map<Constructor<?>, 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;
+ this.constructors = new HashSet<AnnotatedConstructor<X>>();
+ Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
+ Set<Method> mset = new HashSet<Method>();
+ Set<Field> fset = new HashSet<Field>();
+ for (Constructor<?> c : clazz.getConstructors())
+ {
+ AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c), constructorParameterTypes.get(c));
+ constructors.add(nc);
+ cset.add(c);
+ }
+ for (Entry<Constructor<?>, AnnotationStore> c : constructorAnnotations.entrySet())
+ {
+ if (!cset.contains(c.getKey()))
+ {
+ AnnotatedConstructor<X> nc = new AnnotatedConstructorImpl<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())
+ {
+ AnnotatedMethodImpl<X> met = new AnnotatedMethodImpl<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m), methodParameterTypes.get(m));
+ methods.add(met);
+ mset.add(m);
+ }
+ for (Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
+ {
+ if (!mset.contains(c.getKey()))
+ {
+ AnnotatedMethodImpl<X> nc = new AnnotatedMethodImpl<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
+ methods.add(nc);
+ }
+ }
+ this.fields = new HashSet<AnnotatedField<? super X>>();
+ for (Field f : clazz.getFields())
+ {
+ AnnotatedField<X> b = new AnnotatedFieldImpl<X>(this, f, fieldAnnotations.get(f), fieldTypes.get(f));
+ fields.add(b);
+ fset.add(f);
+ }
+ for (Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
+ {
+ if (!fset.contains(e.getKey()))
+ {
+ fields.add(new AnnotatedFieldImpl<X>(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey())));
+ }
+ }
+ }
+
+ public Set<AnnotatedConstructor<X>> getConstructors()
+ {
+ return Collections.unmodifiableSet(constructors);
+ }
+
+ public Set<AnnotatedField<? super X>> getFields()
+ {
+ return Collections.unmodifiableSet(fields);
+ }
+
+ public Class<X> getJavaClass()
+ {
+ return javaClass;
+ }
+
+ public Set<AnnotatedMethod<? super X>> getMethods()
+ {
+ return Collections.unmodifiableSet(methods);
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotatedTypeImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -30,31 +30,31 @@
*/
public class AnnotationBuilder
{
- private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
- private Set<Annotation> annotationSet = new HashSet<Annotation>();
+ private final HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ private final Set<Annotation> annotationSet = new HashSet<Annotation>();
- public AnnotationBuilder add(Annotation a)
+ public AnnotationBuilder add(Annotation annotation)
{
- annotationSet.add(a);
- annotationMap.put(a.annotationType(), a);
+ annotationSet.add(annotation);
+ annotationMap.put(annotation.annotationType(), annotation);
return this;
}
- public void remove(Class<? extends Annotation> a)
+ public void remove(Class<? extends Annotation> annotation)
{
Iterator<Annotation> it = annotationSet.iterator();
while (it.hasNext())
{
Annotation an = it.next();
- if (a.isAssignableFrom(an.annotationType()))
+ if (annotation.isAssignableFrom(an.annotationType()))
{
it.remove();
}
}
- annotationMap.remove(a);
+ annotationMap.remove(annotation);
}
- public AnnotationStore create()
+ AnnotationStore create()
{
return new AnnotationStore(annotationMap, annotationSet);
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -45,17 +45,17 @@
this.annotationSet = new HashSet<Annotation>();
}
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
return annotationType.cast(annotationMap.get(annotationType));
}
- public Set<Annotation> getAnnotations()
+ Set<Annotation> getAnnotations()
{
return Collections.unmodifiableSet(annotationSet);
}
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
return annotationMap.containsKey(annotationType);
}
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.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;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedConstructor<X> extends AbstractNewAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
-{
-
- 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(), getGenericArray(constructor), annotations, parameterAnnotations, null, typeOverrides);
- }
-
- private static Type[] getGenericArray(Constructor<?> constructor)
- {
- Type[] genericTypes = constructor.getGenericParameterTypes();
- // for inner classes genericTypes and parameterTypes can be different
- // length, this is a hack to fix this.
- // TODO: investigate this behaviour further, on different JVM's and
- // compilers
- if (genericTypes.length + 1 == constructor.getParameterTypes().length)
- {
- genericTypes = new Type[constructor.getGenericParameterTypes().length + 1];
- genericTypes[0] = constructor.getParameterTypes()[0];
- for (int i = 0; i < constructor.getGenericParameterTypes().length; ++i)
- {
- genericTypes[i + 1] = constructor.getGenericParameterTypes()[i];
- }
- }
- return genericTypes;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedField<X> extends AbstractNewAnnotatedMember<X, Field> implements AnnotatedField<X>
-{
-
- NewAnnotatedField(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations, Type overridenType)
- {
- super(declaringType, field, field.getType(), annotations, field.getGenericType(), overridenType);
- }
-
-}
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.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;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedMethod<X> extends AbstractNewAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
-{
- NewAnnotatedMethod(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides)
- {
- super(type, method, method.getReturnType(), method.getParameterTypes(), method.getGenericParameterTypes(), annotations, parameterAnnotations, method.getGenericReturnType(), parameterTypeOverrides);
- }
-
-}
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Type;
-
-import javax.enterprise.inject.spi.AnnotatedCallable;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedParameter<X> extends AbstractNewAnnotatedElement implements AnnotatedParameter<X>
-{
-
- private final int position;
- private final AnnotatedCallable<X> declaringCallable;
-
- NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations, Type genericType, Type typeOverride)
- {
- super(type, annotations, genericType, typeOverride);
- this.declaringCallable = declaringCallable;
- this.position = position;
- }
-
- public AnnotatedCallable<X> getDeclaringCallable()
- {
- return declaringCallable;
- }
-
- public int getPosition()
- {
- return position;
- }
-
-}
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- * AnnotatedType implementation for adding beans in the BeforeBeanDiscovery
- * event
- *
- * @author Stuart Douglas
- *
- */
-class NewAnnotatedType<X> extends AbstractNewAnnotatedElement implements AnnotatedType<X>
-{
-
- private final Set<AnnotatedConstructor<X>> constructors;
- private final Set<AnnotatedField<? super X>> fields;
- private final Set<AnnotatedMethod<? super X>> methods;
-
- private final Class<X> javaClass;
-
- /**
- * We make sure that there is a NewAnnotatedMember for every public
- * method/field/constructor
- *
- * 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, Map<Method, Map<Integer, Type>> methodParameterTypes, Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes)
- {
- super(clazz, typeAnnotations, null, null);
- this.javaClass = clazz;
- this.constructors = new HashSet<AnnotatedConstructor<X>>();
- Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
- Set<Method> mset = new HashSet<Method>();
- 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), constructorParameterTypes.get(c));
- constructors.add(nc);
- cset.add(c);
- }
- for (Entry<Constructor<X>, AnnotationStore> c : constructorAnnotations.entrySet())
- {
- if (!cset.contains(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), methodParameterTypes.get(m));
- methods.add(met);
- mset.add(m);
- }
- for (Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
- {
- if (!mset.contains(c.getKey()))
- {
- NewAnnotatedMethod<X> nc = new NewAnnotatedMethod<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()), methodParameterTypes.get(c.getKey()));
- methods.add(nc);
- }
- }
- this.fields = new HashSet<AnnotatedField<? super X>>();
- for (Field f : clazz.getFields())
- {
- NewAnnotatedField<X> b = new NewAnnotatedField<X>(this, f, fieldAnnotations.get(f), fieldTypes.get(f));
- fields.add(b);
- fset.add(f);
- }
- for (Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
- {
- if (!fset.contains(e.getKey()))
- {
- fields.add(new NewAnnotatedField<X>(this, e.getKey(), e.getValue(), fieldTypes.get(e.getKey())));
- }
- }
- }
-
- public Set<AnnotatedConstructor<X>> getConstructors()
- {
- return Collections.unmodifiableSet(constructors);
- }
-
- public Set<AnnotatedField<? super X>> getFields()
- {
- return Collections.unmodifiableSet(fields);
- }
-
- public Class<X> getJavaClass()
- {
- return javaClass;
- }
-
- public Set<AnnotatedMethod<? super X>> getMethods()
- {
- return Collections.unmodifiableSet(methods);
- }
-
-}
Deleted: 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-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -1,556 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util.annotated;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-import org.jboss.weld.extensions.util.ReflectionUtils;
-
-/**
- * Class for constructing a new AnnotatedType. A new instance of builder must be
- * used for each annotated type.
- *
- * In can either be created with no annotations, or the annotations can be read
- * from the underlying class or an AnnotatedType
- *
- * @author Stuart Douglas
- * @author Pete Muir
- *
- */
-public class NewAnnotatedTypeBuilder<X>
-{
- private Map<Field, AnnotationBuilder> fields = new HashMap<Field, AnnotationBuilder>();
- private Map<Method, AnnotationBuilder> methods = new HashMap<Method, AnnotationBuilder>();
- private Map<Method, Map<Integer, AnnotationBuilder>> methodParameters = new HashMap<Method, Map<Integer, AnnotationBuilder>>();
- private Map<Constructor<X>, AnnotationBuilder> constructors = new HashMap<Constructor<X>, AnnotationBuilder>();
- private Map<Constructor<X>, Map<Integer, AnnotationBuilder>> constructorParameters = new HashMap<Constructor<X>, Map<Integer, AnnotationBuilder>>();
- private AnnotationBuilder typeAnnotations = new AnnotationBuilder();
- 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 static <X> NewAnnotatedTypeBuilder<X> newInstance(Class<X> underlying)
- {
- return new NewAnnotatedTypeBuilder<X>(underlying);
- }
-
- public static <X> NewAnnotatedTypeBuilder<X> newInstance(AnnotatedType<X> underlying)
- {
- return new NewAnnotatedTypeBuilder<X>(underlying);
- }
-
- protected NewAnnotatedTypeBuilder(Class<X> underlying)
- {
- this.underlying = underlying;
- }
-
- protected NewAnnotatedTypeBuilder(AnnotatedType<X> underlying)
- {
- this.underlying = underlying.getJavaClass();
-
- }
-
- public NewAnnotatedTypeBuilder<X> readAnnotationsFromUnderlying()
- {
- for (Annotation a : underlying.getAnnotations())
- {
- typeAnnotations.add(a);
- }
-
- for (Field f : ReflectionUtils.getFields(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f, ab);
- f.setAccessible(true);
- for (Annotation a : f.getAnnotations())
- {
- ab.add(a);
- }
- }
-
- for (Method m : ReflectionUtils.getMethods(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- m.setAccessible(true);
- methods.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- for (Constructor m : underlying.getDeclaredConstructors())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- m.setAccessible(true);
- constructors.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
- {
- typeAnnotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotation)
- {
- typeAnnotations.remove(annotation);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
- {
- AnnotationBuilder annotations = fields.get(field);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- fields.put(field, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = fields.get(field);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
- {
- AnnotationBuilder annotations = methods.get(method);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- methods.put(method, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = methods.get(method);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
- {
- if (!methods.containsKey(method))
- {
- methods.put(method, new AnnotationBuilder());
- }
- Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
- if (anmap == null)
- {
- anmap = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(method, anmap);
- }
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- anmap.put(parameter, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromMethodParameter(Method method, int parameter, Class<? extends Annotation> a)
- {
- Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
- if (anmap != null)
- {
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
- {
- AnnotationBuilder annotations = constructors.get(constructor);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- constructors.put(constructor, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromConstructor(Constructor<?> constructor, Class<? extends Annotation> a)
- {
- AnnotationBuilder annotations = constructors.get(constructor);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
- {
- if (!constructors.containsKey(constructor))
- {
- constructors.put(constructor, new AnnotationBuilder());
- }
- Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
- if (anmap == null)
- {
- anmap = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(constructor, anmap);
- }
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations == null)
- {
- annotations = new AnnotationBuilder();
- anmap.put(parameter, annotations);
- }
- annotations.add(a);
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int parameter, Class<? extends Annotation> a)
- {
- Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
- if (anmap != null)
- {
- AnnotationBuilder annotations = anmap.get(parameter);
- if (annotations != null)
- {
- annotations.remove(a);
- }
- }
- return this;
- }
-
- public NewAnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> a)
- {
- removeFromClass(a);
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- e.getValue().remove(a);
- }
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- e.getValue().remove(a);
- Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- p.getValue().remove(a);
- }
- }
- }
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- e.getValue().remove(a);
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- p.getValue().remove(a);
- }
- }
- }
- return this;
- }
-
- public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefineMemberParameters(Class<T> annotationType, ParameterAnnotationRedefiner<T> redefinition)
- {
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, new Parameter(e.getKey(), p.getKey()), p.getValue());
- }
- }
- }
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
- if (params != null)
- {
- for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, new Parameter(e.getKey(), p.getKey()), p.getValue());
- }
- }
- }
- return this;
- }
-
- public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T> redefinition)
- {
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
- }
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
- }
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
- }
- return this;
- }
-
- protected <T extends Annotation, A> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T, A> redefinition, A annotated, AnnotationBuilder builder)
- {
- T an = builder.getAnnotation(annotationType);
- if (an != null)
- {
- builder.remove(annotationType);
- T newAn = redefinition.redefine(an, annotated, builder);
- if (newAn != null)
- {
- builder.add(newAn);
- }
- }
- }
-
- /**
- * merges the annotations from an existing AnnotatedType. If they both have
- * the same annotation on an element overwriteExisting determines which one
- * to keep
- *
- * @param type
- * @param overwriteExisting
- * @return
- */
- public NewAnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
- {
- mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
- for (AnnotatedField<? super X> field : type.getFields())
- {
- AnnotationBuilder ans = fields.get(field.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- fields.put(field.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(field, overwriteExisting, ans);
- }
- for (AnnotatedMethod<? super X> method : type.getMethods())
- {
- AnnotationBuilder ans = methods.get(method.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- methods.put(method.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(method, overwriteExisting, ans);
- for (AnnotatedParameter<? super X> p : method.getParameters())
- {
- Map<Integer, AnnotationBuilder> params = methodParameters.get(method.getJavaMember());
- if (params == null)
- {
- params = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(method.getJavaMember(), params);
- }
- AnnotationBuilder builder = params.get(p.getPosition());
- if (builder == null)
- {
- builder = new AnnotationBuilder();
- params.put(p.getPosition(), builder);
- }
- mergeAnnotationsOnElement(p, overwriteExisting, builder);
- }
- }
- for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
- {
- AnnotationBuilder ans = constructors.get(constructor.getJavaMember());
- if (ans == null)
- {
- ans = new AnnotationBuilder();
- constructors.put((Constructor) constructor.getJavaMember(), ans);
- }
- mergeAnnotationsOnElement(constructor, overwriteExisting, ans);
- for (AnnotatedParameter<? super X> p : constructor.getParameters())
- {
- Map<Integer, AnnotationBuilder> params = constructorParameters.get(constructor.getJavaMember());
- if (params == null)
- {
- params = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put((Constructor) constructor.getJavaMember(), params);
- }
- AnnotationBuilder builder = params.get(p.getPosition());
- if (builder == null)
- {
- builder = new AnnotationBuilder();
- params.put(p.getPosition(), builder);
- }
- mergeAnnotationsOnElement(p, overwriteExisting, builder);
- }
- }
- return this;
- }
-
- protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations)
- {
- for (Annotation a : annotated.getAnnotations())
- {
- if (typeAnnotations.getAnnotation(a.annotationType()) != null)
- {
- if (overwriteExisting)
- {
- typeAnnotations.remove(a.annotationType());
- typeAnnotations.add(a);
- }
- }
- else
- {
- typeAnnotations.add(a);
- }
- }
- }
-
- public AnnotatedType<X> create()
- {
- Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer, AnnotationStore>>();
- Map<Constructor<X>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, AnnotationStore>();
- Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer, AnnotationStore>>();
- Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
- Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
-
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- fieldAnnotations.put(e.getKey(), e.getValue().create());
- }
-
- for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
- {
- methodAnnotations.put(e.getKey(), e.getValue().create());
- }
- for (Entry<Method, Map<Integer, AnnotationBuilder>> e : methodParameters.entrySet())
- {
- Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
- methodParameterAnnnotations.put(e.getKey(), parameterAnnotations);
- for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
- {
- parameterAnnotations.put(pe.getKey(), pe.getValue().create());
- }
- }
-
- for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
- {
- constructorAnnotations.put(e.getKey(), e.getValue().create());
- }
- for (Entry<Constructor<X>, Map<Integer, AnnotationBuilder>> e : constructorParameters.entrySet())
- {
- Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
- constructorParameterAnnnotations.put(e.getKey(), parameterAnnotations);
- for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
- {
- parameterAnnotations.put(pe.getKey(), pe.getValue().create());
- }
- }
-
- return new NewAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
- }
-
- public void overrideFieldType(Field field, Type type)
- {
- 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);
- }
-
-}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java 2010-04-29 20:22:21 UTC (rev 6199)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java 2010-04-29 21:36:09 UTC (rev 6200)
@@ -29,23 +29,25 @@
class TypeClosureBuilder
{
- final Set<Type> types = new HashSet<Type>();
+ private final Set<Type> types;
+
+ TypeClosureBuilder()
+ {
+ this.types = new HashSet<Type>();
+ }
- public TypeClosureBuilder add(Type type)
+ TypeClosureBuilder add(Type type)
{
types.add(type);
return this;
}
- public TypeClosureBuilder add(Class<?> beanType)
+ TypeClosureBuilder add(Class<?> beanType)
{
- Class<?> c = beanType;
- do
+ for (Class<?> c = beanType; c != Object.class && c != null; c = c.getSuperclass())
{
types.add(c);
- c = c.getSuperclass();
}
- while (c != null);
for (Class<?> i : beanType.getInterfaces())
{
types.add(i);
@@ -53,7 +55,7 @@
return this;
}
- public TypeClosureBuilder addInterfaces(Class<?> beanType)
+ TypeClosureBuilder addInterfaces(Class<?> beanType)
{
for (Class<?> i : beanType.getInterfaces())
{
@@ -62,7 +64,7 @@
return this;
}
- public Set<Type> getTypes()
+ Set<Type> getTypes()
{
return types;
}
14 years, 8 months
Weld SVN: r6199 - in extensions/trunk/src/main: java/org/jboss/weld/extensions/core and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 16:22:21 -0400 (Thu, 29 Apr 2010)
New Revision: 6199
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Constructs.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/DefaultLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Exact.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/InjectLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/NamedLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Veto.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/Resource.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/Constructs.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/NamedLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/Resource.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProducer.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProvider.java
extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
move core extensions to core
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/Constructs.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Constructs.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Constructs.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import static java.lang.annotation.ElementType.CONSTRUCTOR;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Allows a bean to be defined by annotating a constructor instead
- * of the bean class. There may be multiple beans defined using
- * <tt>@Constructs</tt> per bean class.
- *
- * @author Gavin King
- *
- */
-@Retention(RUNTIME)
-@Target(CONSTRUCTOR)
-@Documented
-public @interface Constructs {}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,200 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Qualifier;
-
-import org.jboss.weld.extensions.Exact.ExactLiteral;
-import org.jboss.weld.extensions.bean.CustomBeanBuilder;
-import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
-import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
-import org.jboss.weld.extensions.util.annotated.Parameter;
-import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
-
-class CoreExtension implements Extension
-{
-
- private final Collection<Bean<?>> additionalBeans;
-
- CoreExtension()
- {
- this.additionalBeans = new ArrayList<Bean<?>>();
- }
-
- <X> void processAnnotatedType(@Observes final ProcessAnnotatedType<X> pat, BeanManager bm)
- {
- if (pat.getAnnotatedType().isAnnotationPresent(Veto.class))
- {
- pat.veto();
- return;
- }
-
- final AnnotatedType<X> at = pat.getAnnotatedType();
- NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
-
- // support for @Named packages
- Package pkg = at.getJavaClass().getPackage();
- if (pkg.isAnnotationPresent(Named.class))
- {
- final String packageName = getPackageName(pkg);
-
- builder.redefineMembers(Named.class, new MemberAnnotationRedefiner<Named>()
- {
-
- public Named redefine(Named annotation, Member member, AnnotationBuilder annotations)
- {
- if (annotations.isAnnotationPresent(Produces.class))
- {
- String memberName = member.getName();
- String beanName = getName(annotation, memberName);
- return new NamedLiteral(packageName + '.' + beanName);
- }
- else
- {
- return annotation;
- }
- }
-
- });
-
- if (at.isAnnotationPresent(Named.class))
- {
- String className = at.getJavaClass().getSimpleName();
- String beanName = getName(at.getAnnotation(Named.class), className);
- builder.addToClass(new NamedLiteral(packageName + '.' + beanName));
- }
-
- }
-
- // support for @Exact
- Set<Annotation> qualfiers = getAnnotationsWithMetatype(at.getAnnotations(), Qualifier.class);
- if (qualfiers.isEmpty() || (qualfiers.size() == 1 && qualfiers.iterator().next().annotationType() == Named.class))
- {
- builder.addToClass(DefaultLiteral.INSTANCE);
- }
- builder.addToClass(new Exact.ExactLiteral(at.getJavaClass()));
- builder.redefineMembers(Exact.class, new MemberAnnotationRedefiner<Exact>()
- {
-
- public Exact redefine(Exact annotation, Member annotated, AnnotationBuilder annotations)
- {
- if (annotation.value() == void.class)
- {
- return new ExactLiteral(getMemberType(annotated));
- }
- else
- {
- return annotation;
- }
- }
- });
-
- builder.redefineMemberParameters(Exact.class, new ParameterAnnotationRedefiner<Exact>()
- {
-
- public Exact redefine(Exact annotation, Parameter annotated, AnnotationBuilder annotations)
- {
- if (annotation.value() == void.class)
- {
- return new ExactLiteral(getMemberType(annotated.getDeclaringMember()));
- }
- else
- {
- return annotation;
- }
- }
-
- });
-
- pat.setAnnotatedType(builder.create());
-
- // support for @Constructs
- for (AnnotatedConstructor<X> constructor : at.getConstructors())
- {
- if (constructor.isAnnotationPresent(Constructs.class))
- {
- NewAnnotatedTypeBuilder<X> annotatedTypeBuilder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
- // remove class-level @Named annotation
- annotatedTypeBuilder.removeFromClass(Named.class);
- // remove bean constructors annotated @Inject
- for (AnnotatedConstructor<X> constructor2 : at.getConstructors())
- {
- annotatedTypeBuilder.removeFromConstructor(constructor2.getJavaMember(), Inject.class);
- }
- // make the constructor annotated @Constructs the bean constructor
- annotatedTypeBuilder.addToConstructor(constructor.getJavaMember(), InjectLiteral.INSTANCE);
- // add all the annotations of this constructor to the class
- for (Annotation ann : constructor.getAnnotations())
- {
- annotatedTypeBuilder.addToClass(ann);
- }
- AnnotatedType<X> construtsAnnotatedType = builder.create();
- additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType, bm).build());
- }
- }
- }
-
- void afterBeanDiscovery(@Observes AfterBeanDiscovery abd)
- {
- for (Bean<?> bean : additionalBeans)
- {
- abd.addBean(bean);
- }
- }
-
- private String getPackageName(Package pkg)
- {
- String packageName = pkg.getAnnotation(Named.class).value();
- if (packageName.length() == 0)
- {
- packageName = pkg.getName();
- }
- return packageName;
- }
-
- private <X> String getName(Named named, String defaultName)
- {
- String beanName = named.value();
- if (beanName.length() == 0)
- {
- beanName = defaultName.substring(0, 1).toLowerCase() + defaultName.substring(1);
- }
- return beanName;
- }
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import javax.enterprise.inject.Default;
-import javax.enterprise.util.AnnotationLiteral;
-
-class DefaultLiteral extends AnnotationLiteral<Default> implements Default
-{
-
- private static final long serialVersionUID = 2768505716290514234L;
-
- public static final Default INSTANCE = new DefaultLiteral();
-
- private DefaultLiteral() {}
-
-}
\ No newline at end of file
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Qualifier;
-
-/**
- * An injection point qualifier that may be used to select the exact bean to be
- * injected, by specifying its implementation class.
- *
- * @author Gavin King
- *
- */
-@Retention(RUNTIME)
-@Target( { METHOD, TYPE, FIELD, PARAMETER })
-@Documented
-@Qualifier
-public @interface Exact
-{
- Class<?> value() default void.class;
-
- static class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
- {
-
- private static final long serialVersionUID = 4907169607105615674L;
-
- final Class<?> clazz;
-
- ExactLiteral(Class<?> clazz)
- {
- this.clazz = clazz;
- }
-
- public Class<?> value()
- {
- return clazz;
- }
- }
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Inject;
-
-class InjectLiteral extends AnnotationLiteral<Inject> implements Inject
-{
-
- private static final long serialVersionUID = 817936051028981316L;
-
- public static final Inject INSTANCE = new InjectLiteral();
-
- private InjectLiteral() {}
-
-}
\ No newline at end of file
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/NamedLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/NamedLiteral.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/NamedLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Named;
-
-class NamedLiteral extends AnnotationLiteral<Named> implements Named
-{
- private static final long serialVersionUID = 2239690880420187044L;
- final String name;
-
- NamedLiteral(String name)
- {
- this.name = name;
- }
-
- public String value()
- {
- return name;
- }
-}
\ No newline at end of file
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/Resource.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Resource.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Resource.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.enterprise.util.Nonbinding;
-import javax.inject.Qualifier;
-
-/**
- * An injection point qualifier that may be used to specify a resource to inject
- *
- * @author Pete Muir
- *
- */
-@Retention(RUNTIME)
-@Target( { METHOD, TYPE, FIELD, PARAMETER })
-@Documented
-@Qualifier
-public @interface Resource
-{
-
- @Nonbinding
- String value();
-
-}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Signifies that a bean should be vetoed at startup
- *
- * @author Stuart Douglas
- *
- */
-(a)Target(ElementType.TYPE)
-(a)Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface Veto
-{
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Constructs.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/Constructs.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Constructs.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Constructs.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Allows a bean to be defined by annotating a constructor instead
+ * of the bean class. There may be multiple beans defined using
+ * <tt>@Constructs</tt> per bean class.
+ *
+ * @author Gavin King
+ *
+ */
+@Retention(RUNTIME)
+@Target(CONSTRUCTOR)
+@Documented
+public @interface Constructs {}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Constructs.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java (from rev 6196, extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Qualifier;
+
+import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.core.Exact.ExactLiteral;
+import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
+import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.jboss.weld.extensions.util.annotated.Parameter;
+import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
+
+/**
+ * Extension to install the "core" extensions. Core extensions are those that
+ * add additional abilities to CDI applications via annotations.
+ *
+ * @author Stuart
+ * @author Pete Muir
+ * @author Gavin King
+ *
+ */
+class CoreExtension implements Extension
+{
+
+ private final Collection<Bean<?>> additionalBeans;
+
+ CoreExtension()
+ {
+ this.additionalBeans = new ArrayList<Bean<?>>();
+ }
+
+ <X> void processAnnotatedType(@Observes final ProcessAnnotatedType<X> pat, BeanManager beanManager)
+ {
+ // Support for @Veto
+ if (pat.getAnnotatedType().isAnnotationPresent(Veto.class))
+ {
+ pat.veto();
+ return;
+ }
+
+ NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
+
+ // support for @Named packages
+ Package pkg = pat.getAnnotatedType().getJavaClass().getPackage();
+ if (pkg.isAnnotationPresent(Named.class))
+ {
+ final String packageName = getPackageName(pkg);
+
+ builder.redefineMembers(Named.class, new MemberAnnotationRedefiner<Named>()
+ {
+
+ public Named redefine(Named annotation, Member member, AnnotationBuilder annotations)
+ {
+ if (annotations.isAnnotationPresent(Produces.class))
+ {
+ String memberName = member.getName();
+ String beanName = getName(annotation, memberName);
+ return new NamedLiteral(packageName + '.' + beanName);
+ }
+ else
+ {
+ return annotation;
+ }
+ }
+
+ });
+
+ if (pat.getAnnotatedType().isAnnotationPresent(Named.class))
+ {
+ String className = pat.getAnnotatedType().getJavaClass().getSimpleName();
+ String beanName = getName(pat.getAnnotatedType().getAnnotation(Named.class), className);
+ builder.addToClass(new NamedLiteral(packageName + '.' + beanName));
+ }
+
+ }
+
+ // support for @Exact
+ Set<Annotation> qualfiers = getAnnotationsWithMetatype(pat.getAnnotatedType().getAnnotations(), Qualifier.class);
+ if (qualfiers.isEmpty() || (qualfiers.size() == 1 && qualfiers.iterator().next().annotationType() == Named.class))
+ {
+ builder.addToClass(DefaultLiteral.INSTANCE);
+ }
+ builder.addToClass(new Exact.ExactLiteral(pat.getAnnotatedType().getJavaClass()));
+ builder.redefineMembers(Exact.class, new MemberAnnotationRedefiner<Exact>()
+ {
+
+ public Exact redefine(Exact annotation, Member annotated, AnnotationBuilder annotations)
+ {
+ if (annotation.value() == void.class)
+ {
+ return new ExactLiteral(getMemberType(annotated));
+ }
+ else
+ {
+ return annotation;
+ }
+ }
+ });
+
+ builder.redefineMemberParameters(Exact.class, new ParameterAnnotationRedefiner<Exact>()
+ {
+
+ public Exact redefine(Exact annotation, Parameter annotated, AnnotationBuilder annotations)
+ {
+ if (annotation.value() == void.class)
+ {
+ return new ExactLiteral(getMemberType(annotated.getDeclaringMember()));
+ }
+ else
+ {
+ return annotation;
+ }
+ }
+
+ });
+
+ pat.setAnnotatedType(builder.create());
+
+ // support for @Constructs
+ for (AnnotatedConstructor<X> constructor : pat.getAnnotatedType().getConstructors())
+ {
+ if (constructor.isAnnotationPresent(Constructs.class))
+ {
+ NewAnnotatedTypeBuilder<X> annotatedTypeBuilder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
+ // remove class-level @Named annotation
+ annotatedTypeBuilder.removeFromClass(Named.class);
+ // remove bean constructors annotated @Inject
+ for (AnnotatedConstructor<X> constructor2 : pat.getAnnotatedType().getConstructors())
+ {
+ annotatedTypeBuilder.removeFromConstructor(constructor2.getJavaMember(), Inject.class);
+ }
+ // make the constructor annotated @Constructs the bean constructor
+ annotatedTypeBuilder.addToConstructor(constructor.getJavaMember(), InjectLiteral.INSTANCE);
+ // add all the annotations of this constructor to the class
+ for (Annotation ann : constructor.getAnnotations())
+ {
+ annotatedTypeBuilder.addToClass(ann);
+ }
+ AnnotatedType<X> construtsAnnotatedType = builder.create();
+ additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType, beanManager).build());
+ }
+ }
+ }
+
+ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd)
+ {
+ for (Bean<?> bean : additionalBeans)
+ {
+ abd.addBean(bean);
+ }
+ }
+
+ private String getPackageName(Package pkg)
+ {
+ String packageName = pkg.getAnnotation(Named.class).value();
+ if (packageName.length() == 0)
+ {
+ packageName = pkg.getName();
+ }
+ return packageName;
+ }
+
+ private <X> String getName(Named named, String defaultName)
+ {
+ String beanName = named.value();
+ if (beanName.length() == 0)
+ {
+ beanName = defaultName.substring(0, 1).toLowerCase() + defaultName.substring(1);
+ }
+ return beanName;
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/DefaultLiteral.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/DefaultLiteral.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/DefaultLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.util.AnnotationLiteral;
+
+class DefaultLiteral extends AnnotationLiteral<Default> implements Default
+{
+
+ private static final long serialVersionUID = 2768505716290514234L;
+
+ static final Default INSTANCE = new DefaultLiteral();
+
+ private DefaultLiteral() {}
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/DefaultLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Exact.java (from rev 6196, extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Exact.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Exact.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+
+/**
+ * An injection point qualifier that may be used to select the exact bean to be
+ * injected, by specifying its implementation class.
+ *
+ * @author Gavin King
+ *
+ */
+@Retention(RUNTIME)
+@Target( { METHOD, TYPE, FIELD, PARAMETER })
+@Documented
+@Qualifier
+public @interface Exact
+{
+ Class<?> value() default void.class;
+
+ static class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
+ {
+
+ private static final long serialVersionUID = 4907169607105615674L;
+
+ final Class<?> clazz;
+
+ ExactLiteral(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ public Class<?> value()
+ {
+ return clazz;
+ }
+ }
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Exact.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/InjectLiteral.java (from rev 6198, extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/InjectLiteral.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/InjectLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+
+class InjectLiteral extends AnnotationLiteral<Inject> implements Inject
+{
+
+ private static final long serialVersionUID = 817936051028981316L;
+
+ static final Inject INSTANCE = new InjectLiteral();
+
+ private InjectLiteral() {}
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/InjectLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/NamedLiteral.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/NamedLiteral.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/NamedLiteral.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/NamedLiteral.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Named;
+
+class NamedLiteral extends AnnotationLiteral<Named> implements Named
+{
+ private static final long serialVersionUID = 2239690880420187044L;
+ final String name;
+
+ NamedLiteral(String name)
+ {
+ this.name = name;
+ }
+
+ public String value()
+ {
+ return name;
+ }
+}
\ No newline at end of file
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/NamedLiteral.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Veto.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Veto.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/Veto.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.core;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Instructs the CDI container not to deploy the class as a bean
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Veto
+{
+
+}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/Resource.java (from rev 6191, extensions/trunk/src/main/java/org/jboss/weld/extensions/Resource.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/Resource.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/Resource.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions.resourceLoader;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+
+/**
+ * An injection point qualifier that may be used to specify a resource to inject
+ *
+ * @author Pete Muir
+ *
+ */
+@Retention(RUNTIME)
+@Target( { METHOD, TYPE, FIELD, PARAMETER })
+@Documented
+@Qualifier
+public @interface Resource
+{
+
+ @Nonbinding
+ String value();
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/Resource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProducer.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProducer.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProducer.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -27,7 +27,6 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
-import org.jboss.weld.extensions.Resource;
/**
* Resource producer allows injecting of resources
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProvider.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProvider.java 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resourceLoader/ResourceProvider.java 2010-04-29 20:22:21 UTC (rev 6199)
@@ -30,7 +30,6 @@
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
-import org.jboss.weld.extensions.Resource;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
/**
Modified: extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-29 20:14:14 UTC (rev 6198)
+++ extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-29 20:22:21 UTC (rev 6199)
@@ -1,5 +1,5 @@
org.jboss.weld.extensions.bean.generic.GenericExtension
org.jboss.weld.extensions.resourceLoader.servlet.ServletResourceExtension
org.jboss.weld.extensions.bean.lookup.IdentifiableBeanExtension
-org.jboss.weld.extensions.CoreExtension
+org.jboss.weld.extensions.core.CoreExtension
org.jboss.weld.extensions.interceptor.InterceptorExtension
\ No newline at end of file
14 years, 8 months
Weld SVN: r6198 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: util/annotated and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 16:14:14 -0400 (Thu, 29 Apr 2010)
New Revision: 6198
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java
Log:
remove reannotated stuff (first pass, still needs more cleaning)
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.util.AnnotationLiteral;
+
+class DefaultLiteral extends AnnotationLiteral<Default> implements Default
+{
+
+ private static final long serialVersionUID = 2768505716290514234L;
+
+ public static final Default INSTANCE = new DefaultLiteral();
+
+ private DefaultLiteral() {}
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/DefaultLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.extensions;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+
+class InjectLiteral extends AnnotationLiteral<Inject> implements Inject
+{
+
+ private static final long serialVersionUID = 817936051028981316L;
+
+ public static final Inject INSTANCE = new InjectLiteral();
+
+ private InjectLiteral() {}
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/InjectLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,9 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+public interface MemberAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Member>
+{
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/MemberAnnotationRedefiner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,51 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Member;
+
+public class Parameter
+{
+
+ private final Member declaringMember;
+ private final int position;
+
+ Parameter(Member declaringMember, int position)
+ {
+ this.declaringMember = declaringMember;
+ this.position = position;
+ }
+
+ public Member getDeclaringMember()
+ {
+ return declaringMember;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 1;
+ hash = hash * 31 + declaringMember.hashCode();
+ hash = hash * 31 + Integer.valueOf(position).hashCode();
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Parameter)
+ {
+ Parameter that = (Parameter) obj;
+ return this.getDeclaringMember().equals(that.getDeclaringMember()) && this.getPosition() == that.getPosition();
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/Parameter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,8 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+
+public interface ParameterAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Parameter>
+{
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/ParameterAnnotationRedefiner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java 2010-04-29 20:14:14 UTC (rev 6198)
@@ -0,0 +1,8 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+
+public interface TypeAnnotationRedefiner<T extends Annotation> extends AnnotationRedefiner<T, Class<?>>
+{
+
+}
Property changes on: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/TypeAnnotationRedefiner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
14 years, 8 months
Weld SVN: r6197 - in core/trunk/impl/src/main/java/org/jboss/weld: exceptions and 1 other directories.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-29 16:01:54 -0400 (Thu, 29 Apr 2010)
New Revision: 6197
Added:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java
core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
Log:
WELD-504 Exception messages for lifecycle events now includes full stacktraces
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/BusyConversationException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> BusyConversationException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextNotActiveException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> ContextNotActiveException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/NonexistentConversationException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -17,6 +17,7 @@
package org.jboss.weld.context;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
/**
@@ -39,7 +40,7 @@
public <E extends Enum<?>> NonexistentConversationException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/AmbiguousResolutionException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public AmbiguousResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> AmbiguousResolutionException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/CreationException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -40,7 +40,7 @@
*/
public <E extends Enum<?>> CreationException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -55,7 +55,7 @@
public <E extends Enum<?>> CreationException(E key, Throwable throwable, Object... args)
{
super(throwable);
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenArgumentException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -38,7 +38,7 @@
public ForbiddenArgumentException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
*/
public <E extends Enum<?>> ForbiddenArgumentException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/ForbiddenStateException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -39,7 +39,7 @@
*/
public <E extends Enum<?>> ForbiddenStateException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
/**
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/IllegalProductException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -40,7 +40,7 @@
*/
public <E extends Enum<?>> IllegalProductException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InjectionException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public InjectionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
public InjectionException(String message, Throwable throwable)
{
super(throwable);
- this.message = new WeldExceptionMessage(message);
+ this.message = new WeldExceptionStringMessage(message);
}
/**
@@ -64,7 +64,7 @@
*/
public <E extends Enum<?>> InjectionException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidObjectException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -41,7 +41,7 @@
public <E extends Enum<?>> InvalidObjectException(E key, Object... args)
{
super(null);
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/InvalidOperationException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> InvalidOperationException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnproxyableResolutionException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public UnproxyableResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> UnproxyableResolutionException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/UnsatisfiedResolutionException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -37,7 +37,7 @@
public UnsatisfiedResolutionException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -50,7 +50,7 @@
*/
public <E extends Enum<?>> UnsatisfiedResolutionException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -38,7 +38,7 @@
public WeldException(Throwable throwable)
{
super(throwable);
- this.message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ this.message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
/**
@@ -51,7 +51,7 @@
*/
public <E extends Enum<?>> WeldException(E key, Object... args)
{
- this.message = new WeldExceptionMessage(key, args);
+ this.message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -66,7 +66,7 @@
public <E extends Enum<?>> WeldException(E key, Throwable throwable, Object... args)
{
super(throwable);
- this.message = new WeldExceptionMessage(key, args);
+ this.message = new WeldExceptionKeyMessage(key, args);
}
/**
@@ -79,19 +79,7 @@
public WeldException(List<Throwable> errors)
{
super();
- StringBuilder errorMessage = new StringBuilder();
- int i = 0;;
- for (Throwable throwable : errors)
- {
- if (i > 0)
- {
- errorMessage.append('\n');
- }
- errorMessage.append("Exception #").append(i).append(" :");
- errorMessage.append(throwable.getLocalizedMessage());
- i++;
- }
- this.message = new WeldExceptionMessage(errorMessage.toString());
+ this.message = new WeldExceptionListMessage(errors);
}
@Override
Added: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionKeyMessage.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.exceptions;
+
+import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
+
+import java.io.Serializable;
+
+/**
+ * Exception message based on an enumerated key and optional object arguments.
+ * This includes localization of the message based on the settings in the JVM
+ * when the {@link java.lang.Throwable#getMessage()} or
+ * {@link java.lang.Throwable#getLocalizedMessage()} methods are invoked on a
+ * Weld exception.
+ *
+ * @author David Allen
+ */
+public class WeldExceptionKeyMessage implements WeldExceptionMessage, Serializable
+{
+ private static final long serialVersionUID = 3474682221381024558L;
+ private Enum<?> messageKey;
+ private String messageArguments[];
+
+ /**
+ * <p>
+ * Creates a new exception message based on an enumerated message key. This
+ * message will not be localized until it is actually logged or other
+ * software invokes the {@link #getMessage()} method.
+ * </p>
+ *
+ * @param <E> the message key enumeration
+ * @param key the message key from the above enumeration
+ * @param args optional arguments for the message
+ */
+ public <E extends Enum<?>> WeldExceptionKeyMessage(E key, Object... args)
+ {
+ this.messageKey = key;
+ if ((args != null) && (args.length > 0))
+ {
+ this.messageArguments = new String[args.length];
+ int index = 0;
+ for (Object arg : args)
+ {
+ messageArguments[index++] = arg == null ? "null" : arg.toString();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.weld.exceptions.WeldExceptionMessage#getAsString()
+ */
+ public String getAsString()
+ {
+ String result = null;
+ try
+ {
+ result = loggerFactory().getMessageConveyor().getMessage(messageKey, (Object[]) messageArguments);
+ }
+ catch (Exception e)
+ {
+ // We want the using exception to be processed, but also include
+ // this one in its message
+ result = "Exception message for key " + messageKey + " not found due to " + e.getLocalizedMessage();
+ }
+ if (result == null)
+ {
+ result = "Exception message for key " + messageKey + " not found";
+ }
+ return result;
+ }
+
+}
Added: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionListMessage.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.exceptions;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.util.List;
+
+/**
+ * Exception message that produces a list of exceptions and their stack traces
+ * for logging. This is typically used in lifecycle events which accumulate
+ * exceptions across observers.
+ *
+ * @author David Allen
+ *
+ */
+public class WeldExceptionListMessage implements WeldExceptionMessage, Serializable
+{
+
+ private static final long serialVersionUID = 3445187707771082346L;
+
+ private List<Throwable> causes;
+ private String message;
+
+ public WeldExceptionListMessage(List<Throwable> throwables)
+ {
+ this.causes = throwables;
+ }
+
+ public String getAsString()
+ {
+ if (message == null)
+ {
+ generateMessage();
+ }
+ return message;
+ }
+
+ private void generateMessage()
+ {
+ PrintWriter messageBuffer = new PrintWriter(new StringWriter());
+ messageBuffer.print("Exception List with ");
+ messageBuffer.print(causes.size());
+ messageBuffer.print(" exceptions:\n");
+ int i = 0;
+ for (Throwable throwable : causes)
+ {
+ messageBuffer.print("Exception ");
+ messageBuffer.print(i);
+ messageBuffer.print(" :\n");
+ throwable.printStackTrace(messageBuffer);
+ }
+ }
+
+}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -17,101 +17,22 @@
package org.jboss.weld.exceptions;
-import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
-
-import java.io.Serializable;
-
/**
- * <p>
- * The message for exceptions generated by Weld. Each exception contains one
- * message object which will handle the generation of the string message at the
- * time the message is needed. This includes localization of the message based
- * on the settings in the JVM where the {@link java.lang.Throwable#getMessage()}
- * or {@link java.lang.Throwable#getLocalizedMessage()} methods are invoked.
- * </p>
+ * Interface for all exception messages in Weld. This replaces the simple
+ * String used by default in JVM exceptions and allows more complex forms
+ * of messages.
*
* @author David Allen
+ *
*/
-public class WeldExceptionMessage implements Serializable
+public interface WeldExceptionMessage
{
- private static final long serialVersionUID = 2L;
-
/**
- * The string version of the message. This is only used when the original
- * message from a wrapped exception is being used. Since it is already
- * localized, it will simply be stored here and used as the message.
- */
- private String message;
-
- private Enum<?> messageKey;
- private Object messageArguments[];
-
- /**
- * <p>
- * Creates a new exception message initialized to a static message. Use this
- * only for messages generated by third-party software, i.e., those which do
- * not use enumerated message keys.
- * </p>
- *
- * @param message the static message
- */
- public WeldExceptionMessage(String message)
- {
- // This will not be further localized
- this.message = message;
- }
-
- /**
- * <p>
- * Creates a new exception message based on an enumerated message key. This
- * message will not be localized until it is actually logged or other
- * software invokes the {@link #getMessage()} method.
- * </p>
- *
- * @param <E> the message key enumeration
- * @param key the message key from the above enumeration
- * @param args optional arguments for the message
- */
- public <E extends Enum<?>> WeldExceptionMessage(E key, Object... args)
- {
- this.messageKey = key;
- if ((args != null) && (args.length > 0))
- {
- this.messageArguments = new String[args.length];
- int index = 0;
- for (Object arg : args)
- {
- messageArguments[index++] = arg == null ? "null" : arg.toString();
- }
- }
- }
-
- /**
* Generates the localized message for the exception.
*
* @return exception message as a string
*/
- public String getAsString()
- {
- String result = message;
- if (result == null)
- {
- try
- {
- result = loggerFactory().getMessageConveyor().getMessage(messageKey, messageArguments);
- }
- catch (Exception e)
- {
- // We want the using exception to be processed, but also include
- // this one in its message
- result = "Exception message for key " + messageKey + " not found due to " + e.getLocalizedMessage();
- }
- if (result == null)
- {
- result = "Exception message for key " + messageKey + " not found";
- }
- }
- return result;
- }
-}
+ public String getAsString();
+
+}
\ No newline at end of file
Copied: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java (from rev 6162, core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionMessage.java)
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.exceptions;
+
+import java.io.Serializable;
+
+/**
+ * Simple message object that just contains a String already formatted
+ * and localized.
+ *
+ * @author David Allen
+ */
+public class WeldExceptionStringMessage implements Serializable, WeldExceptionMessage
+{
+
+ private static final long serialVersionUID = 2L;
+
+ /**
+ * The string version of the message. This is only used when the original
+ * message from a wrapped exception is being used. Since it is already
+ * localized, it will simply be stored here and used as the message.
+ */
+ private String message;
+
+ /**
+ * <p>
+ * Creates a new exception message initialized to a static message. Use this
+ * only for messages generated by third-party software, i.e., those which do
+ * not use enumerated message keys.
+ * </p>
+ *
+ * @param message the static message
+ */
+ public WeldExceptionStringMessage(String message)
+ {
+ // This will not be further localized
+ this.message = message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.exceptions.WeldExceptionMessage#getAsString()
+ */
+ public String getAsString()
+ {
+ return message;
+ }
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldExceptionStringMessage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2010-04-29 19:24:23 UTC (rev 6196)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2010-04-29 20:01:54 UTC (rev 6197)
@@ -19,7 +19,9 @@
import javax.enterprise.inject.InjectionException;
+import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
import org.jboss.weld.exceptions.WeldExceptionMessage;
+import org.jboss.weld.exceptions.WeldExceptionStringMessage;
/**
* Used for exceptions from the Weld XML parser and provides localization
@@ -37,12 +39,12 @@
public WeldXmlException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionMessage(throwable.getLocalizedMessage());
+ message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
public <E extends Enum<?>> WeldXmlException(E key, Object... args)
{
- message = new WeldExceptionMessage(key, args);
+ message = new WeldExceptionKeyMessage(key, args);
}
@Override
14 years, 8 months
Weld SVN: r6196 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: bean/generic and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-29 15:24:23 -0400 (Thu, 29 Apr 2010)
New Revision: 6196
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/reannotated/
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
remove reannotated stuff (first pass, still needs more cleaning)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -16,38 +16,46 @@
*/
package org.jboss.weld.extensions;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
+
import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Qualifier;
-import org.jboss.weld.extensions.util.BeanImpl;
-import org.jboss.weld.extensions.util.reannotated.AnnotationRedefinition;
-import org.jboss.weld.extensions.util.reannotated.Reannotated;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedMember;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
+import org.jboss.weld.extensions.Exact.ExactLiteral;
+import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.util.annotated.AnnotationBuilder;
+import org.jboss.weld.extensions.util.annotated.MemberAnnotationRedefiner;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.jboss.weld.extensions.util.annotated.Parameter;
+import org.jboss.weld.extensions.util.annotated.ParameterAnnotationRedefiner;
-public class CoreExtension implements Extension
+class CoreExtension implements Extension
{
- Collection<Bean<?>> additionalBeans = new ArrayList<Bean<?>>();
+ private final Collection<Bean<?>> additionalBeans;
+ CoreExtension()
+ {
+ this.additionalBeans = new ArrayList<Bean<?>>();
+ }
+
<X> void processAnnotatedType(@Observes final ProcessAnnotatedType<X> pat, BeanManager bm)
{
if (pat.getAnnotatedType().isAnnotationPresent(Veto.class))
@@ -57,30 +65,23 @@
}
final AnnotatedType<X> at = pat.getAnnotatedType();
+ NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
- ReannotatedType<X> rt = new ReannotatedType<X>(at);
-
// support for @Named packages
Package pkg = at.getJavaClass().getPackage();
if (pkg.isAnnotationPresent(Named.class))
{
final String packageName = getPackageName(pkg);
- if (at.isAnnotationPresent(Named.class))
+
+ builder.redefineMembers(Named.class, new MemberAnnotationRedefiner<Named>()
{
- String className = at.getJavaClass().getSimpleName();
- String beanName = getName(at, className);
- rt.define(new NamedLiteral(packageName + '.' + beanName));
- }
- rt.redefineMembers(Named.class, new AnnotationRedefinition<Named>()
- {
-
- @SuppressWarnings("unchecked")
- public Named redefine(Named annotation, Reannotated reannotated)
+
+ public Named redefine(Named annotation, Member member, AnnotationBuilder annotations)
{
- if (reannotated.isAnnotationPresent(Produces.class))
+ if (annotations.isAnnotationPresent(Produces.class))
{
- String memberName = ((ReannotatedMember<? super X>) reannotated).getJavaMember().getName();
- String beanName = getName(reannotated, memberName);
+ String memberName = member.getName();
+ String beanName = getName(annotation, memberName);
return new NamedLiteral(packageName + '.' + beanName);
}
else
@@ -90,26 +91,31 @@
}
});
+
+ if (at.isAnnotationPresent(Named.class))
+ {
+ String className = at.getJavaClass().getSimpleName();
+ String beanName = getName(at.getAnnotation(Named.class), className);
+ builder.addToClass(new NamedLiteral(packageName + '.' + beanName));
+ }
+
}
// support for @Exact
- Set<Annotation> qualfiers = rt.getAnnotationsWithMetatype(Qualifier.class);
- boolean defaultQualifier = qualfiers.isEmpty() || (qualfiers.size() == 1 && qualfiers.iterator().next().annotationType() == Named.class);
- if (defaultQualifier)
+ Set<Annotation> qualfiers = getAnnotationsWithMetatype(at.getAnnotations(), Qualifier.class);
+ if (qualfiers.isEmpty() || (qualfiers.size() == 1 && qualfiers.iterator().next().annotationType() == Named.class))
{
- rt.define(new AnnotationLiteral<Default>()
- {
- });
+ builder.addToClass(DefaultLiteral.INSTANCE);
}
- rt.define(new ExactLiteral(at.getJavaClass()));
- rt.redefineMembersAndParameters(Exact.class, new AnnotationRedefinition<Exact>()
+ builder.addToClass(new Exact.ExactLiteral(at.getJavaClass()));
+ builder.redefineMembers(Exact.class, new MemberAnnotationRedefiner<Exact>()
{
-
- public Exact redefine(Exact annotation, Reannotated reannotated)
+
+ public Exact redefine(Exact annotation, Member annotated, AnnotationBuilder annotations)
{
if (annotation.value() == void.class)
{
- return new ExactLiteral(reannotated.getJavaClass());
+ return new ExactLiteral(getMemberType(annotated));
}
else
{
@@ -118,43 +124,47 @@
}
});
- pat.setAnnotatedType(rt);
+ builder.redefineMemberParameters(Exact.class, new ParameterAnnotationRedefiner<Exact>()
+ {
+ public Exact redefine(Exact annotation, Parameter annotated, AnnotationBuilder annotations)
+ {
+ if (annotation.value() == void.class)
+ {
+ return new ExactLiteral(getMemberType(annotated.getDeclaringMember()));
+ }
+ else
+ {
+ return annotation;
+ }
+ }
+
+ });
+
+ pat.setAnnotatedType(builder.create());
+
// support for @Constructs
for (AnnotatedConstructor<X> constructor : at.getConstructors())
{
if (constructor.isAnnotationPresent(Constructs.class))
{
- ReannotatedType<X> rtc = new ReannotatedType<X>(at);
+ NewAnnotatedTypeBuilder<X> annotatedTypeBuilder = NewAnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).readAnnotationsFromUnderlying();
// remove class-level @Named annotation
- rtc.redefine(Named.class, new AnnotationRedefinition<Named>()
+ annotatedTypeBuilder.removeFromClass(Named.class);
+ // remove bean constructors annotated @Inject
+ for (AnnotatedConstructor<X> constructor2 : at.getConstructors())
{
-
- public Named redefine(Named annotation, Reannotated reannotated)
- {
- return null;
- }
- });
- // remove bean constructor annotated @Inject
- rtc.redefineConstructors(Inject.class, new AnnotationRedefinition<Inject>()
- {
-
- public Inject redefine(Inject annotation, Reannotated reannotated)
- {
- return null;
- }
- });
+ annotatedTypeBuilder.removeFromConstructor(constructor2.getJavaMember(), Inject.class);
+ }
// make the constructor annotated @Constructs the bean constructor
- rtc.getConstructor(constructor.getJavaMember()).define(new AnnotationLiteral<Inject>()
- {
- });
+ annotatedTypeBuilder.addToConstructor(constructor.getJavaMember(), InjectLiteral.INSTANCE);
// add all the annotations of this constructor to the class
for (Annotation ann : constructor.getAnnotations())
{
- rtc.define(ann);
+ annotatedTypeBuilder.addToClass(ann);
}
-
- additionalBeans.add(new BeanImpl<X>(bm.createInjectionTarget(rtc), rtc));
+ AnnotatedType<X> construtsAnnotatedType = builder.create();
+ additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType, bm).build());
}
}
}
@@ -177,9 +187,9 @@
return packageName;
}
- private <X> String getName(Annotated annotated, String defaultName)
+ private <X> String getName(Named named, String defaultName)
{
- String beanName = annotated.getAnnotation(Named.class).value();
+ String beanName = named.value();
if (beanName.length() == 0)
{
beanName = defaultName.substring(0, 1).toLowerCase() + defaultName.substring(1);
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Exact.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -26,20 +26,39 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
/**
- * An injection point qualifier that may be used to select
- * the exact bean to be injected, by specifying its implementation
- * class.
+ * An injection point qualifier that may be used to select the exact bean to be
+ * injected, by specifying its implementation class.
*
* @author Gavin King
- *
+ *
*/
@Retention(RUNTIME)
-@Target({METHOD, TYPE, FIELD, PARAMETER})
+@Target( { METHOD, TYPE, FIELD, PARAMETER })
@Documented
@Qualifier
-public @interface Exact {
- Class<?> value() default void.class;
+public @interface Exact
+{
+ Class<?> value() default void.class;
+
+ static class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
+ {
+
+ private static final long serialVersionUID = 4907169607105615674L;
+
+ final Class<?> clazz;
+
+ ExactLiteral(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ public Class<?> value()
+ {
+ return clazz;
+ }
+ }
}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/ExactLiteral.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions;
-
-import javax.enterprise.util.AnnotationLiteral;
-
-class ExactLiteral extends AnnotationLiteral<Exact> implements Exact
-{
-
- private static final long serialVersionUID = 4907169607105615674L;
-
- final Class<?> clazz;
-
- ExactLiteral(Class<?> clazz)
- {
- this.clazz = clazz;
- }
-
- public Class<?> value()
- {
- return clazz;
- }
-}
\ No newline at end of file
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -16,6 +16,8 @@
*/
package org.jboss.weld.extensions.bean.generic;
+import static org.jboss.weld.extensions.util.ReflectionUtils.getField;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
@@ -23,12 +25,11 @@
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedField;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
-
/**
* injection target wrapper that injects the configuration for generic beans
*
@@ -53,9 +54,9 @@
private final InjectionTarget<T> delegate;
private final Annotation annotation;
- private final ReannotatedType<T> annotatedType;
+ private final AnnotatedType<T> annotatedType;
- public GenericBeanInjectionTargetWrapper(ReannotatedType<T> annotatedType, InjectionTarget<T> delegate, Annotation annotation)
+ public GenericBeanInjectionTargetWrapper(AnnotatedType<T> annotatedType, InjectionTarget<T> delegate, Annotation annotation)
{
this.annotation = annotation;
this.delegate = delegate;
@@ -69,8 +70,8 @@
if (annotation.annotationType().isAssignableFrom(f.getType()))
{
- ReannotatedField<? super T> reannotatedField = annotatedType.getField(f);
- if (reannotatedField.isAnnotationPresent(InjectConfiguration.class))
+ AnnotatedField<? super T> annotatedField = getField(annotatedType, f);
+ if (annotatedField.isAnnotationPresent(InjectConfiguration.class))
{
try
{
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -41,14 +41,11 @@
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
-import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import org.jboss.weld.extensions.bean.CustomBeanBuilder;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedField;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedParameter;
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
public class GenericExtension implements Extension
{
@@ -92,7 +89,7 @@
event.veto();
}
- //make note of any producer fields that produce generic beans
+ // make note of any producer fields that produce generic beans
for (Object f : type.getFields())
{
AnnotatedField<?> field = (AnnotatedField<?>) f;
@@ -119,7 +116,8 @@
}
/**
- * wraps InjectionTarget to initialise producer fields that produce generic beans
+ * wraps InjectionTarget to initialise producer fields that produce generic
+ * beans
*/
public <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T> event, BeanManager beanManager)
{
@@ -140,111 +138,115 @@
}
/**
- * Installs the generic beans.
+ * Installs the generic beans.
*/
- public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager)
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager)
{
- for (Entry<Class<?>, Set<AnnotatedType<?>>> i : genericBeans.entrySet())
+ for (Entry<Class<?>, Set<AnnotatedType<?>>> entry : genericBeans.entrySet())
{
- Set<Annotation> concretes = concreteGenerics.get(i.getKey());
+ Set<Annotation> concretes = concreteGenerics.get(entry.getKey());
if (concretes != null)
{
- for (AnnotatedType<?> at : i.getValue())
+ for (AnnotatedType<?> type : entry.getValue())
{
for (Annotation conc : concretes)
{
- final SyntheticQualifier newQualifier = getQualifierForGeneric(conc);
- ReannotatedType<?> rt = new ReannotatedType(at);
+ abd.addBean(redefineType(type, conc, beanManager));
+ }
+ }
+ }
+ }
+ }
- rt.define(newQualifier);
- for (AnnotatedField<?> f : rt.getFields())
- {
- ReannotatedField<?> field = (ReannotatedField<?>) f;
+ private <X> Bean<X> redefineType(AnnotatedType<X> at, Annotation conc, BeanManager beanManager)
+ {
+ SyntheticQualifier newQualifier = getQualifierForGeneric(conc);
- if (field.isAnnotationPresent(Inject.class))
- {
- //if this is a configuration injection point
- if (conc.annotationType().isAssignableFrom(field.getJavaMember().getType()))
- {
- field.undefine(Inject.class);
- field.define(new AnnotationLiteral<InjectConfiguration>()
- {
- });
- }
- else
- {
- //check to see if we should be injecting a generic bean
- //we do this by checking if there are any beans that can be injected into this point
- //if there is not then we assume it is a generic injection point
- //this has the downside that if it is actually a deployment error then it will confuse the user
- Annotation[] qls = getQualifiers(field.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qls);
- if (beans.isEmpty())
- {
- field.define(newQualifier);
- }
- }
- }
- else if (field.isAnnotationPresent(Produces.class))
- {
- //TODO: register a producer with the appropriate qualifier
- }
- }
- for (AnnotatedMethod<?> m : rt.getMethods())
- {
- //TODO: need to properly handle Observer methods and Disposal methods
- if (m.isAnnotationPresent(Produces.class))
- {
- //TODO: we need to register the producer bean, so this is not very useful at the moment
- for (AnnotatedParameter<?> pm : m.getParameters())
- {
- ReannotatedParameter<?> param = (ReannotatedParameter<?>) pm;
+ NewAnnotatedTypeBuilder<X> builder = NewAnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlying();
+ builder.addToClass(newQualifier);
+ for (AnnotatedField<? super X> f : at.getFields())
+ {
+ if (f.isAnnotationPresent(Inject.class))
+ {
+ // if this is a configuration injection point
+ if (conc.annotationType().isAssignableFrom(f.getJavaMember().getType()))
+ {
+ builder.removeFromField(f.getJavaMember(), Inject.class);
+ builder.addToField(f.getJavaMember(), InjectConfiguration.INSTANCE);
+ }
+ else
+ {
+ // check to see if we should be injecting a generic bean
+ // we do this by checking if there are any beans that can be
+ // injected into this point
+ // if there is not then we assume it is a generic injection
+ // point
+ // this has the downside that if it is actually a deployment
+ // error then it will confuse the user
+ Annotation[] qls = getQualifiers(f.getAnnotations(), beanManager);
+ Set<Bean<?>> beans = beanManager.getBeans(f.getJavaMember().getType(), qls);
+ if (beans.isEmpty())
+ {
+ builder.addToField(f.getJavaMember(), newQualifier);
+ }
+ }
+ }
+ else if (f.isAnnotationPresent(Produces.class))
+ {
+ // TODO: register a producer with the appropriate qualifier
+ }
+ }
+ for (AnnotatedMethod<?> m : at.getMethods())
+ {
+ // TODO: need to properly handle Observer methods and Disposal
+ // methods
+ if (m.isAnnotationPresent(Produces.class))
+ {
+ // TODO: we need to register the producer bean, so this is not
+ // very useful at the moment
+ for (AnnotatedParameter<?> pm : m.getParameters())
+ {
+ Class<?> paramType = m.getJavaMember().getParameterTypes()[pm.getPosition()];
- Class<?> paramType = m.getJavaMember().getParameterTypes()[param.getPosition()];
+ // check to see if we should be injecting a generic bean
+ // we do this by checking if there are any beans that can be
+ // injected into this point
+ // if there is not then we assume it is a generic injection
+ // point
+ // this has the downside that if it is actually a deployment
+ // error then it will confuse the user
+ Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ if (beans.isEmpty())
+ {
+ builder.addToMethod(m.getJavaMember(), newQualifier);
+ }
+ }
+ }
+ }
- //check to see if we should be injecting a generic bean
- //we do this by checking if there are any beans that can be injected into this point
- //if there is not then we assume it is a generic injection point
- //this has the downside that if it is actually a deployment error then it will confuse the user
- Annotation[] qls = getQualifiers(param.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
- if (beans.isEmpty())
- {
- param.define(newQualifier);
- }
- }
- }
- }
-
- for (AnnotatedConstructor<?> m : rt.getConstructors())
- {
- if (m.isAnnotationPresent(Inject.class))
- {
- for (AnnotatedParameter<?> pm : m.getParameters())
- {
- ReannotatedParameter<?> param = (ReannotatedParameter<?>) pm;
-
- Class paramType = m.getJavaMember().getParameterTypes()[param.getPosition()];
- Annotation[] qls = getQualifiers(param.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
- if (beans.isEmpty())
- {
- param.define(newQualifier);
- }
- }
- }
- }
- InjectionTarget<?> it = beanManager.createInjectionTarget(rt);
-
- it = new GenericBeanInjectionTargetWrapper(rt, it, conc);
- CustomBeanBuilder<?> builder = new CustomBeanBuilder(rt,beanManager,it);
- event.addBean(builder.build());
-
+ for (AnnotatedConstructor<X> m : at.getConstructors())
+ {
+ if (m.isAnnotationPresent(Inject.class))
+ {
+ for (AnnotatedParameter<X> pm : m.getParameters())
+ {
+ Class<?> paramType = m.getJavaMember().getParameterTypes()[pm.getPosition()];
+ Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ if (beans.isEmpty())
+ {
+ builder.addToConstructorParameter(m.getJavaMember(), pm.getPosition(), newQualifier);
}
}
}
}
+ AnnotatedType<X> newAnnotatedType = builder.create();
+ InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
+ it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, conc);
+ CustomBeanBuilder<X> beanBuilder = new CustomBeanBuilder<X>(newAnnotatedType, beanManager, it);
+ return beanBuilder.build();
}
public SyntheticQualifier getQualifierForGeneric(Annotation a)
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/InjectConfiguration.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -19,6 +19,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import javax.enterprise.util.AnnotationLiteral;
+
/**
* synthetic qualifier that is added to Generic beans to signify configuration annotation injection points
*
@@ -28,4 +30,14 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectConfiguration
{
+
+ public static class InjectConfigurationLiteral extends AnnotationLiteral<InjectConfiguration> implements InjectConfiguration
+ {
+
+ private static final long serialVersionUID = 5365615929893138969L;
+
+ }
+
+ public static final InjectConfiguration INSTANCE = new InjectConfigurationLiteral();
+
}
Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanImpl.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -1,152 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.weld.extensions.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Named;
-import javax.inject.Qualifier;
-import javax.inject.Scope;
-
-import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
-
-/**
- * This implementation of Bean is immutable and threadsafe.
- *
- * @author Gavin King
- * @author Pete Muir
- *
- * @param <T>
- */
-public class BeanImpl<T> implements Bean<T>
-{
-
- private final InjectionTarget<T> injectionTarget;
- private final Set<Type> types;
- private final String name;
- private final Set<Annotation> qualifiers;
- private final Class<? extends Annotation> scope;
- private final boolean alternative;
- private final Class<?> beanClass;
-
- public BeanImpl(InjectionTarget<T> it, ReannotatedType<T> rtc)
- {
- // create the Bean
- this.injectionTarget = it;
- // TODO: this stuff does not handle stereotypes
- Set<? extends Annotation> scopes = rtc.getAnnotationsWithMetatype(Scope.class);
- this.scope = scopes.isEmpty() ? Dependent.class : scopes.iterator().next().annotationType();
- if (rtc.isAnnotationPresent(Named.class))
- {
- this.name = rtc.getAnnotation(Named.class).value();
- // no name defaulting for constructors
- if (this.name.length() == 0)
- {
- throw new RuntimeException();
- }
- }
- else
- {
- this.name = null;
- }
- alternative = rtc.isAnnotationPresent(Alternative.class);
- qualifiers = rtc.getAnnotationsWithMetatype(Qualifier.class);
- types = rtc.getTypeClosure();
- beanClass = rtc.getJavaClass();
- }
-
- public BeanImpl(InjectionTarget<T> injectionTarget, Set<Type> types, Set<Annotation> qualifiers, Class<? extends Annotation> scope, String name, boolean alternative, Class<?> beanClass)
- {
- this.injectionTarget = injectionTarget;
- this.types = types;
- this.qualifiers = qualifiers;
- this.scope = scope;
- this.name = name;
- this.alternative = alternative;
- this.beanClass = beanClass;
- // TODO: stereotypes!!!
- }
-
- public Class<?> getBeanClass()
- {
- return beanClass;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return injectionTarget.getInjectionPoints();
- }
-
- public String getName()
- {
- return name;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return Collections.unmodifiableSet(qualifiers);
- }
-
- public Class<? extends Annotation> getScope()
- {
- return scope;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return Collections.emptySet(); // TODO
- }
-
- public Set<Type> getTypes()
- {
- return Collections.unmodifiableSet(types);
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public boolean isNullable()
- {
- return false;
- }
-
- public T create(CreationalContext<T> ctx)
- {
- T instance = injectionTarget.produce(ctx);
- injectionTarget.inject(instance, ctx);
- injectionTarget.postConstruct(instance);
- return instance;
- }
-
- public void destroy(T instance, CreationalContext<T> creationalContext)
- {
- injectionTarget.preDestroy(instance);
- creationalContext.release();
- }
-
-}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -16,12 +16,17 @@
*/
package org.jboss.weld.extensions.util;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
/**
* class that provides a way of retrieving all methods and fields from a class
*
@@ -63,7 +68,33 @@
}
return null;
}
+
+ public static <X> AnnotatedField<? super X> getField(AnnotatedType<X> annotatedType, Field field)
+ {
+ for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
+ {
+ if (annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass()) && annotatedField.getJavaMember().getName().equals(field.getName()))
+ {
+ return annotatedField;
+ }
+ }
+ return null;
+ }
+
+ public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation> annotations, Class<? extends Annotation> metaAnnotationType)
+ {
+ Set<Annotation> set = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ set.add(annotation);
+ }
+ }
+ return set;
+ }
+
public static boolean methodExists(Class<?> parent, String name)
{
Class<?> p = parent;
@@ -134,7 +165,7 @@
public static Set<Constructor<?>> getConstructors(Class<?> clazz)
{
- HashSet<Constructor<?>> ret = new HashSet();
+ HashSet<Constructor<?>> ret = new HashSet<Constructor<?>>();
Class<?> p = clazz;
while (p != null && p != Object.class)
{
@@ -146,4 +177,25 @@
}
return ret;
}
+
+ public static Class<?> getMemberType(Member member)
+ {
+ if (member instanceof Field)
+ {
+ return ((Field) member).getType();
+ }
+ else if (member instanceof Method)
+ {
+ return ((Method) member).getReturnType();
+ }
+ else if (member instanceof Constructor<?>)
+ {
+ return ((Constructor<?>) member).getDeclaringClass();
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Cannot operate on a member of type " + member.getClass());
+ }
+ }
+
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -28,7 +28,7 @@
* @author Stuart Douglas
*
*/
-class AnnotationBuilder
+public class AnnotationBuilder
{
private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
private Set<Annotation> annotationSet = new HashSet<Annotation>();
@@ -90,5 +90,16 @@
{
return (T) annotationMap.get(anType);
}
+
+ public boolean isAnnotationPresent(Class<?> annotationType)
+ {
+ return annotationMap.containsKey(annotationType);
+ }
+
+ @Override
+ public String toString()
+ {
+ return annotationSet.toString();
+ }
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -18,7 +18,7 @@
import java.lang.annotation.Annotation;
-public interface AnnotationRedefiner<X extends Annotation>
+public interface AnnotationRedefiner<T extends Annotation, A>
{
- public X redefine(X annotation, AnnotationBuilder annotations);
+ public T redefine(T annotation, A annotated, AnnotationBuilder annotations);
}
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-04-29 19:00:25 UTC (rev 6195)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-04-29 19:24:23 UTC (rev 6196)
@@ -38,7 +38,7 @@
* Class for constructing a new AnnotatedType. A new instance of builder must be
* used for each annotated type.
*
- * In can either be created with no annotations, or the annotations can be read
+ * In can either be created with no annotations, or the annotations can be read
* from the underlying class or an AnnotatedType
*
* @author Stuart Douglas
@@ -59,136 +59,89 @@
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)
+ public static <X> NewAnnotatedTypeBuilder<X> newInstance(Class<X> underlying)
{
- this(underlying, false);
+ return new NewAnnotatedTypeBuilder<X>(underlying);
}
- public NewAnnotatedTypeBuilder(Class<X> underlying, boolean readAnnotations)
+ public static <X> NewAnnotatedTypeBuilder<X> newInstance(AnnotatedType<X> underlying)
{
+ return new NewAnnotatedTypeBuilder<X>(underlying);
+ }
+
+ protected NewAnnotatedTypeBuilder(Class<X> underlying)
+ {
this.underlying = underlying;
- if (readAnnotations)
- {
- for (Annotation a : underlying.getAnnotations())
- {
- typeAnnotations.add(a);
- }
+ }
- for (Field f : ReflectionUtils.getFields(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f, ab);
- for (Annotation a : f.getAnnotations())
- {
- ab.add(a);
- }
- }
+ protected NewAnnotatedTypeBuilder(AnnotatedType<X> underlying)
+ {
+ this.underlying = underlying.getJavaClass();
- for (Method m : ReflectionUtils.getMethods(underlying))
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- for (Constructor m : underlying.getConstructors())
- {
- AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m, ab);
- for (Annotation a : m.getAnnotations())
- {
- ab.add(a);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(m, mparams);
- for (int i = 0; i < m.getParameterTypes().length; ++i)
- {
- AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(i, mab);
- for (Annotation a : m.getParameterAnnotations()[i])
- {
- mab.add(a);
- }
- }
- }
-
- }
}
- public NewAnnotatedTypeBuilder(AnnotatedType<X> type)
+ public NewAnnotatedTypeBuilder<X> readAnnotationsFromUnderlying()
{
- this.underlying = type.getJavaClass();
- for (Annotation a : type.getAnnotations())
+ for (Annotation a : underlying.getAnnotations())
{
typeAnnotations.add(a);
}
- for (AnnotatedField<? super X> f : type.getFields())
+ for (Field f : ReflectionUtils.getFields(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
- fields.put(f.getJavaMember(), ab);
+ fields.put(f, ab);
+ f.setAccessible(true);
for (Annotation a : f.getAnnotations())
{
ab.add(a);
}
}
- for (AnnotatedMethod<? super X> m : type.getMethods())
+ for (Method m : ReflectionUtils.getMethods(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
- methods.put(m.getJavaMember(), ab);
+ m.setAccessible(true);
+ methods.put(m, ab);
for (Annotation a : m.getAnnotations())
{
ab.add(a);
}
Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
+ methodParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
{
AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
{
mab.add(a);
}
}
}
- for (AnnotatedConstructor<X> m : type.getConstructors())
+ for (Constructor m : underlying.getDeclaredConstructors())
{
AnnotationBuilder ab = new AnnotationBuilder();
- constructors.put(m.getJavaMember(), ab);
+ m.setAccessible(true);
+ constructors.put(m, ab);
for (Annotation a : m.getAnnotations())
{
ab.add(a);
}
Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(m.getJavaMember(), mparams);
- for (AnnotatedParameter<? super X> p : m.getParameters())
+ constructorParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
{
AnnotationBuilder mab = new AnnotationBuilder();
- mparams.put(p.getPosition(), mab);
- for (Annotation a : p.getAnnotations())
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
{
mab.add(a);
}
}
}
-
+ return this;
}
public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
@@ -375,47 +328,57 @@
return this;
}
- public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefine(Class<T> annotationType, AnnotationRedefiner<T> redefinition)
+ public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefineMemberParameters(Class<T> annotationType, ParameterAnnotationRedefiner<T> redefinition)
{
- redefineAnnotationBuilder(annotationType, redefinition, typeAnnotations);
- for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
- {
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
- }
for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
if (params != null)
{
for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(e.getKey(), p.getKey()), p.getValue());
}
}
}
for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
if (params != null)
{
for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
{
- redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ redefineAnnotationBuilder(annotationType, redefinition, new Parameter(e.getKey(), p.getKey()), p.getValue());
}
}
}
return this;
}
+
+ public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T> redefinition)
+ {
+ for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
+ }
+ for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
+ }
+ for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getKey(), e.getValue());
+ }
+ return this;
+ }
- protected <T extends Annotation> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T> redefinition, AnnotationBuilder builder)
+ protected <T extends Annotation, A> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T, A> redefinition, A annotated, AnnotationBuilder builder)
{
T an = builder.getAnnotation(annotationType);
- if(an != null)
+ if (an != null)
{
builder.remove(annotationType);
- T newAn = redefinition.redefine(an, builder);
+ T newAn = redefinition.redefine(an, annotated, builder);
if (newAn != null)
{
builder.add(newAn);
@@ -424,8 +387,10 @@
}
/**
- * merges the annotations from an existing AnnoatedType. If they both have the same annotation
- * on an element overwriteExisting determines which one to keep
+ * merges the annotations from an existing AnnotatedType. If they both have
+ * the same annotation on an element overwriteExisting determines which one
+ * to keep
+ *
* @param type
* @param overwriteExisting
* @return
@@ -461,7 +426,7 @@
methodParameters.put(method.getJavaMember(), params);
}
AnnotationBuilder builder = params.get(p.getPosition());
- if(builder == null)
+ if (builder == null)
{
builder = new AnnotationBuilder();
params.put(p.getPosition(), builder);
@@ -519,17 +484,17 @@
public AnnotatedType<X> create()
{
- Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,AnnotationStore>>();
+ Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer, AnnotationStore>>();
Map<Constructor<X>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, AnnotationStore>();
- Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer,AnnotationStore>>();
+ Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer, AnnotationStore>>();
Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
-
+
for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
{
fieldAnnotations.put(e.getKey(), e.getValue().create());
}
-
+
for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
{
methodAnnotations.put(e.getKey(), e.getValue().create());
@@ -543,7 +508,7 @@
parameterAnnotations.put(pe.getKey(), pe.getValue().create());
}
}
-
+
for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
{
constructorAnnotations.put(e.getKey(), e.getValue().create());
14 years, 8 months