Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

WELD-1111 PART2 #194

Closed
wants to merge 1 commit into from

2 participants

@luksa

No description provided.

@alesj
Collaborator

Either way works for me. ;-)

@luksa luksa WELD-1111 Inheritance of member-level metadata for generic types - mi…
…ssing substitution of actual type arguments (Part II: InjectionTargets)
3abbaf8
@luksa

OK, this pull-req is ready for merge.

@alesj
Collaborator

Merged.

@alesj alesj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @luksa

    WELD-1111 Inheritance of member-level metadata for generic types - mi…

    luksa authored
    …ssing substitution of actual type arguments (Part II: InjectionTargets)
This page is out of date. Refresh to see the latest.
View
2  impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java
@@ -104,7 +104,7 @@ public String toString() {
protected EEResourceProducerField(WeldField<T, ? super X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager, ServiceRegistry services) {
super(field, declaringBean, manager, services);
- this.injectionPoint = FieldInjectionPoint.of(declaringBean, field);
+ this.injectionPoint = FieldInjectionPoint.of(declaringBean, null, field);
}
@Override
View
2  impl/src/main/java/org/jboss/weld/event/ObserverMethodImpl.java
@@ -102,7 +102,7 @@ protected ObserverMethodImpl(final WeldMethod<T, ? super X> observer, final RIBe
this.observerMethod = MethodInjectionPoint.of(declaringBean, observer);
WeldParameter<?, ? super X> eventArgument = observerMethod.getAnnotatedParameters(Observes.class).get(0);
- this.eventType = TypeVariableResolver.resolveVariables(declaringBean, eventArgument.getBaseType());
+ this.eventType = TypeVariableResolver.resolveVariables(declaringBean.getBeanClass(), eventArgument.getBaseType());
this.id = ID_PREFIX + ID_SEPARATOR + /*manager.getId() + ID_SEPARATOR +*/ ObserverMethod.class.getSimpleName() + ID_SEPARATOR + declaringBean.getBeanClass().getName() + "." + observer.getSignature();
this.bindings = new HashSet<Annotation>(eventArgument.getMetaAnnotations(Qualifier.class));
this.reception = eventArgument.getAnnotation(Observes.class).notifyObserver();
View
32 impl/src/main/java/org/jboss/weld/injection/FieldInjectionPoint.java
@@ -35,14 +35,18 @@
import javax.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
+import org.jboss.weld.Container;
import org.jboss.weld.bean.proxy.DecoratorProxy;
import org.jboss.weld.exceptions.IllegalStateException;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy;
import org.jboss.weld.introspector.ForwardingWeldField;
+import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.util.reflection.TypeVariableResolver;
@@ -54,6 +58,7 @@
@SuppressWarnings(value = "SE_BAD_FIELD", justification = "If the bean is not serializable, we won't ever try to serialize the injection point")
private final Bean<?> declaringBean;
+ private final WeldClass<?> injectionTargetClass; // used only when declaringBean is null
private final WeldField<T, X> field;
private final boolean delegate;
private final boolean cacheable;
@@ -61,12 +66,14 @@
private Type type;
- public static <T, X> FieldInjectionPoint<T, X> of(Bean<?> declaringBean, WeldField<T, X> field) {
- return new FieldInjectionPoint<T, X>(declaringBean, field);
+ public static <T, X> FieldInjectionPoint<T, X> of(Bean<?> declaringBean, WeldClass<?> injectionTargetClass, WeldField<T, X> field) {
+ return new FieldInjectionPoint<T, X>(declaringBean, injectionTargetClass, field);
}
- protected FieldInjectionPoint(Bean<?> declaringBean, WeldField<T, X> field) {
+ protected FieldInjectionPoint(Bean<?> declaringBean, WeldClass<?> injectionTargetClass, WeldField<T, X> field) {
+ assert (declaringBean != null || injectionTargetClass != null) : "both declaringBean and injectionTargetClass are null";
this.declaringBean = declaringBean;
+ this.injectionTargetClass = injectionTargetClass;
this.field = field;
this.delegate = isAnnotationPresent(Inject.class) && isAnnotationPresent(Delegate.class) && declaringBean instanceof Decorator<?>;
this.cacheable = !delegate && !InjectionPoint.class.isAssignableFrom(field.getJavaMember().getType()) && !Instance.class.isAssignableFrom(field.getJavaMember().getType());
@@ -97,6 +104,10 @@ public int hashCode() {
return declaringBean;
}
+ public WeldClass<?> getInjectionTargetClass() {
+ return injectionTargetClass;
+ }
+
public WeldField<T, X> getWeldField() {
return field;
}
@@ -158,7 +169,7 @@ public boolean isDelegate() {
public Type getType() {
if (type == null) {
- type = TypeVariableResolver.resolveVariables(getBean(), getBaseType());
+ type = TypeVariableResolver.resolveVariables(getBean() == null ? getInjectionTargetClass().getJavaClass() : getBean().getBeanClass(), getBaseType());
}
return type;
}
@@ -182,19 +193,26 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
private static final long serialVersionUID = -3491482804822264969L;
private final String fieldName;
+ private final String injectionTargetClassName;
public SerializationProxy(FieldInjectionPoint<T, ?> injectionPoint) {
super(injectionPoint);
this.fieldName = injectionPoint.getName();
+ this.injectionTargetClassName = injectionPoint.getInjectionTargetClass().getName();
}
private Object readResolve() {
WeldField<T, ?> field = getWeldField();
- Bean<T> bean = getDeclaringBean();
- if (field == null || (bean == null && getDeclaringBeanId() != null)) {
+ if (field == null || (getDeclaringBean() == null && getDeclaringBeanId() != null)) {
throw new IllegalStateException(ReflectionMessage.UNABLE_TO_GET_FIELD_ON_DESERIALIZATION, getDeclaringBeanId(), getDeclaringWeldClass(), fieldName);
}
- return FieldInjectionPoint.of(getDeclaringBean(), getWeldField());
+
+ return FieldInjectionPoint.of(getDeclaringBean(), getInjectionTargetClass(), getWeldField());
+ }
+
+ protected WeldClass<?> getInjectionTargetClass() {
+ Class<?> clazz = getService(ResourceLoader.class).classForName(injectionTargetClassName);
+ return getService(ClassTransformer.class).loadClass(clazz);
}
protected WeldField<T, ?> getWeldField() {
View
11 impl/src/main/java/org/jboss/weld/injection/WeldInjectionPoint.java
@@ -17,6 +17,7 @@
package org.jboss.weld.injection;
import org.jboss.weld.Container;
+import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.introspector.WeldAnnotated;
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.resources.ClassTransformer;
@@ -37,22 +38,26 @@
public WeldInjectionPointSerializationProxy(WeldInjectionPoint<T, S> injectionPoint) {
this.declaringBeanId =
- injectionPoint.getBean() == null ? null : Container.instance().services().get(ContextualStore.class).putIfAbsent(injectionPoint.getBean());
+ injectionPoint.getBean() == null ? null : getService(ContextualStore.class).putIfAbsent(injectionPoint.getBean());
this.declaringClass = injectionPoint.getDeclaringType().getJavaClass();
}
protected Bean<T> getDeclaringBean() {
- return declaringBeanId == null ? null : Container.instance().services().get(ContextualStore.class).<Bean<T>, T>getContextual(declaringBeanId);
+ return declaringBeanId == null ? null : getService(ContextualStore.class).<Bean<T>, T>getContextual(declaringBeanId);
}
protected WeldClass<?> getDeclaringWeldClass() {
- return Container.instance().services().get(ClassTransformer.class).loadClass(declaringClass);
+ return getService(ClassTransformer.class).loadClass(declaringClass);
}
protected String getDeclaringBeanId() {
return declaringBeanId;
}
+ protected <E extends Service> E getService(Class<E> serviceClass) {
+ return Container.instance().services().get(serviceClass);
+ }
+
}
WeldClass<?> getDeclaringType();
View
45 impl/src/main/java/org/jboss/weld/util/Beans.java
@@ -188,21 +188,22 @@ public static boolean isBeanProxyable(Bean<?> bean) {
public static List<Set<FieldInjectionPoint<?, ?>>> getFieldInjectionPoints(Bean<?> declaringBean, WeldClass<?> weldClass) {
List<Set<FieldInjectionPoint<?, ?>>> list = new ArrayList<Set<FieldInjectionPoint<?, ?>>>();
- while (weldClass != null && !weldClass.getJavaClass().equals(Object.class)) {
- list.add(0, getDeclaredFieldInjectionPoints(declaringBean, weldClass));
- weldClass = weldClass.getWeldSuperclass();
+ WeldClass<?> c = weldClass;
+ while (c != null && !c.getJavaClass().equals(Object.class)) {
+ list.add(0, getDeclaredFieldInjectionPoints(declaringBean, weldClass, c));
+ c = c.getWeldSuperclass();
}
return list;
}
- private static Set<FieldInjectionPoint<?, ?>> getDeclaredFieldInjectionPoints(Bean<?> declaringBean, WeldClass<?> weldClass) {
+ private static Set<FieldInjectionPoint<?, ?>> getDeclaredFieldInjectionPoints(Bean<?> declaringBean, WeldClass<?> injectionTargetClass, WeldClass<?> fieldDeclaringClass) {
ArraySet<FieldInjectionPoint<?, ?>> fields = new ArraySet<FieldInjectionPoint<?, ?>>();
- for (WeldField<?, ?> field : weldClass.getDeclaredWeldFields(Inject.class)) {
+ for (WeldField<?, ?> field : fieldDeclaringClass.getDeclaredWeldFields(Inject.class)) {
if (!field.isStatic() && !field.isAnnotationPresent(Produces.class)) {
if (field.isFinal()) {
throw new DefinitionException(QUALIFIER_ON_FINAL_FIELD, field);
}
- fields.add(FieldInjectionPoint.of(declaringBean, field));
+ fields.add(FieldInjectionPoint.of(declaringBean, injectionTargetClass, field));
}
}
fields.trimToSize();
@@ -299,11 +300,7 @@ public static boolean isBeanProxyable(Bean<?> bean) {
public static Set<WeldInjectionPoint<?, ?>> getEjbInjectionPoints(Bean<?> declaringBean, WeldClass<?> type, BeanManagerImpl manager) {
if (manager.getServices().contains(EjbInjectionServices.class)) {
Class<? extends Annotation> ejbAnnotationType = manager.getServices().get(EJBApiAbstraction.class).EJB_ANNOTATION_CLASS;
- ArraySet<WeldInjectionPoint<?, ?>> ejbInjectionPoints = new ArraySet<WeldInjectionPoint<?, ?>>();
- for (WeldField<?, ?> field : type.getWeldFields(ejbAnnotationType)) {
- ejbInjectionPoints.add(FieldInjectionPoint.of(declaringBean, field));
- }
- return ejbInjectionPoints.trimToSize();
+ return getInjectionPoints(declaringBean, type, ejbAnnotationType);
} else {
return Collections.emptySet();
}
@@ -311,12 +308,8 @@ public static boolean isBeanProxyable(Bean<?> bean) {
public static Set<WeldInjectionPoint<?, ?>> getPersistenceContextInjectionPoints(Bean<?> declaringBean, WeldClass<?> type, BeanManagerImpl manager) {
if (manager.getServices().contains(JpaInjectionServices.class)) {
- ArraySet<WeldInjectionPoint<?, ?>> jpaInjectionPoints = new ArraySet<WeldInjectionPoint<?, ?>>();
Class<? extends Annotation> persistenceContextAnnotationType = manager.getServices().get(PersistenceApiAbstraction.class).PERSISTENCE_CONTEXT_ANNOTATION_CLASS;
- for (WeldField<?, ?> field : type.getWeldFields(persistenceContextAnnotationType)) {
- jpaInjectionPoints.add(FieldInjectionPoint.of(declaringBean, field));
- }
- return jpaInjectionPoints.trimToSize();
+ return getInjectionPoints(declaringBean, type, persistenceContextAnnotationType);
} else {
return Collections.emptySet();
}
@@ -324,12 +317,8 @@ public static boolean isBeanProxyable(Bean<?> bean) {
public static Set<WeldInjectionPoint<?, ?>> getPersistenceUnitInjectionPoints(Bean<?> declaringBean, WeldClass<?> type, BeanManagerImpl manager) {
if (manager.getServices().contains(JpaInjectionServices.class)) {
- ArraySet<WeldInjectionPoint<?, ?>> jpaInjectionPoints = new ArraySet<WeldInjectionPoint<?, ?>>();
Class<? extends Annotation> persistenceUnitAnnotationType = manager.getServices().get(PersistenceApiAbstraction.class).PERSISTENCE_UNIT_ANNOTATION_CLASS;
- for (WeldField<?, ?> field : type.getWeldFields(persistenceUnitAnnotationType)) {
- jpaInjectionPoints.add(FieldInjectionPoint.of(declaringBean, field));
- }
- return jpaInjectionPoints.trimToSize();
+ return getInjectionPoints(declaringBean, type, persistenceUnitAnnotationType);
} else {
return Collections.emptySet();
}
@@ -338,16 +327,20 @@ public static boolean isBeanProxyable(Bean<?> bean) {
public static Set<WeldInjectionPoint<?, ?>> getResourceInjectionPoints(Bean<?> declaringBean, WeldClass<?> type, BeanManagerImpl manager) {
if (manager.getServices().contains(ResourceInjectionServices.class)) {
Class<? extends Annotation> resourceAnnotationType = manager.getServices().get(EJBApiAbstraction.class).RESOURCE_ANNOTATION_CLASS;
- ArraySet<WeldInjectionPoint<?, ?>> resourceInjectionPoints = new ArraySet<WeldInjectionPoint<?, ?>>();
- for (WeldField<?, ?> field : type.getWeldFields(resourceAnnotationType)) {
- resourceInjectionPoints.add(FieldInjectionPoint.of(declaringBean, field));
- }
- return resourceInjectionPoints.trimToSize();
+ return getInjectionPoints(declaringBean, type, resourceAnnotationType);
} else {
return Collections.emptySet();
}
}
+ private static Set<WeldInjectionPoint<?, ?>> getInjectionPoints(Bean<?> declaringBean, WeldClass<?> type, Class<? extends Annotation> annotationType) {
+ ArraySet<WeldInjectionPoint<?, ?>> set = new ArraySet<WeldInjectionPoint<?, ?>>();
+ for (WeldField<?, ?> field : type.getWeldFields(annotationType)) {
+ set.add(FieldInjectionPoint.of(declaringBean, type, field));
+ }
+ return set.trimToSize();
+ }
+
public static List<Set<MethodInjectionPoint<?, ?>>> getInitializerMethods(Bean<?> declaringBean, WeldClass<?> type) {
List<Set<MethodInjectionPoint<?, ?>>> initializerMethodsList = new ArrayList<Set<MethodInjectionPoint<?, ?>>>();
// Keep track of all seen methods so we can ignore overridden methods
View
13 impl/src/main/java/org/jboss/weld/util/reflection/TypeVariableResolver.java
@@ -1,6 +1,5 @@
package org.jboss.weld.util.reflection;
-import javax.enterprise.inject.spi.Bean;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -22,16 +21,8 @@ public TypeVariableResolver(Class beanClass) {
this.beanClass = beanClass;
}
- public static Type resolveVariables(Bean bean, Type type) {
- if (bean == null) {
- // bean is null when we're dealing with an InjectionTarget created through BeanManager.createInjectionTarget()
- // we can't resolve variables since we're missing critical info, thus we simply return the original type for now
- return type;
- }
- if (bean.getBeanClass() == null) {
- throw new IllegalArgumentException("Bean " + bean + " has null beanClass!");
- }
- return new TypeVariableResolver(bean.getBeanClass()).resolveVariablesInType(type);
+ public static Type resolveVariables(Class beanClass, Type type) {
+ return new TypeVariableResolver(beanClass).resolveVariablesInType(type);
}
public Type resolveVariablesInType(Type type) {
Something went wrong with that request. Please try again.