Weld SVN: r5659 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 17:44:46 -0500 (Thu, 28 Jan 2010)
New Revision: 5659
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/CargoShip.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/InvocationOrderTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/LakeCargoShip.java
Log:
bind interceptors to correct class, enable interceptor1, interceptor2
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/CargoShip.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/CargoShip.java 2010-01-28 22:32:55 UTC (rev 5658)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/CargoShip.java 2010-01-28 22:44:46 UTC (rev 5659)
@@ -17,9 +17,7 @@
package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback.order;
import javax.annotation.PostConstruct;
-import javax.interceptor.Interceptors;
-@Interceptors( { Interceptor3.class, Interceptor4.class })
class CargoShip extends Ship
{
@PostConstruct
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/InvocationOrderTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/InvocationOrderTest.java 2010-01-28 22:32:55 UTC (rev 5658)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/InvocationOrderTest.java 2010-01-28 22:44:46 UTC (rev 5659)
@@ -36,6 +36,7 @@
})
public void testInvocationOrder() {
getInstanceByType(LakeCargoShip.class);
+ int s = LakeCargoShip.getSequence();
assert LakeCargoShip.getSequence() == 7;
}
}
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/LakeCargoShip.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/LakeCargoShip.java 2010-01-28 22:32:55 UTC (rev 5658)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/order/LakeCargoShip.java 2010-01-28 22:44:46 UTC (rev 5659)
@@ -17,7 +17,9 @@
package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback.order;
import javax.annotation.PostConstruct;
+import javax.interceptor.Interceptors;
+@Interceptors( { Interceptor1.class, Interceptor2.class, Interceptor3.class, Interceptor4.class })
class LakeCargoShip extends CargoShip
{
// Every interceptor sets this property to a certain value.
14 years, 10 months
Weld SVN: r5658 - core/trunk/impl/src/main/java/org/jboss/weld/bean.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 17:32:55 -0500 (Thu, 28 Jan 2010)
New Revision: 5658
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
Log:
WELD-393
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-01-28 22:11:46 UTC (rev 5657)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-01-28 22:32:55 UTC (rev 5658)
@@ -579,6 +579,11 @@
beanManager.getClassDeclaredInterceptorsRegistry().registerInterceptionModel(getType(), builder.build());
}
}
+ else
+ {
+ InterceptorClassMetadata interceptorClassMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(getType(), true);
+ hasSerializationOrInvocationInterceptorMethods = !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_INVOKE).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_TIMEOUT).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.PRE_PASSIVATE).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.POST_ACTIVATE).isEmpty();
+ }
}
protected void checkConstructor()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2010-01-28 22:11:46 UTC (rev 5657)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2010-01-28 22:32:55 UTC (rev 5658)
@@ -33,6 +33,8 @@
import java.util.List;
import java.util.Set;
+import javassist.util.proxy.MethodHandler;
+
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Decorator;
@@ -41,7 +43,6 @@
import javax.enterprise.inject.spi.Interceptor;
import javax.enterprise.inject.spi.PassivationCapable;
-import javassist.util.proxy.MethodHandler;
import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.registry.InterceptorRegistry;
@@ -362,10 +363,6 @@
initPreDestroy();
initEEInjectionPoints();
initPassivationCapable();
- if (isInterceptionCandidate())
- {
- initDirectlyDefinedInterceptors();
- }
setInjectionTarget(new ManagedBeanInjectionTarget<T>(this));
}
}
14 years, 10 months
Weld SVN: r5657 - in core/trunk/impl/src/main/java/org/jboss/weld: manager and 1 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 17:11:46 -0500 (Thu, 28 Jan 2010)
New Revision: 5657
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/SimpleInjectionTarget.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
Log:
WELD-390
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-01-28 17:59:05 UTC (rev 5656)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-01-28 22:11:46 UTC (rev 5657)
@@ -20,10 +20,8 @@
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BeanMessage.CONFLICTING_INTERCEPTOR_BINDINGS;
import static org.jboss.weld.logging.messages.BeanMessage.INVOCATION_ERROR;
-import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
import static org.jboss.weld.logging.messages.BeanMessage.ONLY_ONE_SCOPE_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN;
import static org.jboss.weld.logging.messages.BeanMessage.USING_DEFAULT_SCOPE;
@@ -59,11 +57,9 @@
import org.jboss.weld.bean.proxy.DecorationHelper;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.context.SerializableContextualImpl;
-import org.jboss.weld.context.SerializableContextualInstanceImpl;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
-import org.jboss.weld.exceptions.ForbiddenStateException;
import org.jboss.weld.exceptions.WeldException;
import org.jboss.weld.injection.ConstructorInjectionPoint;
import org.jboss.weld.injection.FieldInjectionPoint;
@@ -73,7 +69,6 @@
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
-import org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.Proxies.TypeInfo;
@@ -145,8 +140,8 @@
private boolean hasSerializationOrInvocationInterceptorMethods;
// Bean callback methods
- private WeldMethod<?, ?> postConstruct;
- private WeldMethod<?, ?> preDestroy;
+ private List<WeldMethod<?, ? super T>> postConstructMethods;
+ private List<WeldMethod<?, ? super T>> preDestroyMethods;
// Injection target for the bean
private InjectionTarget<T> injectionTarget;
@@ -361,7 +356,7 @@
*/
protected void initPostConstruct()
{
- this.postConstruct = Beans.getPostConstruct(getWeldAnnotated());
+ this.postConstructMethods = Beans.getPostConstructMethods(getWeldAnnotated());
}
/**
@@ -369,7 +364,7 @@
*/
protected void initPreDestroy()
{
- this.preDestroy = Beans.getPreDestroy(getWeldAnnotated());
+ this.preDestroyMethods = Beans.getPreDestroyMethods(getWeldAnnotated());
}
/**
@@ -377,9 +372,9 @@
*
* @return The post-construct method
*/
- public WeldMethod<?, ?> getPostConstruct()
+ public List<WeldMethod<?, ? super T>> getPostConstruct()
{
- return postConstruct;
+ return postConstructMethods;
}
/**
@@ -387,9 +382,9 @@
*
* @return The pre-destroy method
*/
- public WeldMethod<?, ?> getPreDestroy()
+ public List<WeldMethod<?, ? super T>> getPreDestroy()
{
- return preDestroy;
+ return preDestroyMethods;
}
protected abstract boolean isInterceptionCandidate();
@@ -473,34 +468,39 @@
protected void defaultPreDestroy(T instance)
{
- WeldMethod<?, ?> preDestroy = getPreDestroy();
- if (preDestroy != null)
+ for (WeldMethod<?, ? super T> method : getPreDestroy())
{
- try
+ if (method != null)
{
- // note: RI supports injection into @PreDestroy
- preDestroy.invoke(instance);
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ method.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(INVOCATION_ERROR, e, method, instance);
+ }
}
- catch (Exception e)
- {
- throw new WeldException(INVOCATION_ERROR, e, preDestroy, instance);
- }
}
}
protected void defaultPostConstruct(T instance)
{
- WeldMethod<?, ?> postConstruct = getPostConstruct();
- if (postConstruct != null)
+ for (WeldMethod<?, ? super T> method : getPostConstruct())
{
- try
+ if (method != null)
{
- postConstruct.invoke(instance);
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ method.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(INVOCATION_ERROR, e, method, instance);
+ }
}
- catch (Exception e)
- {
- throw new WeldException(INVOCATION_ERROR, e, postConstruct, instance);
- }
}
}
@@ -562,16 +562,22 @@
if (methodDeclaredInterceptors != null)
{
if (method.isAnnotationPresent(beanManager.getServices().get(EJBApiAbstraction.class).TIMEOUT_ANNOTATION_CLASS))
+ {
builder.interceptAroundTimeout(((AnnotatedMethod) method).getJavaMember()).with(methodDeclaredInterceptors);
+ }
else
+ {
builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(methodDeclaredInterceptors);
+ }
}
}
InterceptionModel<Class<?>, Class<?>> interceptionModel = builder.build();
InterceptorClassMetadata interceptorClassMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(getType(), true);
hasSerializationOrInvocationInterceptorMethods = !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_INVOKE).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.AROUND_TIMEOUT).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.PRE_PASSIVATE).isEmpty() || !interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.POST_ACTIVATE).isEmpty();
if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods)
+ {
beanManager.getClassDeclaredInterceptorsRegistry().registerInterceptionModel(getType(), builder.build());
+ }
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/SimpleInjectionTarget.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/SimpleInjectionTarget.java 2010-01-28 17:59:05 UTC (rev 5656)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/SimpleInjectionTarget.java 2010-01-28 22:11:46 UTC (rev 5657)
@@ -16,10 +16,9 @@
*/
package org.jboss.weld.manager;
-import static org.jboss.weld.logging.messages.BeanManagerMessage.ERROR_INVOKING_POST_CONSTRUCT;
-import static org.jboss.weld.logging.messages.BeanManagerMessage.ERROR_INVOKING_PRE_DESTROY;
import static org.jboss.weld.logging.messages.BeanManagerMessage.INJECTION_ON_NON_CONTEXTUAL;
import static org.jboss.weld.logging.messages.BeanManagerMessage.MISSING_BEAN_CONSTRUCTOR_FOUND;
+import static org.jboss.weld.logging.messages.BeanMessage.INVOCATION_ERROR;
import java.util.HashSet;
import java.util.List;
@@ -43,18 +42,18 @@
/**
* @author pmuir
- *
+ *
*/
public class SimpleInjectionTarget<T> implements InjectionTarget<T>
{
-
+
private final BeanManagerImpl beanManager;
private final WeldClass<T> type;
private final ConstructorInjectionPoint<T> constructor;
private final List<Set<FieldInjectionPoint<?, ?>>> injectableFields;
private final List<Set<MethodInjectionPoint<?, ?>>> initializerMethods;
- private final WeldMethod<?, ?> postConstruct;
- private final WeldMethod<?, ?> preDestroy;
+ private final List<WeldMethod<?, ? super T>> postConstructMethods;
+ private final List<WeldMethod<?, ? super T>> preDestroyMethods;
private final Set<InjectionPoint> injectionPoints;
private final Set<WeldInjectionPoint<?, ?>> ejbInjectionPoints;
private final Set<WeldInjectionPoint<?, ?>> persistenceContextInjectionPoints;
@@ -74,7 +73,8 @@
}
catch (Exception e)
{
- // this means the bean of a type that cannot be produce()d, but that is non-fatal
+ // this means the bean of a type that cannot be produce()d, but that is
+ // non-fatal
// unless someone calls produce()
}
this.constructor = constructor;
@@ -82,8 +82,8 @@
this.injectionPoints.addAll(Beans.getFieldInjectionPoints(null, this.injectableFields));
this.initializerMethods = Beans.getInitializerMethods(null, type);
this.injectionPoints.addAll(Beans.getParameterInjectionPoints(null, initializerMethods));
- this.postConstruct = Beans.getPostConstruct(type);
- this.preDestroy = Beans.getPreDestroy(type);
+ this.postConstructMethods = Beans.getPostConstructMethods(type);
+ this.preDestroyMethods = Beans.getPreDestroyMethods(type);
this.ejbInjectionPoints = Beans.getEjbInjectionPoints(null, type, beanManager);
this.persistenceContextInjectionPoints = Beans.getPersistenceContextInjectionPoints(null, type, beanManager);
this.persistenceUnitInjectionPoints = Beans.getPersistenceUnitInjectionPoints(null, type, beanManager);
@@ -110,50 +110,58 @@
}
return constructor.newInstance(beanManager, ctx);
}
-
+
public void inject(final T instance, final CreationalContext<T> ctx)
{
new InjectionContextImpl<T>(beanManager, this, instance)
{
-
+
public void proceed()
{
Beans.injectEEFields(instance, beanManager, ejbInjectionPoints, persistenceContextInjectionPoints, persistenceUnitInjectionPoints, resourceInjectionPoints);
Beans.injectFieldsAndInitializers(instance, ctx, beanManager, injectableFields, initializerMethods);
}
-
+
}.run();
}
public void postConstruct(T instance)
{
- if (postConstruct == null)
- return;
-
- try
+ for (WeldMethod<?, ? super T> method : postConstructMethods)
{
- postConstruct.invoke(instance);
+ if (method != null)
+ {
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ method.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(INVOCATION_ERROR, e, method, instance);
+ }
+ }
}
- catch (Exception e)
- {
- throw new WeldException(ERROR_INVOKING_POST_CONSTRUCT, e, postConstruct);
- }
}
public void preDestroy(T instance)
{
- if (preDestroy == null)
- return;
-
- try
+ for (WeldMethod<?, ? super T> method : preDestroyMethods)
{
- preDestroy.invoke(instance);
+ if (method != null)
+ {
+ try
+ {
+ // note: RI supports injection into @PreDestroy
+ method.invoke(instance);
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(INVOCATION_ERROR, e, method, instance);
+ }
+ }
}
- catch (Exception e)
- {
- throw new WeldException(ERROR_INVOKING_PRE_DESTROY, e, preDestroy);
- }
}
public void dispose(T instance)
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-28 17:59:05 UTC (rev 5656)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-01-28 22:11:46 UTC (rev 5657)
@@ -230,46 +230,50 @@
return injectionPoints;
}
- public static WeldMethod<?, ?> getPostConstruct(WeldClass<?> type)
+ public static <T> List<WeldMethod<?, ? super T>> getPostConstructMethods(WeldClass<T> type)
{
- Set<WeldMethod<?, ?>> postConstructMethods = type.getWeldMethods(PostConstruct.class);
- log.trace(FOUND_POST_CONSTRUCT_METHODS, postConstructMethods, type);
- if (postConstructMethods.size() > 1)
+ WeldClass<?> t = type;
+ List<WeldMethod<?, ? super T>> methods = new ArrayList<WeldMethod<?, ? super T>>();
+ while (!t.getJavaClass().equals(Object.class))
{
- throw new DefinitionException(TOO_MANY_POST_CONSTRUCT_METHODS, type);
+ Set<WeldMethod<?, ? super T>> declaredMethods = (Set) t.getDeclaredWeldMethods(PostConstruct.class);
+ log.trace(FOUND_POST_CONSTRUCT_METHODS, declaredMethods, type);
+ if (declaredMethods.size() > 1)
+ {
+ throw new DefinitionException(TOO_MANY_POST_CONSTRUCT_METHODS, type);
+ }
+ else if (declaredMethods.size() == 1)
+ {
+ WeldMethod<?, ? super T> method = declaredMethods.iterator().next();
+ log.trace(FOUND_ONE_POST_CONSTRUCT_METHOD, method, type);
+ methods.add(0, method);
+ }
+ t = t.getWeldSuperclass();
}
- else if (postConstructMethods.size() == 1)
- {
- WeldMethod<?, ?> postConstruct = postConstructMethods.iterator().next();
- log.trace(FOUND_ONE_POST_CONSTRUCT_METHOD, postConstruct, type);
- return postConstruct;
- }
- else
- {
- return null;
- }
+ return methods;
}
- public static WeldMethod<?, ?> getPreDestroy(WeldClass<?> type)
+ public static <T> List<WeldMethod<?, ? super T>> getPreDestroyMethods(WeldClass<T> type)
{
- Set<WeldMethod<?, ?>> preDestroyMethods = type.getWeldMethods(PreDestroy.class);
- log.trace(FOUND_PRE_DESTROY_METHODS, preDestroyMethods, type);
- if (preDestroyMethods.size() > 1)
+ WeldClass<?> t = type;
+ List<WeldMethod<?, ? super T>> methods = new ArrayList<WeldMethod<?, ? super T>>();
+ while (!t.getJavaClass().equals(Object.class))
{
- // TODO actually this is wrong, in EJB you can have @PreDestroy methods
- // on the superclass, though the CDI spec is silent on the issue
- throw new DefinitionException(TOO_MANY_PRE_DESTROY_METHODS, type);
+ Set<WeldMethod<?, ? super T>> declaredMethods = (Set) t.getDeclaredWeldMethods(PreDestroy.class);
+ log.trace(FOUND_PRE_DESTROY_METHODS, declaredMethods, type);
+ if (declaredMethods.size() > 1)
+ {
+ throw new DefinitionException(TOO_MANY_PRE_DESTROY_METHODS, type);
+ }
+ else if (declaredMethods.size() == 1)
+ {
+ WeldMethod<?, ? super T> method = declaredMethods.iterator().next();
+ log.trace(FOUND_ONE_PRE_DESTROY_METHOD, method, type);
+ methods.add(0, method);
+ }
+ t = t.getWeldSuperclass();
}
- else if (preDestroyMethods.size() == 1)
- {
- WeldMethod<?, ?> preDestroy = preDestroyMethods.iterator().next();
- log.trace(FOUND_ONE_PRE_DESTROY_METHOD, preDestroy, type);
- return preDestroy;
- }
- else
- {
- return null;
- }
+ return methods;
}
public static List<WeldMethod<?,?>> getInterceptableMethods(WeldClass<?> type)
14 years, 10 months
Weld SVN: r5656 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 12:59:05 -0500 (Thu, 28 Jan 2010)
New Revision: 5656
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/WeldConstructorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java
Log:
WELD-309
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-28 17:21:48 UTC (rev 5655)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-01-28 17:59:05 UTC (rev 5656)
@@ -47,6 +47,7 @@
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.Names;
import org.jboss.weld.util.collections.HashSetSupplier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
@@ -365,6 +366,17 @@
}
}
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof WeldClassImpl<?>)
+ {
+ WeldClassImpl<?> that = (WeldClassImpl<?>) other;
+ return AnnotatedTypes.compareAnnotatedTypes(this, that) && this.getActualTypeArguments().length == that.getActualTypeArguments().length && Arrays.equals(this.getActualTypeArguments(), that.getActualTypeArguments());
+ }
+ return false;
+ }
+
/**
* Gets the implementing class
*
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-01-28 17:21:48 UTC (rev 5655)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-01-28 17:59:05 UTC (rev 5656)
@@ -270,7 +270,7 @@
if (super.equals(other) && other instanceof WeldConstructor)
{
WeldConstructor<?> that = (WeldConstructor<?>) other;
- return this.getDeclaringType().equals(that.getDeclaringType()) && this.getWeldParameters().equals(that.getWeldParameters());
+ return this.getJavaMember().equals(that.getJavaMember()) && this.getWeldParameters().equals(that.getWeldParameters());
}
return false;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-01-28 17:21:48 UTC (rev 5655)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-01-28 17:59:05 UTC (rev 5656)
@@ -138,10 +138,10 @@
@Override
public boolean equals(Object other)
{
- if (other instanceof WeldField<?, ?>)
+ if (super.equals(other) && other instanceof WeldField<?, ?>)
{
WeldField<?, ?> that = (WeldField<?, ?>) other;
- return this.getDeclaringType().equals(that.getDeclaringType()) && this.getName().equals(that.getName());
+ return this.getJavaMember().equals(that.getJavaMember());
}
else
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-01-28 17:21:48 UTC (rev 5655)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-01-28 17:59:05 UTC (rev 5656)
@@ -190,10 +190,10 @@
@Override
public boolean equals(Object other)
{
- if (other instanceof WeldMethod)
+ if (super.equals(other) && other instanceof WeldMethod)
{
WeldMethod<?, ?> that = (WeldMethod<?, ?>) other;
- return this.getDeclaringType().equals(that.getDeclaringType()) && this.getName().equals(that.getName()) && this.getWeldParameters().equals(that.getWeldParameters());
+ return this.getJavaMember().equals(that.getJavaMember()) && this.getWeldParameters().equals(that.getWeldParameters());
}
else
{
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-28 17:21:48 UTC (rev 5655)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/AnnotatedTypeExtension.java 2010-01-28 17:59:05 UTC (rev 5656)
@@ -36,6 +36,7 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.inject.Inject;
import org.jboss.weld.tests.extensions.annotatedType.EcoFriendlyWashingMachine.EcoFriendlyWashingMachineLiteral;
@@ -553,4 +554,10 @@
beforeBeanDiscovery.addAnnotatedType(type);
}
+
+ public void vetoOriginalTumbleDryer(@Observes ProcessAnnotatedType<TumbleDryer> event)
+ {
+ event.veto();
+ }
+
}
14 years, 10 months
Weld SVN: r5655 - core/trunk/impl/src/main/java/org/jboss/weld/ejb.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 12:21:48 -0500 (Thu, 28 Jan 2010)
New Revision: 5655
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/ejb/SessionBeanInterceptor.java
Log:
WELD-15
Modified: core/trunk/impl/src/main/java/org/jboss/weld/ejb/SessionBeanInterceptor.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/ejb/SessionBeanInterceptor.java 2010-01-28 17:15:21 UTC (rev 5654)
+++ core/trunk/impl/src/main/java/org/jboss/weld/ejb/SessionBeanInterceptor.java 2010-01-28 17:21:48 UTC (rev 5655)
@@ -18,7 +18,6 @@
import java.io.Serializable;
-import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import org.jboss.weld.Container;
@@ -41,7 +40,6 @@
{
private static final long serialVersionUID = 7327757031821596782L;
- @AroundInvoke
public Object aroundInvoke(InvocationContext invocation) throws Exception
{
if (Container.instance().services().get(ContextLifecycle.class).isRequestActive())
14 years, 10 months
Weld SVN: r5654 - doc/trunk/reference/en-US.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 12:15:21 -0500 (Thu, 28 Jan 2010)
New Revision: 5654
Modified:
doc/trunk/reference/en-US/ri-spi.xml
Log:
WELD-15
Modified: doc/trunk/reference/en-US/ri-spi.xml
===================================================================
--- doc/trunk/reference/en-US/ri-spi.xml 2010-01-28 16:34:47 UTC (rev 5653)
+++ doc/trunk/reference/en-US/ri-spi.xml 2010-01-28 17:15:21 UTC (rev 5654)
@@ -574,10 +574,11 @@
</term>
<listitem>
<para>
- If you are integrating Weld into an EJB environment you must register
- <literal>org.jboss.weld.ejb.SessionBeanInterceptor</literal> as a EJB interceptor for all EJBs in the
+ If you are integrating Weld into an EJB environment you must register the <literal>aroundInvoke</literal> method of
+ <literal>org.jboss.weld.ejb.SessionBeanInterceptor</literal> as a EJB around-invoke interceptor for all EJBs in the
application, either automatically, or through user configuration, for each CDI application which
- uses enterprise beans.
+ uses enterprise beans. If you are running in a EJB 3.1 environment, you should register this as an around-timeout
+ interceptor as well.
</para>
<important>
<para>
14 years, 10 months
Weld SVN: r5653 - in core/trunk: impl/src/main/java/org/jboss/weld/bean/builtin/ee and 11 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-28 11:34:47 -0500 (Thu, 28 Jan 2010)
New Revision: 5653
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtension.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtensionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/Clothes.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/InjectLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/TumbleDryer.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/javax.enterprise.inject.spi.Extension
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessObserverMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerFieldImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/event/TransactionalObserverMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties
Log:
WELD-372
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -119,7 +119,7 @@
}
@Override
- public abstract WeldMember<T, X, S> getWeldAnnotated();
+ public abstract WeldMember<T, ? super X, S> getWeldAnnotated();
@Override
// Overriden to provide the class of the bean that declares the producer
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -46,10 +46,15 @@
public class DisposalMethod<X, T> extends AbstractReceiverBean<X, T, Method>
{
- protected MethodInjectionPoint<T, X> disposalMethodInjectionPoint;
- private WeldParameter<?, X> disposesParameter;
+ protected MethodInjectionPoint<T, ? super X> disposalMethodInjectionPoint;
+ private WeldParameter<?, ? super X> disposesParameter;
+
+ public static <X, T> DisposalMethod<X, T> of(BeanManagerImpl manager, WeldMethod<T, ? super X> method, AbstractClassBean<X> declaringBean)
+ {
+ return new DisposalMethod<X, T>(manager, method, declaringBean);
+ }
- protected DisposalMethod(BeanManagerImpl beanManager, WeldMethod<T, X> disposalMethod, AbstractClassBean<X> declaringBean)
+ protected DisposalMethod(BeanManagerImpl beanManager, WeldMethod<T, ? super X> disposalMethod, AbstractClassBean<X> declaringBean)
{
super(new StringBuilder().append(DisposalMethod.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getWeldAnnotated().getName()).append(disposalMethod.getSignature().toString()).toString(), declaringBean, beanManager);
this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
@@ -65,7 +70,7 @@
this.disposesParameter = getWeldAnnotated().getWeldParameters(Disposes.class).get(0);
}
- public WeldParameter<?, X> getDisposesParameter()
+ public WeldParameter<?, ? super X> getDisposesParameter()
{
return disposesParameter;
}
@@ -85,16 +90,11 @@
}
@Override
- public WeldMethod<T, X> getWeldAnnotated()
+ public WeldMethod<T, ? super X> getWeldAnnotated()
{
return disposalMethodInjectionPoint;
}
- public static <X, T> DisposalMethod<X, T> of(BeanManagerImpl manager, WeldMethod<T, X> disposalMethod, AbstractClassBean<X> declaringBean)
- {
- return new DisposalMethod<X, T>(manager, disposalMethod, declaringBean);
- }
-
@Override
protected void initQualifiers()
{
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 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerField.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -41,7 +41,7 @@
public class ProducerField<X, T> extends AbstractProducerBean<X, T, Field>
{
// The underlying field
- private WeldField<T, X> field;
+ private WeldField<T, ? super X> field;
/**
* Creates a producer field
@@ -51,7 +51,7 @@
* @param beanManager the current manager
* @return A producer field
*/
- public static <X, T> ProducerField<X, T> of(WeldField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
+ public static <X, T> ProducerField<X, T> of(WeldField<T, ? super X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
{
return new ProducerField<X, T>(field, declaringBean, beanManager);
}
@@ -63,7 +63,7 @@
* @param declaringBean The declaring bean
* @param manager The Bean manager
*/
- protected ProducerField(WeldField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
+ protected ProducerField(WeldField<T, ? super X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(createId(field, declaringBean), declaringBean, manager);
this.field = field;
@@ -142,7 +142,7 @@
* @return The annotated item
*/
@Override
- public WeldField<T, X> getWeldAnnotated()
+ public WeldField<T, ? super X> getWeldAnnotated()
{
return field;
}
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 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ProducerMethod.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -55,7 +55,7 @@
public class ProducerMethod<X, T> extends AbstractProducerBean<X, T, Method>
{
// The underlying method
- private MethodInjectionPoint<T, X> method;
+ private MethodInjectionPoint<T, ? super X> method;
private DisposalMethod<X, ?> disposalMethodBean;
private ProducerMethod<?, ?> specializedBean;
private final String id;
@@ -68,12 +68,12 @@
* @param beanManager the current manager
* @return A producer Web Bean
*/
- public static <X, T> ProducerMethod<X, T> of(WeldMethod<T, X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
+ public static <X, T> ProducerMethod<X, T> of(WeldMethod<T, ? super X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
{
return new ProducerMethod<X, T>(method, declaringBean, beanManager);
}
- protected ProducerMethod(WeldMethod<T, X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
+ protected ProducerMethod(WeldMethod<T, ? super X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl beanManager)
{
super(new StringBuilder().append(ProducerMethod.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getWeldAnnotated().getName()).append(".").append(method.getSignature().toString()).toString(), declaringBean, beanManager);
this.method = MethodInjectionPoint.of(this, method);
@@ -85,7 +85,7 @@
initProducerMethodInjectableParameters();
}
- protected String createId(WeldMethod<T, X> method, AbstractClassBean<X> declaringBean)
+ protected String createId(WeldMethod<T, ? super X> method, AbstractClassBean<X> declaringBean)
{
if (declaringBean.getWeldAnnotated().isDiscovered())
{
@@ -240,7 +240,7 @@
* @return The annotated item
*/
@Override
- public WeldMethod<T, X> getWeldAnnotated()
+ public WeldMethod<T, ? super X> getWeldAnnotated()
{
return method;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -103,12 +103,12 @@
* @param manager the current manager
* @return A producer field
*/
- public static <X, T> EEResourceProducerField<X, T> of(WeldField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
+ public static <X, T> EEResourceProducerField<X, T> of(WeldField<T, ? super X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
return new EEResourceProducerField<X, T>(field, declaringBean, manager);
}
- protected EEResourceProducerField(WeldField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
+ protected EEResourceProducerField(WeldField<T, ? super X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(field, declaringBean, manager);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -173,7 +173,7 @@
protected <X> void createProducerMethods(AbstractClassBean<X> declaringBean, WeldClass<X> annotatedClass)
{
- for (WeldMethod<?, X> method : annotatedClass.getDeclaredWeldMethods(Produces.class))
+ for (WeldMethod<?, ? super X> method : annotatedClass.getDeclaredWeldMethods(Produces.class))
{
createProducerMethod(declaringBean, method);
}
@@ -181,21 +181,21 @@
protected <X> void createDisposalMethods(AbstractClassBean<X> declaringBean, WeldClass<X> annotatedClass)
{
- for (WeldMethod<?, X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Disposes.class))
+ for (WeldMethod<?, ? super X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Disposes.class))
{
- DisposalMethod<X, ?> disposalBean = DisposalMethod.of(manager, method, declaringBean);
+ DisposalMethod<? super X, ?> disposalBean = DisposalMethod.of(manager, method, declaringBean);
disposalBean.initialize(getEnvironment());
getEnvironment().addDisposesMethod(disposalBean);
}
}
- protected <X, T> void createProducerMethod(AbstractClassBean<X> declaringBean, WeldMethod<T, X> annotatedMethod)
+ protected <X, T> void createProducerMethod(AbstractClassBean<X> declaringBean, WeldMethod<T, ? super X> annotatedMethod)
{
- ProducerMethod<X, T> bean = ProducerMethod.of(annotatedMethod, declaringBean, manager);
+ ProducerMethod<? super X, T> bean = ProducerMethod.of(annotatedMethod, declaringBean, manager);
getEnvironment().addProducerMethod(bean);
}
- protected <X, T> void createProducerField(AbstractClassBean<X> declaringBean, WeldField<T, X> field)
+ protected <X, T> void createProducerField(AbstractClassBean<X> declaringBean, WeldField<T, ? super X> field)
{
ProducerField<X, T> bean;
if (isEEResourceProducerField(field))
@@ -211,7 +211,7 @@
protected <X> void createProducerFields(AbstractClassBean<X> declaringBean, WeldClass<X> annotatedClass)
{
- for (WeldField<?, X> field : annotatedClass.getDeclaredWeldFields(Produces.class))
+ for (WeldField<?, ? super X> field : annotatedClass.getDeclaredWeldFields(Produces.class))
{
createProducerField(declaringBean, field);
}
@@ -219,15 +219,15 @@
protected <X> void createObserverMethods(RIBean<X> declaringBean, WeldClass<X> annotatedClass)
{
- for (WeldMethod<?, X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Observes.class))
+ for (WeldMethod<?, ? super X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Observes.class))
{
createObserverMethod(declaringBean, method);
}
}
- protected <T, X> void createObserverMethod(RIBean<X> declaringBean, WeldMethod<T, X> method)
+ protected <T, X> void createObserverMethod(RIBean<X> declaringBean, WeldMethod<T, ? super X> method)
{
- ObserverMethodImpl<T, X> observer = ObserverFactory.create(method, declaringBean, manager);
+ ObserverMethodImpl<T, ? super X> observer = ObserverFactory.create(method, declaringBean, manager);
getEnvironment().addObserverMethod(observer);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -96,13 +96,13 @@
protected <X> void createObserverMethods(RIBean<X> declaringBean, BeanManagerImpl beanManager, WeldClass<X> annotatedClass, Set<ObserverMethodImpl<?, ?>> observerMethods)
{
- for (WeldMethod<?, X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Observes.class))
+ for (WeldMethod<?, ? super X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Observes.class))
{
createObserverMethod(declaringBean, beanManager, method, observerMethods);
}
}
- protected <T, X> void createObserverMethod(RIBean<X> declaringBean, BeanManagerImpl beanManager, WeldMethod<T, X> method, Set<ObserverMethodImpl<?, ?>> observerMethods)
+ protected <T, X> void createObserverMethod(RIBean<X> declaringBean, BeanManagerImpl beanManager, WeldMethod<T, ? super X> method, Set<ObserverMethodImpl<?, ?>> observerMethods)
{
ObserverMethodImpl<T, X> observer = ObserverFactory.create(method, declaringBean, beanManager);
observerMethods.add(observer);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessObserverMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessObserverMethodImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessObserverMethodImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -40,7 +40,7 @@
public static <T, X> void fire(BeanManagerImpl beanManager, ObserverMethodImpl<T, X> observer)
{
- new ProcessObserverMethodImpl<T, X>(beanManager, observer.getMethod(), observer) {}.fire();
+ new ProcessObserverMethodImpl<T, X>(beanManager, (AnnotatedMethod<X>) observer.getMethod(), observer) {}.fire();
}
private final AnnotatedMethod<X> beanMethod;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerFieldImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerFieldImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerFieldImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -40,7 +40,7 @@
public AnnotatedField<X> getAnnotatedProducerField()
{
- return getBean().getWeldAnnotated();
+ return (AnnotatedField<X>) getBean().getWeldAnnotated();
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -32,7 +32,7 @@
public static <X, T> void fire(BeanManagerImpl beanManager, AbstractProducerBean<X, T, Member> producer)
{
- new ProcessProducerImpl<X, T>(beanManager, producer.getWeldAnnotated(), producer) {}.fire();
+ new ProcessProducerImpl<X, T>(beanManager, (AnnotatedMember<X>) producer.getWeldAnnotated(), producer) {}.fire();
}
private final AnnotatedMember<X> annotatedMember;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerMethodImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/ProcessProducerMethodImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -41,12 +41,12 @@
public AnnotatedParameter<X> getAnnotatedDisposedParameter()
{
- return getBean().getDisposalMethod().getDisposesParameter();
+ return (AnnotatedParameter<X>) getBean().getDisposalMethod().getDisposesParameter();
}
public AnnotatedMethod<X> getAnnotatedProducerMethod()
{
- return getBean().getWeldAnnotated();
+ return (AnnotatedMethod<X>) getBean().getWeldAnnotated();
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverFactory.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverFactory.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -41,7 +41,7 @@
* @param manager The Bean manager
* @return An observer implementation built from the method abstraction
*/
- public static <T, X> ObserverMethodImpl<T, X> create(WeldMethod<T, X> method, RIBean<X> declaringBean, BeanManagerImpl manager)
+ public static <T, X> ObserverMethodImpl<T, X> create(WeldMethod<T, ? super X> method, RIBean<X> declaringBean, BeanManagerImpl manager)
{
ObserverMethodImpl<T, X> result = null;
TransactionPhase transactionPhase = getTransactionalPhase(method);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -48,7 +48,6 @@
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.injection.WeldInjectionPoint;
import org.jboss.weld.introspector.WeldMethod;
-import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Beans;
@@ -76,7 +75,7 @@
protected BeanManagerImpl manager;
private final Reception notifyType;
protected final RIBean<X> declaringBean;
- protected final MethodInjectionPoint<T, X> observerMethod;
+ protected final MethodInjectionPoint<T, ? super X> observerMethod;
protected TransactionPhase transactionPhase;
private final String id;
@@ -90,7 +89,7 @@
* @param declaringBean The observer bean
* @param manager The Bean manager
*/
- protected ObserverMethodImpl(final WeldMethod<T, X> observer, final RIBean<X> declaringBean, final BeanManagerImpl manager)
+ protected ObserverMethodImpl(final WeldMethod<T, ? super X> observer, final RIBean<X> declaringBean, final BeanManagerImpl manager)
{
this.manager = manager;
this.declaringBean = declaringBean;
@@ -123,7 +122,7 @@
private void checkObserverMethod()
{
// Make sure exactly one and only one parameter is annotated with Observes
- List<WeldParameter<?, X>> eventObjects = this.observerMethod.getAnnotatedParameters(Observes.class);
+ List<?> eventObjects = this.observerMethod.getAnnotatedParameters(Observes.class);
if (this.notifyType.equals(Reception.IF_EXISTS) && declaringBean.getScope().equals(Dependent.class))
{
throw new DefinitionException(INVALID_SCOPED_CONDITIONAL_OBSERVER, this);
@@ -133,7 +132,7 @@
throw new DefinitionException(MULTIPLE_EVENT_PARAMETERS, this);
}
// Check for parameters annotated with @Disposes
- List<WeldParameter<?, X>> disposeParams = this.observerMethod.getAnnotatedParameters(Disposes.class);
+ List<?> disposeParams = this.observerMethod.getAnnotatedParameters(Disposes.class);
if (disposeParams.size() > 0)
{
throw new DefinitionException(INVALID_DISPOSES_PARAMETER, this);
@@ -184,7 +183,7 @@
/**
* @return the observerMethod
*/
- public MethodInjectionPoint<T, X> getMethod()
+ public MethodInjectionPoint<T, ? super X> getMethod()
{
return observerMethod;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/event/TransactionalObserverMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/event/TransactionalObserverMethodImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/event/TransactionalObserverMethodImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -38,7 +38,7 @@
* @param observerBean The bean declaring the observer method
* @param manager The JCDI manager in use
*/
- protected TransactionalObserverMethodImpl(WeldMethod<T, X> observer, RIBean<X> observerBean, TransactionPhase transactionPhase, BeanManagerImpl manager)
+ protected TransactionalObserverMethodImpl(WeldMethod<T, ? super X> observer, RIBean<X> observerBean, TransactionPhase transactionPhase, BeanManagerImpl manager)
{
super(observer, observerBean, manager);
this.transactionPhase = transactionPhase;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -51,17 +51,17 @@
return delegate().getWeldMethods();
}
- public Set<WeldField<?, T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
+ public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldFields(annotationType);
}
- public Set<WeldMethod<?, T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldMethods(annotationType);
}
- public Set<WeldMethod<?, T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldMethodsWithAnnotatedParameters(annotationType);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -79,7 +79,7 @@
* @return A set of abstracted fields with the given annotation. Returns an
* empty set if there are no matches
*/
- public Set<WeldField<?, T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);
+ public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);
/**
* Gets all constructors which are annotated with annotationType
@@ -121,7 +121,7 @@
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
- public Set<WeldMethod<?, T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);
/**
* Find the annotated method for a given methodDescriptor
@@ -163,7 +163,7 @@
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
- public Set<WeldMethod<?, T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
/**
* Gets the superclass.
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-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -93,7 +93,7 @@
private final Set<WeldField<?, ?>> declaredFields;
private final Map<String, WeldField<?, ?>> declaredFieldsByName;
// The map from annotation type to abstracted field with annotation
- private final SetMultimap<Class<? extends Annotation>, WeldField<?, T>> declaredAnnotatedFields;
+ private final SetMultimap<Class<? extends Annotation>, WeldField<?, ? super T>> declaredAnnotatedFields;
// The map from annotation type to abstracted field with meta-annotation
private final SetMultimap<Class<? extends Annotation>, WeldField<?, ?>> declaredMetaAnnotatedFields;
@@ -107,9 +107,9 @@
// The set of abstracted methods
private final Set<WeldMethod<?, ?>> declaredMethods;
// The map from annotation type to abstracted method with annotation
- private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, T>> declaredAnnotatedMethods;
+ private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredAnnotatedMethods;
// The map from annotation type to method with a parameter with annotation
- private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, T>> declaredMethodsByAnnotatedParameters;
+ private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredMethodsByAnnotatedParameters;
// The set of abstracted constructors
private final Set<AnnotatedConstructor<T>> constructors;
@@ -167,7 +167,7 @@
this.annotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ?>>>(), HashSetSupplier.<WeldField<?, ?>> instance());
this.declaredFields = new HashSet<WeldField<?, ?>>();
this.declaredFieldsByName = new HashMap<String, WeldField<?, ?>>();
- this.declaredAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, T>>>(), HashSetSupplier.<WeldField<?, T>> instance());
+ this.declaredAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ? super T>>>(), HashSetSupplier.<WeldField<?, ? super T>> instance());
this.declaredMetaAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ?>>>(), HashSetSupplier.<WeldField<?, ?>> instance());
if (annotatedType == null)
@@ -203,11 +203,11 @@
}
else
{
- for (AnnotatedField<? super T> field : annotatedType.getFields())
+ for (AnnotatedField<? super T> annotatedField : annotatedType.getFields())
{
- WeldField<?, T> weldField = WeldFieldImpl.of(field, this.<T> getDeclaringWeldClass(field.getJavaMember(), classTransformer), classTransformer);
+ WeldField<?, ? super T> weldField = WeldFieldImpl.of(annotatedField, this, classTransformer);
this.fields.add(weldField);
- if (field.getDeclaringType().getJavaClass() == rawType)
+ if (annotatedField.getDeclaringType().getJavaClass() == rawType)
{
this.declaredFields.add(weldField);
this.declaredFieldsByName.put(weldField.getName(), weldField);
@@ -215,7 +215,7 @@
for (Annotation annotation : weldField.getAnnotations())
{
this.annotatedFields.put(annotation.annotationType(), weldField);
- if (field.getDeclaringType().getJavaClass() == rawType)
+ if (annotatedField.getDeclaringType().getJavaClass() == rawType)
{
this.declaredAnnotatedFields.put(annotation.annotationType(), weldField);
for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
@@ -251,8 +251,7 @@
{
for (AnnotatedConstructor<T> constructor : annotatedType.getConstructors())
{
- WeldClass<T> declaringClass = this.getDeclaringWeldClass(constructor.getJavaMember(), classTransformer);
- WeldConstructor<T> weldConstructor = WeldConstructorImpl.of(constructor, declaringClass, classTransformer);
+ WeldConstructor<T> weldConstructor = WeldConstructorImpl.of(constructor, this, classTransformer);
this.constructors.add(weldConstructor);
@@ -271,8 +270,8 @@
this.methods = new HashSet<WeldMethod<?, ?>>();
this.annotatedMethods = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, ?>>>(), HashSetSupplier.<WeldMethod<?, ?>> instance());
this.declaredMethods = new HashSet<WeldMethod<?, ?>>();
- this.declaredAnnotatedMethods = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, T>>>(), HashSetSupplier.<WeldMethod<?, T>> instance());
- this.declaredMethodsByAnnotatedParameters = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, T>>>(), HashSetSupplier.<WeldMethod<?, T>> instance());
+ this.declaredAnnotatedMethods = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, ? super T>>>(), HashSetSupplier.<WeldMethod<?, ? super T>> instance());
+ this.declaredMethodsByAnnotatedParameters = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?,? super T>>>(), HashSetSupplier.<WeldMethod<?, ? super T>> instance());
this.declaredMethodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
this.methodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
@@ -315,7 +314,7 @@
{
for (AnnotatedMethod<? super T> method : annotatedType.getMethods())
{
- WeldMethod<?, T> weldMethod = WeldMethodImpl.of(method, this, classTransformer);
+ WeldMethod<?, ? super T> weldMethod = WeldMethodImpl.of(method, this, classTransformer);
this.methods.add(weldMethod);
this.methodsBySignature.put(weldMethod.getSignature(), weldMethod);
if (method.getDeclaringType().getJavaClass() == rawType)
@@ -409,7 +408,7 @@
return (WeldField<F, ?>) declaredFieldsByName.get(fieldName);
}
- public Set<WeldField<?, T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
+ public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
{
return Collections.unmodifiableSet(declaredAnnotatedFields.get(annotationType));
}
@@ -479,7 +478,7 @@
return Collections.unmodifiableSet(annotatedMethods.get(annotationType));
}
- public Set<WeldMethod<?, T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
{
return Collections.unmodifiableSet(declaredAnnotatedMethods.get(annotationType));
}
@@ -504,7 +503,7 @@
return constructorsByArgumentMap.get(Collections.emptyList());
}
- public Set<WeldMethod<?, T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
+ public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
{
return Collections.unmodifiableSet(declaredMethodsByAnnotatedParameters.get(annotationType));
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldConstructorImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -21,6 +21,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -31,10 +32,12 @@
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedParameter;
+import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.introspector.ConstructorSignature;
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldConstructor;
import org.jboss.weld.introspector.WeldParameter;
+import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
@@ -56,7 +59,7 @@
*/
public class WeldConstructorImpl<T> extends AbstractWeldCallable<T, T, Constructor<T>> implements WeldConstructor<T>
{
-
+
// The underlying constructor
private final Constructor<T> constructor;
@@ -64,17 +67,17 @@
private final List<WeldParameter<?, T>> parameters;
// The mapping of annotation -> parameter abstraction
private final ListMultimap<Class<? extends Annotation>, WeldParameter<?, T>> annotatedParameters;
-
+
private final ConstructorSignature signature;
-
+
public static <T> WeldConstructor<T> of(Constructor<T> constructor, WeldClass<T> declaringClass, ClassTransformer classTransformer)
{
return new WeldConstructorImpl<T>(constructor, constructor.getDeclaringClass(), constructor.getDeclaringClass(), null, new HierarchyDiscovery(constructor.getDeclaringClass()).getTypeClosure(), buildAnnotationMap(constructor.getAnnotations()), buildAnnotationMap(constructor.getDeclaredAnnotations()), declaringClass, classTransformer);
}
-
- public static <T> WeldConstructor<T> of(AnnotatedConstructor<T> annotatedConstructor, WeldClass<T> declaringClass, ClassTransformer classTransformer)
+
+ public static <T> WeldConstructor<T> of(AnnotatedConstructor<T> annotatedConstructor, WeldClass<T> declaringClass, ClassTransformer classTransformer)
{
- return new WeldConstructorImpl<T>(annotatedConstructor.getJavaMember(), annotatedConstructor.getJavaMember().getDeclaringClass(), annotatedConstructor.getBaseType(), annotatedConstructor, annotatedConstructor.getTypeClosure(), buildAnnotationMap(annotatedConstructor.getAnnotations()), buildAnnotationMap(annotatedConstructor.getAnnotations()), declaringClass, classTransformer);
+ return new WeldConstructorImpl<T>(annotatedConstructor.getJavaMember(), Reflections.<T>getRawType(annotatedConstructor.getBaseType()), annotatedConstructor.getBaseType(), annotatedConstructor, annotatedConstructor.getTypeClosure(), buildAnnotationMap(annotatedConstructor.getAnnotations()), buildAnnotationMap(annotatedConstructor.getAnnotations()), declaringClass, classTransformer);
}
/**
@@ -91,18 +94,18 @@
this.constructor = constructor;
this.parameters = new ArrayList<WeldParameter<?, T>>();
- annotatedParameters = Multimaps.newListMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldParameter<?, T>>>(), new Supplier< List<WeldParameter<?, T>>>()
+ annotatedParameters = Multimaps.newListMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldParameter<?, T>>>(), new Supplier<List<WeldParameter<?, T>>>()
{
-
+
public List<WeldParameter<?, T>> get()
{
return new ArrayList<WeldParameter<?, T>>();
}
-
+
});
-
+
Map<Integer, AnnotatedParameter<?>> annotatedTypeParameters = new HashMap<Integer, AnnotatedParameter<?>>();
-
+
if (annotatedConstructor != null)
{
for (AnnotatedParameter<?> annotated : annotatedConstructor.getParameters())
@@ -110,66 +113,78 @@
annotatedTypeParameters.put(annotated.getPosition(), annotated);
}
}
-
- // If the class is a (non-static) member class, its constructors parameterTypes array will prefix the
- // outer class instance, whilst the genericParameterTypes array isn't prefix'd
+
+ // If the class is a (non-static) member class, its constructors
+ // parameterTypes array will prefix the
+ // outer class instance, whilst the genericParameterTypes array isn't
+ // prefix'd
int nesting = Reflections.getNesting(declaringClass.getJavaClass());
- for (int i = 0; i < constructor.getParameterTypes().length; i++)
+ if (annotatedConstructor == null)
{
- int gi = i - nesting;
- if (constructor.getParameterAnnotations()[i].length > 0 || annotatedTypeParameters.containsKey(i))
+ for (int i = 0; i < constructor.getParameterTypes().length; i++)
{
- Class<?> clazz = constructor.getParameterTypes()[i];
- Type parameterType;
- if (constructor.getGenericParameterTypes().length > gi && gi >=0)
+ int gi = i - nesting;
+ if (constructor.getParameterAnnotations()[i].length > 0)
{
- parameterType = constructor.getGenericParameterTypes()[gi];
+ Class<? extends Object> clazz = constructor.getParameterTypes()[i];
+ Type parameterType;
+ if (constructor.getGenericParameterTypes().length > gi && gi >= 0)
+ {
+ parameterType = constructor.getGenericParameterTypes()[gi];
+ }
+ else
+ {
+ parameterType = clazz;
+ }
+ WeldParameter<?, T> parameter = WeldParameterImpl.of(constructor.getParameterAnnotations()[i], clazz, parameterType, this, i, classTransformer);
+ this.parameters.add(parameter);
+ for (Annotation annotation : parameter.getAnnotations())
+ {
+ if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ {
+ annotatedParameters.put(annotation.annotationType(), parameter);
+ }
+ }
}
else
{
- parameterType = clazz;
+ Class<? extends Object> clazz = constructor.getParameterTypes()[i];
+ Type parameterType;
+ if (constructor.getGenericParameterTypes().length > gi && gi >= 0)
+ {
+ parameterType = constructor.getGenericParameterTypes()[gi];
+ }
+ else
+ {
+ parameterType = clazz;
+ }
+ WeldParameter<?, T> parameter = WeldParameterImpl.of(new Annotation[0], (Class<Object>) clazz, parameterType, this, i, classTransformer);
+ this.parameters.add(parameter);
}
- WeldParameter<?, T> parameter = null;
- if (annotatedTypeParameters.containsKey(i))
- {
- AnnotatedParameter<?> annotatedParameter = annotatedTypeParameters.get(i);
- parameter = WeldParameterImpl.of(annotatedParameter.getAnnotations(), clazz, parameterType, this, i, classTransformer);
- }
- else
- {
- parameter = WeldParameterImpl.of(constructor.getParameterAnnotations()[i], clazz, parameterType, this, i, classTransformer);
- }
-
- parameters.add(parameter);
-
- for (Annotation annotation : parameter.getAnnotations())
- {
- annotatedParameters.put(annotation.annotationType(), parameter);
- }
}
+ }
+ else
+ {
+ if (annotatedConstructor.getParameters().size() != constructor.getParameterTypes().length)
+ {
+ throw new DefinitionException(ReflectionMessage.INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD, annotatedConstructor.getParameters().size(), annotatedConstructor, annotatedConstructor.getParameters(), Arrays.asList(constructor.getParameterTypes()));
+ }
else
{
- Class<?> clazz = constructor.getParameterTypes()[i];
- Type parameterType;
- if (constructor.getGenericParameterTypes().length > gi && gi >=0)
+ for (AnnotatedParameter<T> annotatedParameter : annotatedConstructor.getParameters())
{
- parameterType = constructor.getGenericParameterTypes()[gi];
- }
- else
- {
- parameterType = clazz;
- }
- WeldParameter<?, T> parameter = WeldParameterImpl.of(new Annotation[0], clazz, parameterType, this, i, classTransformer);
- parameters.add(parameter);
-
- for (Annotation annotation : parameter.getAnnotations())
- {
- if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ WeldParameter<?, T> parameter = WeldParameterImpl.of(annotatedParameter.getAnnotations(), Reflections.getRawType(annotatedParameter.getBaseType()), annotatedParameter.getBaseType(), this, annotatedParameter.getPosition(), classTransformer);
+ this.parameters.add(parameter);
+ for (Annotation annotation : parameter.getAnnotations())
{
- annotatedParameters.put(annotation.annotationType(), parameter);
+ if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ {
+ annotatedParameters.put(annotation.annotationType(), parameter);
+ }
}
}
}
+
}
this.signature = new ConstructorSignatureImpl(this);
}
@@ -190,7 +205,7 @@
* @return The delegate
*/
@Override
-public Constructor<T> getDelegate()
+ public Constructor<T> getDelegate()
{
return constructor;
}
@@ -230,10 +245,10 @@
*
* @param beanManager The Bean manager
* @return An instance
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- * @throws InstantiationException
- * @throws IllegalArgumentException
+ * @throws InvocationTargetException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws IllegalArgumentException
*
* @see org.jboss.weld.introspector.WeldConstructor#newInstance(BeanManagerImpl)
*/
@@ -283,12 +298,12 @@
{
return new StringBuilder().append("constructor ").append(constructor.toString()).toString();
}
-
+
public ConstructorSignature getSignature()
{
return signature;
}
-
+
public List<AnnotatedParameter<T>> getParameters()
{
return Collections.unmodifiableList((List) parameters);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldFieldImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -53,9 +53,9 @@
return new WeldFieldImpl<T, X>(field, (Class<T>) field.getType(), field.getGenericType(), new HierarchyDiscovery(field.getGenericType()).getTypeClosure(), buildAnnotationMap(field.getAnnotations()), buildAnnotationMap(field.getDeclaredAnnotations()), declaringClass, classTransformer);
}
- public static <T, X> WeldFieldImpl<T, X> of(AnnotatedField<? super X> annotatedField, WeldClass<X> declaringClass, ClassTransformer classTransformer)
+ public static <X> WeldFieldImpl<?, X> of(AnnotatedField<? super X> annotatedField, WeldClass<X> declaringClass, ClassTransformer classTransformer)
{
- return new WeldFieldImpl<T, X>(annotatedField.getJavaMember(), (Class<T>) annotatedField.getJavaMember().getType(), annotatedField.getBaseType(), annotatedField.getTypeClosure(), buildAnnotationMap(annotatedField.getAnnotations()), buildAnnotationMap(annotatedField.getAnnotations()), declaringClass, classTransformer);
+ return new WeldFieldImpl<Object, X>(annotatedField.getJavaMember(), (Class<Object>) annotatedField.getJavaMember().getType(), annotatedField.getBaseType(), annotatedField.getTypeClosure(), buildAnnotationMap(annotatedField.getAnnotations()), buildAnnotationMap(annotatedField.getAnnotations()), declaringClass, classTransformer);
}
/**
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -32,10 +32,12 @@
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
+import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.introspector.MethodSignature;
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.introspector.WeldParameter;
+import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.collections.ArrayListSupplier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
@@ -76,9 +78,9 @@
return new WeldMethodImpl<T, X>(method, (Class<T>) method.getReturnType(), method.getGenericReturnType(), new HierarchyDiscovery(method.getGenericReturnType()).getTypeClosure(), null, buildAnnotationMap(method.getAnnotations()), buildAnnotationMap(method.getDeclaredAnnotations()), declaringClass, classTransformer);
}
- public static <T, X> WeldMethodImpl<T, X> of(AnnotatedMethod<T> method, WeldClass<X> declaringClass, ClassTransformer classTransformer)
+ public static <T, X> WeldMethodImpl<T, X> of(AnnotatedMethod<? super X> method, WeldClass<X> declaringClass, ClassTransformer classTransformer)
{
- return new WeldMethodImpl<T, X>(method.getJavaMember(), (Class<T>) method.getJavaMember().getReturnType(), method.getBaseType(), method.getTypeClosure(), method, buildAnnotationMap(method.getAnnotations()), buildAnnotationMap(method.getAnnotations()), declaringClass, classTransformer);
+ return new WeldMethodImpl<T, X>(method.getJavaMember(), Reflections.<T>getRawType(method.getBaseType()), method.getBaseType(), method.getTypeClosure(), method, buildAnnotationMap(method.getAnnotations()), buildAnnotationMap(method.getAnnotations()), declaringClass, classTransformer);
}
/**
@@ -91,57 +93,66 @@
* @param declaringClass The declaring class abstraction
*/
@SuppressWarnings("unchecked")
- private WeldMethodImpl(Method method, final Class<T> rawType, final Type type, Set<Type> typeClosure, AnnotatedMethod<T> annotatedMethod, Map<Class<? extends Annotation>, Annotation> annotationMap, Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, WeldClass<X> declaringClass, ClassTransformer classTransformer)
+ private WeldMethodImpl(Method method, final Class<T> rawType, final Type type, Set<Type> typeClosure, AnnotatedMethod<? super X> annotatedMethod, Map<Class<? extends Annotation>, Annotation> annotationMap, Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, WeldClass<X> declaringClass, ClassTransformer classTransformer)
{
super(annotationMap, declaredAnnotationMap, classTransformer, method, rawType, type, typeClosure, declaringClass);
this.method = method;
this.parameters = new ArrayList<WeldParameter<?, X>>();
this.annotatedParameters = Multimaps.newListMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldParameter<?, X>>>(), ArrayListSupplier.<WeldParameter<?, X>>instance());
- Map<Integer, AnnotatedParameter<?>> annotatedTypeParameters = new HashMap<Integer, AnnotatedParameter<?>>();
-
- if (annotatedMethod != null)
+ if (annotatedMethod == null)
{
- for (AnnotatedParameter<?> annotated : annotatedMethod.getParameters())
+ for (int i = 0; i < method.getParameterTypes().length; i++)
{
- annotatedTypeParameters.put(annotated.getPosition(), annotated);
- }
- }
-
- for (int i = 0; i < method.getParameterTypes().length; i++)
- {
- if (method.getParameterAnnotations()[i].length > 0 || annotatedTypeParameters.containsKey(i))
- {
- Class<? extends Object> clazz = method.getParameterTypes()[i];
- Type parametertype = method.getGenericParameterTypes()[i];
- WeldParameter<?, X> parameter = null;
- if (annotatedTypeParameters.containsKey(i))
+ if (method.getParameterAnnotations()[i].length > 0)
{
- AnnotatedParameter<?> annotatedParameter = annotatedTypeParameters.get(i);
- parameter = WeldParameterImpl.of(annotatedParameter.getAnnotations(), clazz, parametertype, this, i, classTransformer);
+ Class<? extends Object> clazz = method.getParameterTypes()[i];
+ Type parametertype = method.getGenericParameterTypes()[i];
+ WeldParameter<?, X> parameter = WeldParameterImpl.of(method.getParameterAnnotations()[i], clazz, parametertype, this, i, classTransformer);
+ this.parameters.add(parameter);
+ for (Annotation annotation : parameter.getAnnotations())
+ {
+ if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ {
+ annotatedParameters.put(annotation.annotationType(), parameter);
+ }
+ }
}
else
{
- parameter = WeldParameterImpl.of(method.getParameterAnnotations()[i], clazz, parametertype, this, i, classTransformer);
+ Class<? extends Object> clazz = method.getParameterTypes()[i];
+ Type parameterType = method.getGenericParameterTypes()[i];
+ WeldParameter<?, X> parameter = WeldParameterImpl.of(new Annotation[0], (Class<Object>) clazz, parameterType, this, i, classTransformer);
+ this.parameters.add(parameter);
}
- this.parameters.add(parameter);
- for (Annotation annotation : parameter.getAnnotations())
+ }
+ }
+ else
+ {
+ if (annotatedMethod.getParameters().size() != method.getParameterTypes().length)
+ {
+ throw new DefinitionException(ReflectionMessage.INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD, annotatedMethod.getParameters().size(), annotatedMethod, annotatedMethod.getParameters(), Arrays.asList(method.getParameterTypes()));
+ }
+ else
+ {
+ for (AnnotatedParameter<? super X> annotatedParameter : annotatedMethod.getParameters())
{
- if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ WeldParameter<?, X> parameter = WeldParameterImpl.of(annotatedParameter.getAnnotations(), Reflections.getRawType(annotatedParameter.getBaseType()), annotatedParameter.getBaseType(), this, annotatedParameter.getPosition(), classTransformer);
+ this.parameters.add(parameter);
+ for (Annotation annotation : parameter.getAnnotations())
{
- annotatedParameters.put(annotation.annotationType(), parameter);
+ if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ {
+ annotatedParameters.put(annotation.annotationType(), parameter);
+ }
}
}
}
- else
- {
- Class<? extends Object> clazz = method.getParameterTypes()[i];
- Type parameterType = method.getGenericParameterTypes()[i];
- WeldParameter<?, X> parameter = WeldParameterImpl.of(new Annotation[0], (Class<Object>) clazz, parameterType, this, i, classTransformer);
- this.parameters.add(parameter);
- }
+
}
+
+
String propertyName = Reflections.getPropertyName(getDelegate());
if (propertyName == null)
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -48,6 +48,8 @@
@MessageId("000610") UNABLE_TO_GET_CONSTRUCTOR_ON_DESERIALIZATION,
@MessageId("000611") UNABLE_TO_GET_METHOD_ON_DESERIALIZATION,
@MessageId("000612") UNABLE_TO_GET_FIELD_ON_DESERIALIZATION,
- @MessageId("000613") UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION;
+ @MessageId("000613") UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION,
+ @MessageId("000614") INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD,
+ @MessageId("000615") INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR;
}
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties 2010-01-28 04:56:14 UTC (rev 5652)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties 2010-01-28 16:34:47 UTC (rev 5653)
@@ -11,4 +11,6 @@
UNABLE_TO_GET_FIELD_ON_DESERIALIZATION=Unable to deserialize field. Declaring bean id {0}, declaring class {1}, field name {2}
UNABLE_TO_GET_CONSTRUCTOR_ON_DESERIALIZATION=Unable to deserialize constructor. Declaring bean id {0}, declaring class {1}, signature {2}
UNABLE_TO_GET_METHOD_ON_DESERIALIZATION=Unable to deserialize method. Declaring bean id {0}, declaring class {1}, signature {2}
-UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION=Unable to deserialize paramter. Declaring bean id {0}, declaring class {1}, parameter {3} of method with signature {2}
\ No newline at end of file
+UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION=Unable to deserialize paramter. Declaring bean id {0}, declaring class {1}, parameter {3} of method with signature {2}
+INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD=Incorrect number of AnnotatedParameters {0} on AnnotatedMethod {1}. AnnotatedMethod has {2} as parameters but should have {3} as parameters
+INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR=Incorrect number of AnnotatedParameters {0} on AnnotatedConstructor {1}. AnnotatedConstructor has {2} as parameters but should have {3} as parameters
\ No newline at end of file
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtension.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtension.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtension.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -0,0 +1,221 @@
+/*
+ * 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.invalidParameters;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+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.util.collections.Arrays2;
+
+public class AnnotatedTypeExtension implements Extension
+{
+
+ public void addTumbleDryer(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+ {
+
+ final Set<AnnotatedConstructor<TumbleDryer>> constructors = new HashSet<AnnotatedConstructor<TumbleDryer>>();
+
+
+ final AnnotatedType<TumbleDryer> tumbleDryer = new AnnotatedType<TumbleDryer>()
+ {
+
+ public Set<AnnotatedConstructor<TumbleDryer>> getConstructors()
+ {
+ return constructors;
+ }
+
+ public Set<AnnotatedField<? super TumbleDryer>> getFields()
+ {
+ return Collections.emptySet();
+ }
+
+ public Set<AnnotatedMethod<? super TumbleDryer>> getMethods()
+ {
+ return Collections.emptySet();
+ }
+
+ // 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;
+ }
+
+ };
+
+ 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)
+ {
+ return null;
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.emptySet();
+ }
+
+ 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)
+ {
+ return false;
+ }
+ };
+ clothesParameters.add(clothesParameter);
+ clothesParameters.add(clothesParameter);
+
+ beforeBeanDiscovery.addAnnotatedType(tumbleDryer);
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtension.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtensionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtensionTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtensionTest.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -0,0 +1,40 @@
+/*
+ * 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.invalidParameters;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.jsr299.Extension;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+@Artifact
+@IntegrationTest
+(a)ExpectedDeploymentException(Exception.class)
+@Extension("javax.enterprise.inject.spi.Extension")
+public class AnnotatedTypeExtensionTest extends AbstractWeldTest
+{
+
+ @Test(description = "WELD-371")
+ public void testIncorrectlyOverridenParameters()
+ {
+ assert false;
+ }
+
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/AnnotatedTypeExtensionTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/Clothes.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/Clothes.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/Clothes.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -0,0 +1,27 @@
+package org.jboss.weld.tests.extensions.annotatedType.invalidParameters;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+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/invalidParameters/Clothes.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/InjectLiteral.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/InjectLiteral.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/InjectLiteral.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -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.invalidParameters;
+
+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/invalidParameters/InjectLiteral.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/TumbleDryer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/TumbleDryer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/TumbleDryer.java 2010-01-28 16:34:47 UTC (rev 5653)
@@ -0,0 +1,23 @@
+package org.jboss.weld.tests.extensions.annotatedType.invalidParameters;
+
+import javax.inject.Inject;
+
+
+
+public class TumbleDryer
+{
+
+ private final Clothes clothers;
+
+ @Inject
+ public TumbleDryer(Clothes clothes)
+ {
+ this.clothers = clothes;
+ }
+
+ public Clothes getClothes()
+ {
+ return clothers;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/TumbleDryer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/javax.enterprise.inject.spi.Extension
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/javax.enterprise.inject.spi.Extension (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/invalidParameters/javax.enterprise.inject.spi.Extension 2010-01-28 16:34:47 UTC (rev 5653)
@@ -0,0 +1 @@
+org.jboss.weld.tests.extensions.annotatedType.invalidParameters.AnnotatedTypeExtension
14 years, 10 months
Weld SVN: r5652 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/unit and 2 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-01-27 23:56:14 -0500 (Wed, 27 Jan 2010)
New Revision: 5652
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/AnnotatedTypesTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/Chair.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/ComfyChair.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
Log:
added tests and minor bug fixes to AnnotatedTypes
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 03:51:14 UTC (rev 5651)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -207,7 +207,7 @@
builder.append(clazz.getName());
builder.append(createAnnotationCollectionId(annotations));
- builder.append("{ ");
+ builder.append("{");
// now deal with the fields
List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
@@ -256,7 +256,7 @@
{
for (AnnotatedParameter<X> parameter : callable.getParameters())
{
- if (parameter.getAnnotations().isEmpty())
+ if (!parameter.getAnnotations().isEmpty())
{
return true;
}
@@ -448,7 +448,7 @@
public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
{
- if (f1.getJavaMember().equals(f2.getJavaMember()))
+ if (!f1.getJavaMember().equals(f2.getJavaMember()))
{
return false;
}
@@ -457,7 +457,7 @@
public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
{
- if (m1.getJavaMember().equals(m2.getJavaMember()))
+ if (!m1.getJavaMember().equals(m2.getJavaMember()))
{
return false;
}
@@ -473,7 +473,7 @@
*/
public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2)
{
- if (t1.getJavaClass().equals(t2.getJavaClass()))
+ if (!t1.getJavaClass().equals(t2.getJavaClass()))
{
return false;
}
@@ -481,6 +481,11 @@
{
return false;
}
+
+ if (t1.getFields().size() != t2.getFields().size())
+ {
+ return false;
+ }
Map<Field, AnnotatedField<?>> fields = new HashMap<Field, AnnotatedField<?>>();
for (AnnotatedField<?> f : t2.getFields())
{
@@ -501,6 +506,10 @@
}
}
+ if (t1.getMethods().size() != t2.getMethods().size())
+ {
+ return false;
+ }
Map<Method, AnnotatedMethod<?>> methods = new HashMap<Method, AnnotatedMethod<?>>();
for (AnnotatedMethod<?> f : t2.getMethods())
{
@@ -520,7 +529,10 @@
return false;
}
}
-
+ if (t1.getConstructors().size() != t2.getConstructors().size())
+ {
+ return false;
+ }
Map<Constructor<?>, AnnotatedConstructor<?>> constructors = new HashMap<Constructor<?>, AnnotatedConstructor<?>>();
for (AnnotatedConstructor<?> f : t2.getConstructors())
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/AnnotatedTypesTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/AnnotatedTypesTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/AnnotatedTypesTest.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -0,0 +1,152 @@
+package org.jboss.weld.tests.unit.util;
+
+import java.util.Iterator;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.weld.introspector.WeldClass;
+import org.jboss.weld.introspector.jlr.WeldClassImpl;
+import org.jboss.weld.metadata.TypeStore;
+import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.tests.util.annotated.TestAnnotatedTypeBuilder;
+import org.jboss.weld.util.AnnotatedTypes;
+import org.testng.annotations.Test;
+
+/**
+ * Test comparison and id creation for AnnotatedTypes
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class AnnotatedTypesTest
+{
+ /**
+ * tests the AnnotatedTypes.compareAnnotatedTypes
+ */
+ @Test
+ public void testComparison() throws SecurityException, NoSuchFieldException, NoSuchMethodException
+ {
+ //check that two weld classes on the same underlying are equal
+ TypeStore ts = new TypeStore();
+ ClassTransformer ct =new ClassTransformer(ts);
+ WeldClass<Chair> chair1 = WeldClassImpl.of(Chair.class,ct);
+ WeldClass<Chair> chair2 = WeldClassImpl.of(Chair.class,ct);
+ assert AnnotatedTypes.compareAnnotatedTypes(chair1, chair2);
+
+ //check that a different implementation of annotated type is equal to the weld implementation
+ TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToClass(new DefaultLiteral());
+ builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
+ builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
+ AnnotatedType<Chair> chair3 = builder.create();
+ assert AnnotatedTypes.compareAnnotatedTypes(chair1, chair3);
+
+ //check that the implementation returns false if a field annotation changes
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToClass(new DefaultLiteral());
+ builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
+ builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
+ chair3 = builder.create();
+ assert !AnnotatedTypes.compareAnnotatedTypes(chair1, chair3);
+
+ //check that the implementation returns false if a class level annotation changes
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToClass(new ProducesLiteral());
+ builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
+ builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
+ chair3 = builder.create();
+ assert !AnnotatedTypes.compareAnnotatedTypes(chair1, chair3);
+
+ }
+
+ @Test
+ public void testFieldId() throws SecurityException, NoSuchFieldException
+ {
+ TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
+ AnnotatedType<Chair> chair3 = builder.create();
+ AnnotatedField<? super Chair> field = chair3.getFields().iterator().next();
+ String id = AnnotatedTypes.createFieldId(field);
+ assert "org.jboss.weld.tests.unit.util.Chair.legs[(a)javax.enterprise.inject.Produces()]".equals(id): "wrong id for field :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ chair3 = builder.create();
+ field = chair3.getFields().iterator().next();
+ id = AnnotatedTypes.createFieldId(field);
+ assert "org.jboss.weld.tests.unit.util.Chair.legs".equals(id) : "wrong id for field :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToField(Chair.class.getField("legs"), new ComfyChairLiteral());
+ chair3 = builder.create();
+ field = chair3.getFields().iterator().next();
+ id = AnnotatedTypes.createFieldId(field);
+ assert "org.jboss.weld.tests.unit.util.Chair.legs[(a)org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]".equals(id) : "wrong id for field :" + id;
+ }
+
+ @Test
+ public void testMethodId() throws SecurityException, NoSuchMethodException
+ {
+ TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
+ AnnotatedType<Chair> chair3 = builder.create();
+ Iterator<AnnotatedMethod<? super Chair>> it = chair3.getMethods().iterator();
+ AnnotatedMethod<? super Chair> method = it.next();
+ while(!method.getJavaMember().getName().equals("sit"))method = it.next();
+ String id = AnnotatedTypes.createCallableId(method);
+ assert "org.jboss.weld.tests.unit.util.Chair.sit[(a)javax.enterprise.inject.Produces()]()".equals(id): "wrong id for method :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ chair3 = builder.create();
+ it = chair3.getMethods().iterator();
+ method = it.next();
+ while(!method.getJavaMember().getName().equals("sit"))method = it.next();
+ id = AnnotatedTypes.createCallableId(method);
+ assert "org.jboss.weld.tests.unit.util.Chair.sit()".equals(id) : "wrong id for method :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToMethod(Chair.class.getMethod("sit"), new ComfyChairLiteral());
+ chair3 = builder.create();
+ it = chair3.getMethods().iterator();
+ method = it.next();
+ while(!method.getJavaMember().getName().equals("sit"))method = it.next();
+ id = AnnotatedTypes.createCallableId(method);
+ assert "org.jboss.weld.tests.unit.util.Chair.sit[(a)org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]()".equals(id) : "wrong id for method :" + id;
+ }
+
+ @Test
+ public void testTypeId() throws SecurityException, NoSuchMethodException
+ {
+ TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
+ AnnotatedType<Chair> chair3 = builder.create();
+ String id = AnnotatedTypes.createTypeId(chair3);
+ assert "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[(a)javax.enterprise.inject.Produces()]();}".equals(id): "wrong id for type :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ chair3 = builder.create();
+ id = AnnotatedTypes.createTypeId(chair3);
+ assert "org.jboss.weld.tests.unit.util.Chair{}".equals(id) : "wrong id for type :" + id;
+
+ builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
+ builder.addToMethod(Chair.class.getMethod("sit"), new ComfyChairLiteral());
+ chair3 = builder.create();
+ id = AnnotatedTypes.createTypeId(chair3);
+ assert "org.jboss.weld.tests.unit.util.Chair{org.jboss.weld.tests.unit.util.Chair.sit[(a)org.jboss.weld.tests.unit.util.ComfyChair(softness=1)]();}".equals(id) : "wrong id for type :" + id;
+ }
+
+ private static class DefaultLiteral extends AnnotationLiteral<Default> implements Default {}
+ private static class ProducesLiteral extends AnnotationLiteral<Produces> implements Produces {}
+ private static class ComfyChairLiteral extends AnnotationLiteral<ComfyChair> implements ComfyChair
+ {
+ public int softness()
+ {
+ return 1;
+ }
+
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/Chair.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/Chair.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/Chair.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -0,0 +1,17 @@
+package org.jboss.weld.tests.unit.util;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.Produces;
+
+@Default
+public class Chair
+{
+ @Produces
+ public int legs;
+
+ @Produces
+ public String sit()
+ {
+ return "sitting";
+ }
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/ComfyChair.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/ComfyChair.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/util/ComfyChair.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -0,0 +1,6 @@
+package org.jboss.weld.tests.unit.util;
+
+public @interface ComfyChair
+{
+ int softness();
+}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java 2010-01-28 03:51:14 UTC (rev 5651)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -34,19 +34,19 @@
super(clazz, typeAnnotations);
this.javaClass = clazz;
this.constructors = new HashSet<AnnotatedConstructor<X>>();
- for (Constructor<?> c : clazz.getConstructors())
+ for (Constructor<?> c : clazz.getDeclaredConstructors())
{
TestAnnotatedConstructor<X> nc = new TestAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
constructors.add(nc);
}
this.methods = new HashSet<AnnotatedMethod<? super X>>();
- for (Method m : clazz.getMethods())
+ for (Method m : clazz.getDeclaredMethods())
{
TestAnnotatedMethod<X> met = new TestAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
methods.add(met);
}
this.fields = new HashSet<AnnotatedField<? super X>>();
- for (Field f : clazz.getFields())
+ for (Field f : clazz.getDeclaredFields())
{
TestAnnotatedField<X> b = new TestAnnotatedField<X>(this, f, fieldAnnotations.get(f));
fields.add(b);
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java 2010-01-28 03:51:14 UTC (rev 5651)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java 2010-01-28 04:56:14 UTC (rev 5652)
@@ -34,6 +34,7 @@
public TestAnnotatedTypeBuilder(Class<X> underlying)
{
this.underlying = underlying;
+
}
public TestAnnotatedTypeBuilder<X> addToClass(Annotation a)
14 years, 10 months
Weld SVN: r5651 - in core/trunk/tests/src/test/java/org/jboss/weld/tests: util and 1 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-01-27 22:51:14 -0500 (Wed, 27 Jan 2010)
New Revision: 5651
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java
Log:
Added an implementation of AnnotatedType to test the SPI. This implementation was ripped from weld-extensions
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,57 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Member;
+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 AbstractTestAnnotatedCallable<X, Y extends Member> extends AbstractTestAnnotatedMember<X, Y> implements AnnotatedCallable<X>
+{
+
+ private final List<AnnotatedParameter<X>> parameters;
+
+ protected AbstractTestAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+ {
+ super(declaringType, member, memberType, annotations);
+ this.parameters = getAnnotatedParameters(this, parameterTypes, parameterAnnotations);
+ }
+
+ 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(AbstractTestAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Map<Integer, TestAnnotationStore> parameterAnnotations)
+ {
+ List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+ int len = parameterTypes.length;
+ for (int i = 0; i < len; ++i)
+ {
+ TestAnnotationBuilder builder = new TestAnnotationBuilder();
+ if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+ {
+ builder.addAll(parameterAnnotations.get(i));
+ }
+ TestAnnotatedParameter<X> p = new TestAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create());
+ parameters.add(p);
+ }
+ return parameters;
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,62 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+
+/**
+ * The base class for all New Annotated types.
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AbstractTestAnnotatedElement implements Annotated
+{
+
+ private final Class<?> type;
+ private final Set<Type> typeClosure;
+ private final TestAnnotationStore annotations;
+
+ protected AbstractTestAnnotatedElement(Class<?> type, TestAnnotationStore annotations)
+ {
+ this.typeClosure = new TestTypeClosureBuilder().add(type).getTypes();
+ if (annotations == null)
+ {
+ this.annotations = new TestAnnotationStore();
+ }
+ else
+ {
+ this.annotations = annotations;
+ }
+ this.type = type;
+ }
+
+ 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 Collections.unmodifiableSet(typeClosure);
+ }
+
+ public Type getBaseType()
+ {
+ return type;
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,41 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+abstract class AbstractTestAnnotatedMember<X, M extends Member> extends AbstractTestAnnotatedElement implements AnnotatedMember<X>
+{
+ private final AnnotatedType<X> declaringType;
+ private final M javaMember;
+
+ protected AbstractTestAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, TestAnnotationStore annotations)
+ {
+ super(memberType, annotations);
+ 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());
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotatedConstructor<X> extends AbstractTestAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
+{
+
+ TestAnnotatedConstructor(TestAnnotatedType<X> type, Constructor<?> constructor, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+ {
+ super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), annotations, parameterAnnotations);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Field;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotatedField<X> extends AbstractTestAnnotatedMember<X, Field> implements AnnotatedField<X>
+{
+
+ TestAnnotatedField(AnnotatedType<X> declaringType, Field field, TestAnnotationStore annotations)
+ {
+ super(declaringType, field, field.getType(), annotations);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotatedMethod<X> extends AbstractTestAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
+{
+ TestAnnotatedMethod(AnnotatedType<X> type, Method method, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+ {
+ super(type, method, method.getReturnType(), method.getParameterTypes(), annotations, parameterAnnotations);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,34 @@
+package org.jboss.weld.tests.util.annotated;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotatedParameter<X> extends AbstractTestAnnotatedElement implements AnnotatedParameter<X>
+{
+
+ private final int position;
+ private final AnnotatedCallable<X> declaringCallable;
+
+ TestAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, TestAnnotationStore annotations)
+ {
+ super(type, annotations);
+ this.declaringCallable = declaringCallable;
+ this.position = position;
+ }
+
+ public AnnotatedCallable<X> getDeclaringCallable()
+ {
+ return declaringCallable;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,76 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+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 TestAnnotatedType<X> extends AbstractTestAnnotatedElement 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;
+
+ TestAnnotatedType(Class<X> clazz, TestAnnotationStore typeAnnotations, Map<Field, TestAnnotationStore> fieldAnnotations, Map<Method, TestAnnotationStore> methodAnnotations, Map<Method, Map<Integer, TestAnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, TestAnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, TestAnnotationStore>> constructorParameterAnnotations)
+ {
+ super(clazz, typeAnnotations);
+ this.javaClass = clazz;
+ this.constructors = new HashSet<AnnotatedConstructor<X>>();
+ for (Constructor<?> c : clazz.getConstructors())
+ {
+ TestAnnotatedConstructor<X> nc = new TestAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
+ constructors.add(nc);
+ }
+ this.methods = new HashSet<AnnotatedMethod<? super X>>();
+ for (Method m : clazz.getMethods())
+ {
+ TestAnnotatedMethod<X> met = new TestAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
+ methods.add(met);
+ }
+ this.fields = new HashSet<AnnotatedField<? super X>>();
+ for (Field f : clazz.getFields())
+ {
+ TestAnnotatedField<X> b = new TestAnnotatedField<X>(this, f, fieldAnnotations.get(f));
+ fields.add(b);
+ }
+ }
+
+ 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);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,161 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Class for constructing a new AnnotatedType. A new instance of builder must be
+ * used for each annotated type.
+ *
+ * No annotations will be read from the underlying class definition, all
+ * annotations must be added explicitly
+ *
+ * @author Stuart Douglas
+ * @author Pete Muir
+ *
+ */
+public class TestAnnotatedTypeBuilder<X>
+{
+ private Map<Field, TestAnnotationBuilder> fields = new HashMap<Field, TestAnnotationBuilder>();
+ private Map<Method, TestAnnotationBuilder> methods = new HashMap<Method, TestAnnotationBuilder>();
+ private Map<Method, Map<Integer, TestAnnotationBuilder>> methodParameters = new HashMap<Method, Map<Integer, TestAnnotationBuilder>>();
+ private Map<Constructor<X>, TestAnnotationBuilder> constructors = new HashMap<Constructor<X>, TestAnnotationBuilder>();
+ private Map<Constructor<X>, Map<Integer, TestAnnotationBuilder>> constructorParameters = new HashMap<Constructor<X>, Map<Integer, TestAnnotationBuilder>>();
+ private TestAnnotationBuilder typeAnnotations = new TestAnnotationBuilder();
+ private Class<X> underlying;
+
+ public TestAnnotatedTypeBuilder(Class<X> underlying)
+ {
+ this.underlying = underlying;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToClass(Annotation a)
+ {
+ typeAnnotations.add(a);
+ return this;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
+ {
+ TestAnnotationBuilder annotations = fields.get(field);
+ if (annotations == null)
+ {
+ annotations = new TestAnnotationBuilder();
+ fields.put(field, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
+ {
+ TestAnnotationBuilder annotations = methods.get(method);
+ if (annotations == null)
+ {
+ annotations = new TestAnnotationBuilder();
+ methods.put(method, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
+ {
+ Map<Integer, TestAnnotationBuilder> anmap = methodParameters.get(method);
+ if (anmap == null)
+ {
+ anmap = new HashMap<Integer, TestAnnotationBuilder>();
+ methodParameters.put(method, anmap);
+ }
+ TestAnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations == null)
+ {
+ annotations = new TestAnnotationBuilder();
+ anmap.put(parameter, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
+ {
+ TestAnnotationBuilder annotations = constructors.get(constructor);
+ if (annotations == null)
+ {
+ annotations = new TestAnnotationBuilder();
+ constructors.put(constructor, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public TestAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
+ {
+ Map<Integer, TestAnnotationBuilder> anmap = constructorParameters.get(constructor);
+ if (anmap == null)
+ {
+ anmap = new HashMap<Integer, TestAnnotationBuilder>();
+ constructorParameters.put(constructor, anmap);
+ }
+ TestAnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations == null)
+ {
+ annotations = new TestAnnotationBuilder();
+ anmap.put(parameter, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public AnnotatedType<X> create()
+ {
+ Map<Constructor<X>, Map<Integer, TestAnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,TestAnnotationStore>>();
+ Map<Constructor<X>, TestAnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, TestAnnotationStore>();
+ Map<Method, Map<Integer, TestAnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer,TestAnnotationStore>>();
+ Map<Method, TestAnnotationStore> methodAnnotations = new HashMap<Method, TestAnnotationStore>();
+ Map<Field, TestAnnotationStore> fieldAnnotations = new HashMap<Field, TestAnnotationStore>();
+
+ for (Entry<Field, TestAnnotationBuilder> e : fields.entrySet())
+ {
+ fieldAnnotations.put(e.getKey(), e.getValue().create());
+ }
+
+ for (Entry<Method, TestAnnotationBuilder> e : methods.entrySet())
+ {
+ methodAnnotations.put(e.getKey(), e.getValue().create());
+ }
+ for (Entry<Method, Map<Integer, TestAnnotationBuilder>> e : methodParameters.entrySet())
+ {
+ Map<Integer, TestAnnotationStore> parameterAnnotations = new HashMap<Integer, TestAnnotationStore>();
+ methodParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+ for (Entry<Integer, TestAnnotationBuilder> pe : e.getValue().entrySet())
+ {
+ parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+ }
+ }
+
+ for (Entry<Constructor<X>, TestAnnotationBuilder> e : constructors.entrySet())
+ {
+ constructorAnnotations.put(e.getKey(), e.getValue().create());
+ }
+ for (Entry<Constructor<X>, Map<Integer, TestAnnotationBuilder>> e : constructorParameters.entrySet())
+ {
+ Map<Integer, TestAnnotationStore> parameterAnnotations = new HashMap<Integer, TestAnnotationStore>();
+ constructorParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+ for (Entry<Integer, TestAnnotationBuilder> pe : e.getValue().entrySet())
+ {
+ parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+ }
+ }
+
+ return new TestAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,58 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotationBuilder
+{
+ private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ private Set<Annotation> annotationSet = new HashSet<Annotation>();
+
+ public TestAnnotationBuilder add(Annotation a)
+ {
+ annotationSet.add(a);
+ annotationMap.put(a.getClass(), a);
+ return this;
+ }
+
+ public TestAnnotationStore create()
+ {
+ return new TestAnnotationStore(annotationMap, annotationSet);
+ }
+
+ public TestAnnotationBuilder addAll(Set<Annotation> annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public TestAnnotationBuilder addAll(TestAnnotationStore annotations)
+ {
+ for (Annotation annotation : annotations.getAnnotations())
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public TestAnnotationBuilder addAll(AnnotatedElement element)
+ {
+ for (Annotation a : element.getAnnotations())
+ {
+ add(a);
+ }
+ return this;
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,47 @@
+package org.jboss.weld.tests.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 TestAnnotationStore
+{
+
+ private final HashMap<Class<? extends Annotation>, Annotation> annotationMap;
+ private final Set<Annotation> annotationSet;
+
+ TestAnnotationStore(HashMap<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
+ {
+ this.annotationMap = annotationMap;
+ this.annotationSet = annotationSet;
+ }
+
+ TestAnnotationStore()
+ {
+ 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);
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java 2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,48 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A type closure builder
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TestTypeClosureBuilder
+{
+
+ final Set<Type> types = new HashSet<Type>();
+
+ public TestTypeClosureBuilder 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 TestTypeClosureBuilder addInterfaces(Class<?> beanType)
+ {
+ for (Class<?> i : beanType.getInterfaces())
+ {
+ types.add(i);
+ }
+ return this;
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+}
14 years, 10 months
Weld SVN: r5650 - core/trunk/impl/src/main/java/org/jboss/weld/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-01-27 21:45:45 -0500 (Wed, 27 Jan 2010)
New Revision: 5650
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java
Log:
minor change to annotated type comparison
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 02:26:52 UTC (rev 5649)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java 2010-01-28 02:45:45 UTC (rev 5650)
@@ -393,6 +393,27 @@
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
*
@@ -427,7 +448,7 @@
public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
{
- if (f1.getJavaMember() != f2.getJavaMember())
+ if (f1.getJavaMember().equals(f2.getJavaMember()))
{
return false;
}
@@ -436,7 +457,7 @@
public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
{
- if(m1.getJavaMember() != m2.getJavaMember())
+ if (m1.getJavaMember().equals(m2.getJavaMember()))
{
return false;
}
@@ -452,7 +473,7 @@
*/
public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2)
{
- if (t1.getJavaClass() != t2.getJavaClass())
+ if (t1.getJavaClass().equals(t2.getJavaClass()))
{
return false;
}
@@ -523,27 +544,7 @@
}
- 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();
- }
-
private AnnotatedTypes()
{
}
14 years, 10 months