Weld SVN: r5649 - core/trunk/impl/src/main/java/org/jboss/weld/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-01-27 21:26:52 -0500 (Wed, 27 Jan 2010)
New Revision: 5649
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java
Log:
WELD-335 forgot file
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java 2010-01-28 01:36:40 UTC (rev 5648)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java 2010-01-28 02:26:52 UTC (rev 5649)
@@ -26,9 +26,12 @@
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;
@@ -282,7 +285,10 @@
builder.append('(');
Method[] declaredMethods = a.annotationType().getDeclaredMethods();
List<Method> methods = new ArrayList<Method>(declaredMethods.length);
- // TODO Shouldn't the declared methods be added here?
+ for (Method m : declaredMethods)
+ {
+ methods.add(m);
+ }
Collections.sort(methods, MethodComparator.INSTANCE);
for (int i = 0; i < methods.size(); ++i)
@@ -387,6 +393,136 @@
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() != f2.getJavaMember())
+ {
+ return false;
+ }
+ return compareAnnotated(f1, f2);
+ }
+
+ public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
+ {
+ if(m1.getJavaMember() != 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() != t2.getJavaClass())
+ {
+ return false;
+ }
+ if (!compareAnnotated(t1, t2))
+ {
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+
+ }
+
public static <X> String createParameterId(AnnotatedParameter<X> annotatedParameter)
{
return createParameterId(annotatedParameter.getBaseType(), annotatedParameter.getAnnotations());
14 years, 11 months
Weld SVN: r5648 - core/trunk/impl/src/main/java/org/jboss/weld/bean.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-01-27 20:36:40 -0500 (Wed, 27 Jan 2010)
New Revision: 5648
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
Log:
WELD-335
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2010-01-28 00:22:07 UTC (rev 5647)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2010-01-28 01:36:40 UTC (rev 5648)
@@ -29,6 +29,7 @@
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.util.AnnotatedTypes;
/**
* Represents a producer field
@@ -64,7 +65,7 @@
*/
protected ProducerField(WeldField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
- super(new StringBuilder().append(ProducerField.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getWeldAnnotated().getName()).append(".").append(field.getName()).toString(), declaringBean, manager);
+ super(createId(field, declaringBean), declaringBean, manager);
this.field = field;
initType();
initTypes();
@@ -72,6 +73,30 @@
initStereotypes();
}
+ protected static String createId(WeldField<?, ?> field, AbstractClassBean<?> declaringBean)
+ {
+ if (declaringBean.getWeldAnnotated().isDiscovered())
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(ProducerField.class.getSimpleName());
+ sb.append(BEAN_ID_SEPARATOR);
+ sb.append(declaringBean.getWeldAnnotated().getName());
+ sb.append(".");
+ sb.append(field.getName());
+ return sb.toString();
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(ProducerField.class.getSimpleName());
+ sb.append(BEAN_ID_SEPARATOR);
+ sb.append(AnnotatedTypes.createTypeId(declaringBean.getWeldAnnotated()));
+ sb.append(".");
+ sb.append(AnnotatedTypes.createFieldId(field));
+ return sb.toString();
+ }
+ }
+
@Override
public void initialize(BeanDeployerEnvironment environment)
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2010-01-28 00:22:07 UTC (rev 5647)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2010-01-28 01:36:40 UTC (rev 5648)
@@ -42,6 +42,7 @@
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.reflection.SecureReflections;
/**
@@ -79,11 +80,36 @@
initType();
initTypes();
initQualifiers();
- this.id = new StringBuilder().append(BEAN_ID_PREFIX).append(getClass().getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getWeldAnnotated().getName()).append(getWeldAnnotated().getSignature().toString()).toString();
+ this.id = createId(method, declaringBean);
initStereotypes();
initProducerMethodInjectableParameters();
}
+ protected String createId(WeldMethod<T, X> method, AbstractClassBean<X> declaringBean)
+ {
+ if (declaringBean.getWeldAnnotated().isDiscovered())
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(BEAN_ID_PREFIX);
+ sb.append(ProducerMethod.class.getSimpleName());
+ sb.append(BEAN_ID_SEPARATOR);
+ sb.append(declaringBean.getWeldAnnotated().getName());
+ sb.append(getWeldAnnotated().getSignature().toString());
+ return sb.toString();
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(BEAN_ID_PREFIX);
+ sb.append(ProducerMethod.class.getSimpleName());
+ sb.append(BEAN_ID_SEPARATOR);
+ sb.append(AnnotatedTypes.createTypeId(declaringBean.getWeldAnnotated()));
+ sb.append(AnnotatedTypes.createCallableId(method));
+ return sb.toString();
+ }
+
+ }
+
/**
* Initializes the bean and its metadata
*/
14 years, 11 months
Weld SVN: r5647 - in core/trunk: impl/src/main/java/org/jboss/weld/introspector/jlr and 4 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-27 19:22:07 -0500 (Wed, 27 Jan 2010)
New Revision: 5647
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Clothes.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Coins.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/HotAir.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/InjectLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Original.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Plug.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/RunningTime.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SerialNumber.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Special.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SpecialLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/TumbleDryer.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/util_en.properties
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java
Log:
WELD-372, still needs work on verifying parameters
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-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/impl/src/main/java/org/jboss/weld/exceptions/WeldException.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -80,14 +80,16 @@
{
super();
StringBuilder errorMessage = new StringBuilder();
- boolean firstError = true;
+ int i = 0;;
for (Throwable throwable : errors)
{
- if (!firstError)
+ if (i > 0)
{
errorMessage.append('\n');
}
+ errorMessage.append("Exception #").append(i).append(" :");
errorMessage.append(throwable.getLocalizedMessage());
+ i++;
}
this.message = new WeldExceptionMessage(errorMessage.toString());
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -23,6 +23,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -35,6 +36,7 @@
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.bootstrap.events.ExternalAnnotatedType;
@@ -66,7 +68,19 @@
*/
public class WeldClassImpl<T> extends AbstractWeldAnnotated<T, Class<T>> implements WeldClass<T>
{
-
+
+ private static <T> void mapConstructorAnnotations(SetMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors, WeldConstructor<T> annotatedConstructor)
+ {
+ for (Annotation annotation : annotatedConstructor.getAnnotations())
+ {
+ if (!annotatedConstructors.containsKey(annotation.annotationType()))
+ {
+ annotatedConstructors.putAll(annotation.annotationType(), new HashSet<WeldConstructor<T>>());
+ }
+ annotatedConstructors.get(annotation.annotationType()).add(annotatedConstructor);
+ }
+ }
+
// Class attributes
private final WeldClass<?> superclass;
@@ -104,7 +118,7 @@
private final SetMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors;
// The map from class list to abstracted constructor
private final Map<List<Class<?>>, WeldConstructor<T>> constructorsByArgumentMap;
-
+
// The meta-annotation map (annotation type -> set of annotations containing
// meta-annotation) of the item
private final SetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
@@ -156,51 +170,60 @@
this.declaredAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, T>>>(), HashSetSupplier.<WeldField<?, T>> instance());
this.declaredMetaAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ?>>>(), HashSetSupplier.<WeldField<?, ?>> instance());
- Map<Field, AnnotatedField<? super T>> annotatedTypeFields = new HashMap<Field, AnnotatedField<? super T>>();
- if (annotatedType != null)
+ if (annotatedType == null)
{
- for (AnnotatedField<? super T> annotatedField : annotatedType.getFields())
+ for (Class<?> c = rawType; c != Object.class && c != null; c = c.getSuperclass())
{
- annotatedTypeFields.put(annotatedField.getJavaMember(), annotatedField);
+ for (Field field : SecureReflections.getDeclaredFields(c))
+ {
+ WeldField<?, T> annotatedField = WeldFieldImpl.of(field, this.<T> getDeclaringWeldClass(field, classTransformer), classTransformer);
+ this.fields.add(annotatedField);
+ if (c == rawType)
+ {
+ this.declaredFields.add(annotatedField);
+ this.declaredFieldsByName.put(annotatedField.getName(), annotatedField);
+ }
+ for (Annotation annotation : annotatedField.getAnnotations())
+ {
+ this.annotatedFields.put(annotation.annotationType(), annotatedField);
+ if (c == rawType)
+ {
+ this.declaredAnnotatedFields.put(annotation.annotationType(), annotatedField);
+ }
+ for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
+ {
+ if (c == rawType)
+ {
+ this.declaredMetaAnnotatedFields.put(metaAnnotation.annotationType(), annotatedField);
+ }
+ }
+ }
+ }
}
}
-
- for (Class<?> c = rawType; c != Object.class && c != null; c = c.getSuperclass())
+ else
{
- for (Field field : SecureReflections.getDeclaredFields(c))
+ for (AnnotatedField<? super T> field : annotatedType.getFields())
{
- WeldField<?, T> annotatedField = null;
- if (annotatedTypeFields.containsKey(field))
+ WeldField<?, T> weldField = WeldFieldImpl.of(field, this.<T> getDeclaringWeldClass(field.getJavaMember(), classTransformer), classTransformer);
+ this.fields.add(weldField);
+ if (field.getDeclaringType().getJavaClass() == rawType)
{
- annotatedField = WeldFieldImpl.of(annotatedTypeFields.get(field), this.<T> getDeclaringWBClass(field, classTransformer), classTransformer);
+ this.declaredFields.add(weldField);
+ this.declaredFieldsByName.put(weldField.getName(), weldField);
}
- else
+ for (Annotation annotation : weldField.getAnnotations())
{
- annotatedField = WeldFieldImpl.of(field, this.<T> getDeclaringWBClass(field, classTransformer), classTransformer);
- }
-
- this.fields.add(annotatedField);
- if (c == rawType)
- {
- this.declaredFields.add(annotatedField);
- this.declaredFieldsByName.put(annotatedField.getName(), annotatedField);
- }
- for (Annotation annotation : annotatedField.getAnnotations())
- {
- this.annotatedFields.put(annotation.annotationType(), annotatedField);
- if (c == rawType)
+ this.annotatedFields.put(annotation.annotationType(), weldField);
+ if (field.getDeclaringType().getJavaClass() == rawType)
{
- this.declaredAnnotatedFields.put(annotation.annotationType(), annotatedField);
- }
- for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
- {
- if (c == rawType)
+ this.declaredAnnotatedFields.put(annotation.annotationType(), weldField);
+ for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
{
- this.declaredMetaAnnotatedFields.put(metaAnnotation.annotationType(), annotatedField);
+ this.declaredMetaAnnotatedFields.put(metaAnnotation.annotationType(), weldField);
}
}
}
-
}
}
@@ -209,43 +232,38 @@
this.constructorsByArgumentMap = new HashMap<List<Class<?>>, WeldConstructor<T>>();
this.annotatedConstructors = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldConstructor<T>>>(), HashSetSupplier.<WeldConstructor<T>> instance());
- Map<Constructor<? super T>, AnnotatedConstructor<T>> annotatedTypeConstructors = new HashMap<Constructor<? super T>, AnnotatedConstructor<T>>();
- if (annotatedType != null)
+ this.declaredConstructorsBySignature = new HashMap<ConstructorSignature, WeldConstructor<?>>();
+ if (annotatedType == null)
{
- for (AnnotatedConstructor<T> annotated : annotatedType.getConstructors())
+ for (Constructor<?> constructor : SecureReflections.getDeclaredConstructors(rawType))
{
- annotatedTypeConstructors.put(annotated.getJavaMember(), annotated);
+ @SuppressWarnings("unchecked")
+ Constructor<T> c = (Constructor<T>) constructor;
+
+ WeldConstructor<T> annotatedConstructor = WeldConstructorImpl.of(c, this.<T> getDeclaringWeldClass(c, classTransformer), classTransformer);
+ this.constructors.add(annotatedConstructor);
+ this.constructorsByArgumentMap.put(Arrays.asList(constructor.getParameterTypes()), annotatedConstructor);
+ this.declaredConstructorsBySignature.put(annotatedConstructor.getSignature(), annotatedConstructor);
+ mapConstructorAnnotations(annotatedConstructors, annotatedConstructor);
}
}
-
- this.declaredConstructorsBySignature = new HashMap<ConstructorSignature, WeldConstructor<?>>();
- for (Constructor<?> constructor : SecureReflections.getDeclaredConstructors(rawType))
+ else
{
- WeldConstructor<T> annotatedConstructor = null;
- if (annotatedTypeConstructors.containsKey(constructor))
+ for (AnnotatedConstructor<T> constructor : annotatedType.getConstructors())
{
- WeldClass<T> declaringClass = this.getDeclaringWBClass(constructor, classTransformer);
- annotatedConstructor = WeldConstructorImpl.of(annotatedTypeConstructors.get(constructor), declaringClass, classTransformer);
- }
- else
- {
- // TODO Fix this cast
- Constructor<T> c = (Constructor<T>) constructor;
- annotatedConstructor = WeldConstructorImpl.of(c, this.<T> getDeclaringWBClass(c, classTransformer), classTransformer);
- }
+ WeldClass<T> declaringClass = this.getDeclaringWeldClass(constructor.getJavaMember(), classTransformer);
+ WeldConstructor<T> weldConstructor = WeldConstructorImpl.of(constructor, declaringClass, classTransformer);
- this.constructors.add(annotatedConstructor);
- this.constructorsByArgumentMap.put(Arrays.asList(constructor.getParameterTypes()), annotatedConstructor);
+ this.constructors.add(weldConstructor);
- this.declaredConstructorsBySignature.put(annotatedConstructor.getSignature(), annotatedConstructor);
-
- for (Annotation annotation : annotatedConstructor.getAnnotations())
- {
- if (!annotatedConstructors.containsKey(annotation.annotationType()))
+ List<Class<?>> parameterTypes = new ArrayList<Class<?>>();
+ for (AnnotatedParameter<T> parameter : constructor.getParameters())
{
- annotatedConstructors.putAll(annotation.annotationType(), new HashSet<WeldConstructor<T>>());
+ parameterTypes.add(Reflections.getRawType(parameter.getBaseType()));
}
- annotatedConstructors.get(annotation.annotationType()).add(annotatedConstructor);
+ this.constructorsByArgumentMap.put(parameterTypes, weldConstructor);
+ this.declaredConstructorsBySignature.put(weldConstructor.getSignature(), weldConstructor);
+ mapConstructorAnnotations(annotatedConstructors, weldConstructor);
}
}
@@ -258,57 +276,75 @@
this.declaredMethodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
this.methodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
- Map<Method, AnnotatedMethod<?>> annotatedTypeMethods = new HashMap<Method, AnnotatedMethod<?>>();
- if (annotatedType != null)
+ if (annotatedType == null)
{
- for (AnnotatedMethod<?> annotated : annotatedType.getMethods())
+ for (Class<?> c = rawType; c != Object.class && c != null; c = c.getSuperclass())
{
- annotatedTypeMethods.put(annotated.getJavaMember(), annotated);
+ for (Method method : SecureReflections.getDeclaredMethods(c))
+ {
+ WeldMethod<?, T> weldMethod = WeldMethodImpl.of(method, this.<T> getDeclaringWeldClass(method, classTransformer), classTransformer);
+ this.methods.add(weldMethod);
+ this.methodsBySignature.put(weldMethod.getSignature(), weldMethod);
+ if (c == rawType)
+ {
+ this.declaredMethods.add(weldMethod);
+ this.declaredMethodsBySignature.put(weldMethod.getSignature(), weldMethod);
+ }
+ for (Annotation annotation : weldMethod.getAnnotations())
+ {
+ annotatedMethods.put(annotation.annotationType(), weldMethod);
+ if (c == rawType)
+ {
+ this.declaredAnnotatedMethods.put(annotation.annotationType(), weldMethod);
+ }
+ }
+ for (Class<? extends Annotation> annotationType : WeldMethod.MAPPED_PARAMETER_ANNOTATIONS)
+ {
+ if (weldMethod.getWeldParameters(annotationType).size() > 0)
+ {
+ if (c == rawType)
+ {
+ this.declaredMethodsByAnnotatedParameters.put(annotationType, weldMethod);
+ }
+ }
+ }
+ }
}
}
-
- for (Class<?> c = rawType; c != Object.class && c != null; c = c.getSuperclass())
+ else
{
- for (Method method : SecureReflections.getDeclaredMethods(c))
+ for (AnnotatedMethod<? super T> method : annotatedType.getMethods())
{
- WeldMethod<?, T> annotatedMethod = null;
- if (annotatedTypeMethods.containsKey(method))
+ WeldMethod<?, T> weldMethod = WeldMethodImpl.of(method, this, classTransformer);
+ this.methods.add(weldMethod);
+ this.methodsBySignature.put(weldMethod.getSignature(), weldMethod);
+ if (method.getDeclaringType().getJavaClass() == rawType)
{
- annotatedMethod = WeldMethodImpl.of(annotatedTypeMethods.get(method), this, classTransformer);
+ this.declaredMethods.add(weldMethod);
+ this.declaredMethodsBySignature.put(weldMethod.getSignature(), weldMethod);
}
- else
+ for (Annotation annotation : weldMethod.getAnnotations())
{
- annotatedMethod = WeldMethodImpl.of(method, this.<T> getDeclaringWBClass(method, classTransformer), classTransformer);
- }
- this.methods.add(annotatedMethod);
- this.methodsBySignature.put(annotatedMethod.getSignature(), annotatedMethod);
- if (c == rawType)
- {
- this.declaredMethods.add(annotatedMethod);
- this.declaredMethodsBySignature.put(annotatedMethod.getSignature(), annotatedMethod);
- }
- for (Annotation annotation : annotatedMethod.getAnnotations())
- {
- annotatedMethods.put(annotation.annotationType(), annotatedMethod);
- if (c == rawType)
+ annotatedMethods.put(annotation.annotationType(), weldMethod);
+ if (method.getDeclaringType().getJavaClass() == rawType)
{
- this.declaredAnnotatedMethods.put(annotation.annotationType(), annotatedMethod);
+ this.declaredAnnotatedMethods.put(annotation.annotationType(), weldMethod);
}
}
for (Class<? extends Annotation> annotationType : WeldMethod.MAPPED_PARAMETER_ANNOTATIONS)
{
- if (annotatedMethod.getWeldParameters(annotationType).size() > 0)
+ if (weldMethod.getWeldParameters(annotationType).size() > 0)
{
- if (c == rawType)
+ if (method.getDeclaringType().getJavaClass() == rawType)
{
- this.declaredMethodsByAnnotatedParameters.put(annotationType, annotatedMethod);
+ this.declaredMethodsByAnnotatedParameters.put(annotationType, weldMethod);
}
}
}
}
}
-
- this.declaredMetaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
+
+ this.declaredMetaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation> instance());
for (Annotation declaredAnnotation : declaredAnnotationMap.values())
{
addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, declaredAnnotation.annotationType().getAnnotations(), true);
@@ -318,7 +354,7 @@
}
@SuppressWarnings("unchecked")
- private <X> WeldClass<X> getDeclaringWBClass(Member member, ClassTransformer transformer)
+ private <X> WeldClass<X> getDeclaringWeldClass(Member member, ClassTransformer transformer)
{
if (member.getDeclaringClass().equals(getJavaClass()))
{
@@ -636,7 +672,7 @@
{
return (Set) methods;
}
-
+
public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
return Collections.unmodifiableSet(declaredMetaAnnotationMap.get(metaAnnotationType));
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -672,7 +672,7 @@
{
if (initializerAnnotatedConstructors.size() > 1)
{
- throw new DefinitionException(AMBIGUOUS_CONSTRUCTOR, type);
+ throw new DefinitionException(AMBIGUOUS_CONSTRUCTOR, type, initializerAnnotatedConstructors);
}
}
else if (initializerAnnotatedConstructors.size() == 1)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -635,5 +635,22 @@
{
return clazz.isPrimitive() || Serializable.class.isAssignableFrom(clazz);
}
+
+ @SuppressWarnings("unchecked")
+ public static <T> Class<T> getRawType(Type type)
+ {
+ if (type instanceof Class<?>)
+ {
+ return (Class<T>) type;
+ }
+ else if (type instanceof ParameterizedType)
+ {
+ if (((ParameterizedType) type).getRawType() instanceof Class<?>)
+ {
+ return (Class<T>) ((ParameterizedType) type).getRawType();
+ }
+ }
+ return null;
+ }
}
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/util_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/util_en.properties 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/util_en.properties 2010-01-28 00:22:07 UTC (rev 5647)
@@ -10,8 +10,8 @@
INITIALIZER_CANNOT_BE_OBSERVER=Initializer method {0} cannot be annotated @Observes on {1}
QUALIFIER_ON_FINAL_FIELD=Cannot place qualifiers on final fields: {0}
TOO_MANY_INITIALIZERS=Cannot have more than one constructor annotated with @Initializer for {0}
-AMBIGUOUS_CONSTRUCTOR=Cannot determine constructor to use for {0}
-INVALID_QUANTITY_INJECTABLE_FIELDS_AND_INITIALIZER_METHODS=injectableFields and initializerMethods must have the same size.\\n\\nInjectable Fields: {0}\\nInitializerMethods: {1}
+AMBIGUOUS_CONSTRUCTOR=Cannot determine constructor to use for {0}. Possible constructors {1}
+INVALID_QUANTITY_INJECTABLE_FIELDS_AND_INITIALIZER_METHODS=injectableFields and initializerMethods must have the same size.\\n\\nInjectable Fields\: {0}\\nInitializerMethods\: {1}
ANNOTATION_NOT_QUALIFIER=Annotation {0} is not a qualifier
REDUNDANT_QUALIFIER=Qualifier {0} is already present in the set {1}
UNABLE_TO_FIND_CONSTRUCTOR=Cannot determine constructor to use for {0}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -17,36 +17,435 @@
package org.jboss.weld.tests.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.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.enterprise.event.Observes;
+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;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
import org.jboss.weld.tests.extensions.annotatedType.EcoFriendlyWashingMachine.EcoFriendlyWashingMachineLiteral;
+import org.jboss.weld.util.collections.Arrays2;
public class AnnotatedTypeExtension implements Extension
{
+ public void addTumbleDryer(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+ {
+
+ final Set<AnnotatedConstructor<TumbleDryer>> constructors = new HashSet<AnnotatedConstructor<TumbleDryer>>();
+ final Set<AnnotatedField<? super TumbleDryer>> fields = new HashSet<AnnotatedField<? super TumbleDryer>>();
+ final Set<AnnotatedMethod<? super TumbleDryer>> methods = new HashSet<AnnotatedMethod<? super TumbleDryer>>();
+
+ final AnnotatedType<TumbleDryer> tumbleDryer = new AnnotatedType<TumbleDryer>()
+ {
+
+ public Set<AnnotatedConstructor<TumbleDryer>> getConstructors()
+ {
+ return constructors;
+ }
+
+ public Set<AnnotatedField<? super TumbleDryer>> getFields()
+ {
+ return fields;
+ }
+
+ public Set<AnnotatedMethod<? super TumbleDryer>> getMethods()
+ {
+ return methods;
+ }
+
+ // Now the easy stuff
+
+ public Class<TumbleDryer> getJavaClass()
+ {
+ return TumbleDryer.class;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ // Class has no annotations
+ return null;
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.emptySet();
+ }
+
+ public Type getBaseType()
+ {
+ return TumbleDryer.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(TumbleDryer.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ // Class has no annotations
+ return false;
+ }
+
+ };
+
+ AnnotatedField<TumbleDryer> plug = new AnnotatedField<TumbleDryer>()
+ {
+
+ public Field getJavaMember()
+ {
+ try
+ {
+ return TumbleDryer.class.getDeclaredField("plug");
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public boolean isStatic()
+ {
+ return false;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ if (annotationType.equals(Inject.class))
+ {
+ return annotationType.cast(InjectLiteral.INSTANCE);
+ }
+ else if (annotationType.equals(Special.class))
+ {
+ return annotationType.cast(SpecialLiteral.INSTANCE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Arrays2.asSet(InjectLiteral.INSTANCE, SpecialLiteral.INSTANCE);
+ }
+
+ public Type getBaseType()
+ {
+ return Plug.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(Plug.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType.equals(Inject.class) || annotationType.equals(Special.class))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public AnnotatedType<TumbleDryer> getDeclaringType()
+ {
+ return tumbleDryer;
+ }
+ };
+ fields.add(plug);
+
+
+ final List<AnnotatedParameter<TumbleDryer>> runningTimeParameters = new ArrayList<AnnotatedParameter<TumbleDryer>>();
+ final AnnotatedMethod<TumbleDryer> runningTimeMethod = new AnnotatedMethod<TumbleDryer>()
+ {
+
+ public Method getJavaMember()
+ {
+ try
+ {
+ return TumbleDryer.class.getDeclaredMethod("setRunningTime", RunningTime.class);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public List<AnnotatedParameter<TumbleDryer>> getParameters()
+ {
+ return runningTimeParameters;
+ }
+
+ public AnnotatedType<TumbleDryer> getDeclaringType()
+ {
+ return tumbleDryer;
+ }
+
+ public boolean isStatic()
+ {
+ return false;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ if (annotationType.equals(Inject.class))
+ {
+ return annotationType.cast(InjectLiteral.INSTANCE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.<Annotation>singleton(InjectLiteral.INSTANCE);
+ }
+
+ public Type getBaseType()
+ {
+ return TumbleDryer.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(TumbleDryer.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType.equals(Inject.class))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ };
+ methods.add(runningTimeMethod);
+
+ final AnnotatedParameter<TumbleDryer> runningTimeParameter = new AnnotatedParameter<TumbleDryer>()
+ {
+
+ public AnnotatedCallable<TumbleDryer> getDeclaringCallable()
+ {
+ return runningTimeMethod;
+ }
+
+ public int getPosition()
+ {
+ return 0;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ if (annotationType.equals(Special.class))
+ {
+ return annotationType.cast(SpecialLiteral.INSTANCE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.<Annotation>singleton(SpecialLiteral.INSTANCE);
+ }
+
+ public Type getBaseType()
+ {
+ return RunningTime.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Collections.<Type>singleton(RunningTime.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType.equals(Special.class))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ };
+ runningTimeParameters.add(runningTimeParameter);
+
+ final List<AnnotatedParameter<TumbleDryer>> clothesParameters = new ArrayList<AnnotatedParameter<TumbleDryer>>();
+ final AnnotatedConstructor<TumbleDryer> clothesConstructor = new AnnotatedConstructor<TumbleDryer>()
+ {
+
+ public Constructor<TumbleDryer> getJavaMember()
+ {
+ try
+ {
+ return TumbleDryer.class.getDeclaredConstructor(Clothes.class);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public List<AnnotatedParameter<TumbleDryer>> getParameters()
+ {
+ return clothesParameters;
+ }
+
+ public AnnotatedType<TumbleDryer> getDeclaringType()
+ {
+ return tumbleDryer;
+ }
+
+ public boolean isStatic()
+ {
+ return false;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ if (annotationType.equals(Inject.class))
+ {
+ return annotationType.cast(InjectLiteral.INSTANCE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.<Annotation>singleton(InjectLiteral.INSTANCE);
+ }
+
+ public Type getBaseType()
+ {
+ return TumbleDryer.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(TumbleDryer.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType.equals(Inject.class))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ };
+ constructors.add(clothesConstructor);
+
+ AnnotatedParameter<TumbleDryer> clothesParameter = new AnnotatedParameter<TumbleDryer>()
+ {
+
+ public AnnotatedCallable<TumbleDryer> getDeclaringCallable()
+ {
+ return clothesConstructor;
+ }
+
+ public int getPosition()
+ {
+ return 0;
+ }
+
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ if (annotationType.equals(Special.class))
+ {
+ return annotationType.cast(SpecialLiteral.INSTANCE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.<Annotation>singleton(SpecialLiteral.INSTANCE);
+ }
+
+ public Type getBaseType()
+ {
+ return Clothes.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(Clothes.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ if (annotationType.equals(Special.class))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ };
+ clothesParameters.add(clothesParameter);
+
+ beforeBeanDiscovery.addAnnotatedType(tumbleDryer);
+ }
+
/**
* Adds an eco friendly wasing machine
* @param beforeBeanDiscovery
*/
public void addWashingMachine(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
- beforeBeanDiscovery.addAnnotatedType(new AnnotatedType<WashingMachine>()
+ final Set<AnnotatedConstructor<WashingMachine>> constructors = new HashSet<AnnotatedConstructor<WashingMachine>>();
+ final AnnotatedType<WashingMachine> type = new AnnotatedType<WashingMachine>()
{
public Set<AnnotatedConstructor<WashingMachine>> getConstructors()
{
- return Collections.emptySet();
+ return constructors;
}
public Set<AnnotatedField<? super WashingMachine>> getFields()
@@ -85,10 +484,7 @@
public Set<Type> getTypeClosure()
{
- Set<Type> ret = new HashSet<Type>();
- ret.add(Object.class);
- ret.add(WashingMachine.class);
- return ret;
+ return Arrays2.<Type>asSet(WashingMachine.class, Object.class);
}
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
@@ -96,6 +492,65 @@
return annotationType == EcoFriendlyWashingMachine.class;
}
- });
+ };
+
+ final AnnotatedConstructor<WashingMachine> constructor = new AnnotatedConstructor<WashingMachine>()
+ {
+
+ public Constructor<WashingMachine> getJavaMember()
+ {
+ try
+ {
+ return WashingMachine.class.getDeclaredConstructor();
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public List<AnnotatedParameter<WashingMachine>> getParameters()
+ {
+ return Collections.emptyList();
+ }
+
+ public AnnotatedType<WashingMachine> getDeclaringType()
+ {
+ return type;
+ }
+
+ public boolean isStatic()
+ {
+ return false;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ return null;
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.emptySet();
+ }
+
+ public Type getBaseType()
+ {
+ return WashingMachine.class;
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return Arrays2.<Type>asSet(WashingMachine.class, Object.class);
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return false;
+ }
+ };
+ constructors.add(constructor);
+
+ beforeBeanDiscovery.addAnnotatedType(type);
}
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java 2010-01-27 20:25:08 UTC (rev 5646)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -16,13 +16,21 @@
*/
package org.jboss.weld.tests.extensions.annotatedType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Set;
+
import javax.enterprise.inject.Any;
+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.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
-import org.jboss.testharness.impl.packaging.Packaging;
-import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.testharness.impl.packaging.jsr299.Extension;
import org.jboss.weld.test.AbstractWeldTest;
import org.jboss.weld.test.Utils;
@@ -31,7 +39,6 @@
@Artifact
@IntegrationTest
-(a)Packaging(PackagingType.EAR)
@Extension("javax.enterprise.inject.spi.Extension")
public class AnnotatedTypeExtensionTest extends AbstractWeldTest
{
@@ -49,7 +56,102 @@
{
Bean<WashingMachine> bean = getBean(WashingMachine.class, EcoFriendlyWashingMachineLiteral.INSTANCE);
assert Utils.annotationSetMatches(bean.getQualifiers(), Any.class, EcoFriendlyWashingMachine.class);
+
+ // Verify overriding the class structure works
+ Clothes.reset();
+ TumbleDryer tumbleDryer = getReference(TumbleDryer.class);
+ Bean<TumbleDryer> tumbleDryerBean = getBean(TumbleDryer.class);
+ assert tumbleDryer != null;
+
+ assert !containsConstructor(tumbleDryerBean.getInjectionPoints(), SerialNumber.class);
+ assert containsConstructor(tumbleDryerBean.getInjectionPoints(), Clothes.class);
+ assert tumbleDryer.getSerialNumber() == null;
+ assert tumbleDryer.getClothes() != null;
+ assert !Clothes.getInjectionPoint().getAnnotated().isAnnotationPresent(Original.class);
+ AnnotatedConstructor<?> clothesConstructor = getConstructor(tumbleDryerBean.getInjectionPoints(), Clothes.class);
+ assert clothesConstructor.getParameters().get(0).isAnnotationPresent(Special.class);
+ assert !clothesConstructor.getParameters().get(0).isAnnotationPresent(Original.class);
+
+ assert containsField(tumbleDryerBean.getInjectionPoints(), "plug");
+ assert !containsField(tumbleDryerBean.getInjectionPoints(), "coins");
+ assert tumbleDryer.getPlug() != null;
+ assert tumbleDryer.getCoins() == null;
+
+ assert containsMethod(tumbleDryerBean.getInjectionPoints(), "setRunningTime", RunningTime.class);
+ assert !containsMethod(tumbleDryerBean.getInjectionPoints(), "setHotAir", HotAir.class);
+ assert tumbleDryer.getRunningTime() != null;
+ assert tumbleDryer.getHotAir() == null;
+ AnnotatedMethod<?> runningTimeMethod = getMethod(tumbleDryerBean.getInjectionPoints(), "setRunningTime", RunningTime.class);
+ assert runningTimeMethod.getParameters().get(0).isAnnotationPresent(Special.class);
+ assert !runningTimeMethod.getParameters().get(0).isAnnotationPresent(Original.class);
}
+ private static boolean containsField(Set<InjectionPoint> injectionPoints, String name)
+ {
+ for (InjectionPoint ip : injectionPoints)
+ {
+ if (ip.getAnnotated() instanceof AnnotatedField<?>)
+ {
+ AnnotatedField<?> field = (AnnotatedField<?>) ip.getAnnotated();
+ if (field.getJavaMember().getName().equals(name))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean containsConstructor(Set<InjectionPoint> injectionPoints, Class<?>... parameters)
+ {
+ return getConstructor(injectionPoints, parameters) != null;
+ }
+
+ private static AnnotatedConstructor<?> getConstructor(Set<InjectionPoint> injectionPoints, Class<?>... parameters)
+ {
+ for (InjectionPoint ip : injectionPoints)
+ {
+ if (ip.getAnnotated() instanceof AnnotatedParameter<?>)
+ {
+ AnnotatedParameter<?> param = (AnnotatedParameter<?>) ip.getAnnotated();
+ if (param.getDeclaringCallable() instanceof AnnotatedConstructor<?>)
+ {
+ Class<?>[] parameterTypes = ((Constructor<?>) param.getDeclaringCallable().getJavaMember()).getParameterTypes();
+ if (Arrays.equals(parameters, parameterTypes))
+ {
+ return (AnnotatedConstructor<?>) param.getDeclaringCallable();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static boolean containsMethod(Set<InjectionPoint> injectionPoints, String name, Class<?>... parameters)
+ {
+ return getMethod(injectionPoints, name, parameters) != null;
+ }
+
+ private static AnnotatedMethod<?> getMethod(Set<InjectionPoint> injectionPoints, String name, Class<?>... parameters)
+ {
+ for (InjectionPoint ip : injectionPoints)
+ {
+ if (ip.getAnnotated() instanceof AnnotatedParameter<?>)
+ {
+ AnnotatedParameter<?> param = (AnnotatedParameter<?>) ip.getAnnotated();
+ if (param.getDeclaringCallable() instanceof AnnotatedMethod<?>)
+ {
+ Class<?>[] parameterTypes = ((Method) param.getDeclaringCallable().getJavaMember()).getParameterTypes();
+ String methodName = param.getDeclaringCallable().getJavaMember().getName();
+ if (Arrays.equals(parameters, parameterTypes) && methodName.equals(name))
+ {
+ return (AnnotatedMethod<?>) param.getDeclaringCallable();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Clothes.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Clothes.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Clothes.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+@Special
+public class Clothes
+{
+
+ private static InjectionPoint injectionPoint;
+
+ @Inject
+ public void setInjectionPoint(InjectionPoint injectionPoint)
+ {
+ Clothes.injectionPoint = injectionPoint;
+ }
+
+ public static void reset()
+ {
+ injectionPoint = null;
+ }
+
+ public static InjectionPoint getInjectionPoint()
+ {
+ return injectionPoint;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Clothes.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Coins.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Coins.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Coins.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,6 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+public class Coins
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Coins.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/HotAir.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/HotAir.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/HotAir.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,6 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+public class HotAir
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/HotAir.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/InjectLiteral.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/InjectLiteral.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/InjectLiteral.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,29 @@
+/*
+ * 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.tests.extensions.annotatedType;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+
+public class InjectLiteral extends AnnotationLiteral<Inject> implements Inject
+{
+
+ public static final Inject INSTANCE = new InjectLiteral();
+
+ private InjectLiteral() {}
+
+}
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/InjectLiteral.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Original.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Original.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Original.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -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.tests.extensions.annotatedType;
+
+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.inject.Qualifier;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+public @interface Original
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Original.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Plug.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Plug.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Plug.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,7 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+@Special
+public class Plug
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Plug.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/RunningTime.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/RunningTime.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/RunningTime.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,7 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+@Special
+public class RunningTime
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/RunningTime.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SerialNumber.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SerialNumber.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SerialNumber.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,6 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+public class SerialNumber
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SerialNumber.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Special.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Special.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Special.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -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.tests.extensions.annotatedType;
+
+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.inject.Qualifier;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+public @interface Special
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/Special.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SpecialLiteral.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SpecialLiteral.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SpecialLiteral.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,28 @@
+/*
+ * 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.tests.extensions.annotatedType;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+public class SpecialLiteral extends AnnotationLiteral<Special> implements Special
+{
+
+ public static final Special INSTANCE = new SpecialLiteral();
+
+ private SpecialLiteral() {}
+
+}
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/SpecialLiteral.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/TumbleDryer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/TumbleDryer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/TumbleDryer.java 2010-01-28 00:22:07 UTC (rev 5647)
@@ -0,0 +1,77 @@
+package org.jboss.weld.tests.extensions.annotatedType;
+
+import javax.inject.Inject;
+
+
+public class TumbleDryer
+{
+
+
+ private Plug plug;
+
+ @Inject @Original
+ private Coins coins;
+
+ private final Clothes clothers;
+
+ private RunningTime runningTime;
+
+ private final SerialNumber serialNumber;
+
+ private HotAir hotAir;
+
+ public TumbleDryer(@Original Clothes clothes)
+ {
+ this.clothers = clothes;
+ this.serialNumber = null;
+ }
+
+ @Inject
+ public TumbleDryer(SerialNumber serialNumber)
+ {
+ this.serialNumber = serialNumber;
+ this.clothers = null;
+ }
+
+ public void setRunningTime(@Original RunningTime runningTime)
+ {
+ this.runningTime = runningTime;
+ }
+
+ @Inject
+ public void setHotAir(HotAir hotAir)
+ {
+ this.hotAir = hotAir;
+ }
+
+ public Plug getPlug()
+ {
+ return plug;
+ }
+
+ public Clothes getClothes()
+ {
+ return clothers;
+ }
+
+ public HotAir getHotAir()
+ {
+ return hotAir;
+ }
+
+ public RunningTime getRunningTime()
+ {
+ return runningTime;
+ }
+
+ public SerialNumber getSerialNumber()
+ {
+ return serialNumber;
+ }
+
+ public Coins getCoins()
+ {
+ return coins;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/TumbleDryer.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 11 months
Weld SVN: r5646 - core/trunk/osgi-bundle.
by weld-commits@lists.jboss.org
Author: rogerk
Date: 2010-01-27 15:25:08 -0500 (Wed, 27 Jan 2010)
New Revision: 5646
Modified:
core/trunk/osgi-bundle/pom.xml
Log:
export org.jboss.weld.manager;remove specific include for jsf package export
Modified: core/trunk/osgi-bundle/pom.xml
===================================================================
--- core/trunk/osgi-bundle/pom.xml 2010-01-27 19:15:34 UTC (rev 5645)
+++ core/trunk/osgi-bundle/pom.xml 2010-01-27 20:25:08 UTC (rev 5646)
@@ -72,13 +72,13 @@
org.jboss.weld;
org.jboss.weld.bootstrap;
org.jboss.weld.introspector;
+ org.jboss.weld.manager;
org.jboss.weld.servlet;
org.jboss.interceptor.*;
version=${osgi.version},
org.jboss.weld.el;
version=${osgi.version},
org.jboss.weld.jsf;
- include:="WeldPhaseListener";
version=${osgi.version},
javassist.util.proxy;version=${javassist.version}
</_exportcontents>
14 years, 11 months
Weld SVN: r5645 - doc/trunk/reference/en-US.
by weld-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-01-27 14:15:34 -0500 (Wed, 27 Jan 2010)
New Revision: 5645
Modified:
doc/trunk/reference/en-US/weldexamples.xml
Log:
reference issue report
Modified: doc/trunk/reference/en-US/weldexamples.xml
===================================================================
--- doc/trunk/reference/en-US/weldexamples.xml 2010-01-27 19:07:47 UTC (rev 5644)
+++ doc/trunk/reference/en-US/weldexamples.xml 2010-01-27 19:15:34 UTC (rev 5645)
@@ -475,7 +475,9 @@
<para>
Be sure to uncheck the box "Skip Maven compile plugin when processing resources (recommended)" in the
Maven properties screen or else the example might not run in Eclipse because beans.xml will be missing
- from the classpath!
+ from the classpath! See the <ulink
+ url="https://issues.sonatype.org/browse/MNGECLIPSE-768">MNGECLIPSE-768</ulink> issue report for
+ details.
</para>
</note>
14 years, 11 months
Weld SVN: r5644 - doc/trunk/reference/en-US.
by weld-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-01-27 14:07:47 -0500 (Wed, 27 Jan 2010)
New Revision: 5644
Modified:
doc/trunk/reference/en-US/weldexamples.xml
Log:
make note about skipping maven compile plugin when processing resources setting more apparent
Modified: doc/trunk/reference/en-US/weldexamples.xml
===================================================================
--- doc/trunk/reference/en-US/weldexamples.xml 2010-01-27 18:22:07 UTC (rev 5643)
+++ doc/trunk/reference/en-US/weldexamples.xml 2010-01-27 19:07:47 UTC (rev 5644)
@@ -465,13 +465,17 @@
profile. Right-click on the project and select <emphasis>Properties</emphasis>, then select the
<emphasis>Maven</emphasis> tab in the window that appears. In the form field labeled "Active Maven
Profiles (comma separated):", type <literal>jetty</literal>. That will enable some extra dependencies
- that allow the project to compile. You're now ready to develop!
+ that allow the project to compile. Additionally, <emphasis>uncheck</emphasis> the box labeled "Skip Maven
+ compile plugin when processing resources (recommended)". That solves an incompatiblity between the
+ m2eclipse plugin and the Maven enforcer plugin that we use for the Weld project. Now, you're ready to
+ develop!
</para>
<note>
<para>
- You are also advised to uncheck the box "Skip Maven compiler when processing resources" in the Maven
- properties screen because of conflicts with the Maven enforcer plugin.
+ Be sure to uncheck the box "Skip Maven compile plugin when processing resources (recommended)" in the
+ Maven properties screen or else the example might not run in Eclipse because beans.xml will be missing
+ from the classpath!
</para>
</note>
14 years, 11 months
Weld SVN: r5643 - core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-27 13:22:07 -0500 (Wed, 27 Jan 2010)
New Revision: 5643
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/EcoFriendlyWashingMachine.java
Log:
WELD-371
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java 2010-01-27 18:17:24 UTC (rev 5642)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java 2010-01-27 18:22:07 UTC (rev 5643)
@@ -29,18 +29,12 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.util.AnnotationLiteral;
+import org.jboss.weld.tests.extensions.annotatedType.EcoFriendlyWashingMachine.EcoFriendlyWashingMachineLiteral;
+
public class AnnotatedTypeExtension implements Extension
{
- public static class EcoFriendlyWashingMachineLiteral extends AnnotationLiteral<EcoFriendlyWashingMachine> implements EcoFriendlyWashingMachine
- {
-
- public static final EcoFriendlyWashingMachine INSTANCE = new EcoFriendlyWashingMachineLiteral();
-
- }
-
/**
* Adds an eco friendly wasing machine
* @param beforeBeanDiscovery
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java 2010-01-27 18:17:24 UTC (rev 5642)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtensionTest.java 2010-01-27 18:22:07 UTC (rev 5643)
@@ -16,12 +16,17 @@
*/
package org.jboss.weld.tests.extensions.annotatedType;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.spi.Bean;
+
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.testharness.impl.packaging.jsr299.Extension;
import org.jboss.weld.test.AbstractWeldTest;
+import org.jboss.weld.test.Utils;
+import org.jboss.weld.tests.extensions.annotatedType.EcoFriendlyWashingMachine.EcoFriendlyWashingMachineLiteral;
import org.testng.annotations.Test;
@Artifact
@@ -39,5 +44,12 @@
assert laundry.fastWashingMachine != null;
}
+ @Test(description = "WELD-371")
+ public void testAnnotationsAreOverridden()
+ {
+ Bean<WashingMachine> bean = getBean(WashingMachine.class, EcoFriendlyWashingMachineLiteral.INSTANCE);
+ assert Utils.annotationSetMatches(bean.getQualifiers(), Any.class, EcoFriendlyWashingMachine.class);
+ }
+
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/EcoFriendlyWashingMachine.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/EcoFriendlyWashingMachine.java 2010-01-27 18:17:24 UTC (rev 5642)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/EcoFriendlyWashingMachine.java 2010-01-27 18:22:07 UTC (rev 5643)
@@ -26,6 +26,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
@Target( { TYPE, METHOD, PARAMETER, FIELD })
@@ -34,5 +35,15 @@
@Qualifier
public @interface EcoFriendlyWashingMachine
{
+
+ @SuppressWarnings("serial")
+ public static class EcoFriendlyWashingMachineLiteral extends AnnotationLiteral<EcoFriendlyWashingMachine> implements EcoFriendlyWashingMachine
+ {
+
+ public static final EcoFriendlyWashingMachine INSTANCE = new EcoFriendlyWashingMachineLiteral();
+
+ private EcoFriendlyWashingMachineLiteral() {}
+
+ }
}
14 years, 11 months
Weld SVN: r5641 - core/trunk/impl/src/main/java/org/jboss/weld/util.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-27 12:09:28 -0500 (Wed, 27 Jan 2010)
New Revision: 5641
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
Log:
always check we can split the string first
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2010-01-27 17:02:07 UTC (rev 5640)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2010-01-27 17:09:28 UTC (rev 5641)
@@ -223,10 +223,16 @@
if (version != null)
{
StringBuilder builder = new StringBuilder();
- builder.append(version.substring(0, version.indexOf("."))).append(".");
- version = version.substring(version.indexOf(".") + 1);
- builder.append(version.substring(0, version.indexOf("."))).append(".");
- version = version.substring(version.indexOf(".") + 1);
+ if (version.indexOf(".") > 0)
+ {
+ builder.append(version.substring(0, version.indexOf("."))).append(".");
+ version = version.substring(version.indexOf(".") + 1);
+ }
+ if (version.indexOf(".") > 0)
+ {
+ builder.append(version.substring(0, version.indexOf("."))).append(".");
+ version = version.substring(version.indexOf(".") + 1);
+ }
if (version.indexOf("-") > 0)
{
builder.append(version.substring(0, version.indexOf("-"))).append(" (");
14 years, 11 months
Weld SVN: r5640 - in core/trunk: impl/src/main/java/org/jboss/weld/manager and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-27 12:02:07 -0500 (Wed, 27 Jan 2010)
New Revision: 5640
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/Employee.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/SaveAction.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/home.xhtml
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
Log:
WELD-404
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2010-01-27 14:06:01 UTC (rev 5639)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2010-01-27 17:02:07 UTC (rev 5640)
@@ -80,7 +80,7 @@
return creationalContextImpl.getIncompleteInstance(getDeclaringBean());
}
}
- return beanManager.getReference(getDeclaringBean(), Object.class, creationalContext);
+ return beanManager.getReference(getDeclaringBean(), creationalContext, true);
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-01-27 14:06:01 UTC (rev 5639)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-01-27 17:02:07 UTC (rev 5640)
@@ -765,14 +765,14 @@
}
- public Object getReference(Bean<?> bean, CreationalContext<?> creationalContext, boolean delegate)
+ public Object getReference(Bean<?> bean, CreationalContext<?> creationalContext, boolean noProxy)
{
bean = getMostSpecializedBean(bean);
if (creationalContext instanceof WeldCreationalContext<?>)
{
creationalContext = ((WeldCreationalContext<?>) creationalContext).getCreationalContext(bean);
}
- if (!delegate && isProxyRequired(bean))
+ if (!noProxy && isProxyRequired(bean))
{
if (creationalContext != null || getContext(bean.getScope()).get(bean) != null)
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/Employee.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/Employee.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/Employee.java 2010-01-27 17:02:07 UTC (rev 5640)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.producer.field.named;
+
+import java.io.Serializable;
+
+
+public class Employee implements Serializable
+{
+
+ private String name;
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/Employee.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java 2010-01-27 14:06:01 UTC (rev 5639)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java 2010-01-27 17:02:07 UTC (rev 5640)
@@ -33,6 +33,7 @@
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
/**
* <p>Check what happens when session.invalidate() is called.</p>
@@ -41,15 +42,17 @@
*
*/
@Artifact(addCurrentPackage=false)
-(a)Classes({User.class, NewUserAction.class})
+(a)Classes({User.class, NewUserAction.class, Employee.class, SaveAction.class})
@IntegrationTest(runLocally=true)
@Resources({
@Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION, source="web.xml"),
@Resource(destination="view.xhtml", source="view.xhtml"),
+ @Resource(destination="home.xhtml", source="home.xhtml"),
@Resource(destination="/WEB-INF/faces-config.xml", source="faces-config.xml")
})
public class NamedProducerTest extends AbstractWeldTest
{
+
@Test(description = "forum post")
public void testNamedProducerWorks() throws Exception
{
@@ -60,6 +63,24 @@
// Check the page rendered ok
assert getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton") != null;
}
+
+ @Test(description = "WELD-404")
+ public void testNamedProducerFieldLoosesValues() throws Exception
+ {
+ WebClient client = new WebClient();
+
+ HtmlPage page = client.getPage(getPath("/home.jsf"));
+ // Check the page rendered ok
+ HtmlSubmitInput saveButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton");
+ HtmlTextInput employeeFieldName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeFieldName");
+ HtmlTextInput employeeMethodName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeMethodName");
+ assert employeeFieldName != null;
+ assert employeeMethodName != null;
+ assert saveButton != null;
+ employeeFieldName.setValueAttribute("Pete");
+ employeeMethodName.setValueAttribute("Gavin");
+ saveButton.click();
+ }
protected <T> Set<T> getElements(HtmlElement rootElement, Class<T> elementClass)
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/SaveAction.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/SaveAction.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/SaveAction.java 2010-01-27 17:02:07 UTC (rev 5640)
@@ -0,0 +1,46 @@
+package org.jboss.weld.tests.producer.field.named;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+@Named("save")
+@SessionScoped
+public class SaveAction implements Serializable
+{
+
+ @Produces
+ @Named
+ private Employee employeeField = new Employee();
+
+ private Employee employeeMethod = new Employee();
+
+ private boolean executeCalled;
+
+ @Produces
+ @Named
+ public Employee getEmployeeMethod()
+ {
+ return employeeMethod;
+ }
+
+ public SaveAction()
+ {
+ }
+
+ public String execute()
+ {
+ assert employeeMethod.getName().equals("Gavin");
+ assert employeeField.getName().equals("Pete");
+ this.executeCalled = true;
+ return "/home?faces-redirect=true";
+ }
+
+ public boolean isExecuteCalled()
+ {
+ return executeCalled;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/SaveAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/home.xhtml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/home.xhtml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/home.xhtml 2010-01-27 17:02:07 UTC (rev 5640)
@@ -0,0 +1,19 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+ <h:head>
+ <title>New Employee</title>
+ </h:head>
+ <h:body>
+ <ui:debug hotkey="d"/>
+ <h:form>
+ <h:messages/>
+ <h:outputLabel value="Name:"/>
+ <h:inputText value="#{employeeField.name}" id="employeeFieldName" />
+ <h:inputText value="#{employeeMethod.name}" id="employeeMethodName" />
+ <h:commandButton action="#{save.execute}" value="Save!" id="saveButton"/>
+ </h:form>
+ </h:body>
+</html>
Property changes on: core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/home.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 11 months