Skip to content

Commit

Permalink
WELD-1054 Parameterized bean type with actual type argument is assign…
Browse files Browse the repository at this point in the history
…able to a raw required type
  • Loading branch information
jharting committed May 23, 2012
1 parent 3280f73 commit 67b99f2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 26 deletions.
5 changes: 2 additions & 3 deletions impl/src/main/java/org/jboss/weld/bean/DisposalMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ protected void checkType() {

}

@Override
public Class<T> getType() {
return type;
public Type getGenericType() {
return getDisposesParameter().getBaseType();
}

public void destroy(T instance, CreationalContext<T> creationalContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ public Resolvable create() {
final MetaAnnotationStore store = beanManager.getServices().get(MetaAnnotationStore.class);
this.qualifierInstances.add(new QualifierInstance(DefaultLiteral.INSTANCE, store));
}
for (Class<?> facadeType : FACADE_TYPES) {
if (Reflections.isAssignableFrom(facadeType, types)) {
return createFacade(facadeType);
for (Type type : types) {
Class<?> rawType = Reflections.getRawType(type);
for (Class<?> facadeType : FACADE_TYPES) {
if (facadeType.equals(rawType)) {
return createFacade(facadeType);
}
}
}
for (Class<?> metadataType : METADATA_TYPES) {
if (Reflections.isAssignableFrom(metadataType, types)) {
return createMetadataProvider(metadataType);
for (Class<?> metadataType : METADATA_TYPES) {
if (metadataType.equals(rawType)) {
return createMetadataProvider(metadataType);
}
}
}
return new ResolvableImpl(rawType, types, mappedQualifiers, declaringBean, qualifierInstances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TypeSafeDisposerResolver(BeanManagerImpl manager, Iterable<DisposalMethod

@Override
protected boolean matches(Resolvable resolvable, DisposalMethod<?, ?> disposer) {
return resolvable.getDeclaringBean().equals(disposer.getDeclaringBean()) && Reflections.isAssignableFrom(disposer.getType(), resolvable.getTypes()) && Beans.containsAllQualifiers(QualifierInstance.qualifiers(getBeanManager(), disposer), resolvable.getQualifiers(), manager);
return resolvable.getDeclaringBean().equals(disposer.getDeclaringBean()) && Reflections.isAssignableFrom(disposer.getGenericType(), resolvable.getTypes()) && Beans.containsAllQualifiers(QualifierInstance.qualifiers(getBeanManager(), disposer), resolvable.getQualifiers(), manager);
}

@Override
Expand Down
36 changes: 30 additions & 6 deletions impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ public static boolean isEnum(Class<?> clazz) {
return clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum());
}

public static boolean isArrayOfUnboundedTypeVariablesOrObjects(Type[] types) {
for (Type type : types) {
if (Object.class.equals(type)) {
continue;
}
if (type instanceof TypeVariable<?>) {
Type[] bounds = ((TypeVariable<?>) type).getBounds();
if (bounds == null || bounds.length == 0 || (bounds.length == 1 && Object.class.equals(bounds[0]))) {
continue;
}
}
return false;
}
return true;
}

/**
* This is a helper class that holds the raw type and the actual type arguments of a Type.
* In case of arrays, the raw type is the raw type of the array, while the actualTypeArguments are the actualTypeArguments
Expand Down Expand Up @@ -555,14 +571,22 @@ public boolean matches(TypeHolder otherTypeHolder) {
}

private boolean areActualTypeArgumentsAssignableFrom(Type[] otherActualTypeArguments) {
for (int i = 0; i < this.getActualTypeArguments().length; i++) {
Type type1 = this.getActualTypeArguments()[i];
Type type2 = otherActualTypeArguments.length > i ? otherActualTypeArguments[i] : Object.class;
if (!Reflections.isAssignableFrom(type1, type2)) {
return false;
if (this.getActualTypeArguments().length == 0) {
/*
* A parameterized bean type is considered assignable to a raw required type if the raw types are identical and
* all type parameters of the bean type are either unbounded type variables or java.lang.Object.
*/
return isArrayOfUnboundedTypeVariablesOrObjects(otherActualTypeArguments);
} else {
for (int i = 0; i < this.getActualTypeArguments().length; i++) {
Type type1 = this.getActualTypeArguments()[i];
Type type2 = otherActualTypeArguments.length > i ? otherActualTypeArguments[i] : Object.class;
if (!Reflections.isAssignableFrom(type1, type2)) {
return false;
}
}
return true;
}
return true;
}

private static TypeHolder wrap(Type type) {
Expand Down
6 changes: 0 additions & 6 deletions jboss-tck-runner/1.1/src/test/resources/tck-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@
<exclude name="testSyntheticBeanIntercepted"/>
</methods>
</class>
<!-- WELD-1054 -->
<class name="org.jboss.cdi.tck.tests.lookup.typesafe.resolution.parameterized.AssignabilityOfRawAndParameterizedTypesTest">
<methods>
<exclude name="testAssignabilityToRawType"/>
</methods>
</class>
<class name="org.jboss.cdi.tck.tests.lookup.injection.parameterized.ParameterizedTypesInjectionToRawTypeTest">
<methods>
<exclude name="testInjection"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void addDecorators(@Observes AfterBeanDiscovery event, BeanManager beanMa
/**
* Must veto the custom decorator class, otherwise a bean will be created
*/
public void vetoCustomDecorator(@Observes ProcessAnnotatedType event, BeanManager beanManager) {
public void vetoCustomDecorator(@Observes ProcessAnnotatedType<?> event, BeanManager beanManager) {
if (event.getAnnotatedType().getJavaClass().equals(CustomWindowFrame.class))
event.veto();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
public class ListInstance {
@Inject
@Any
Instance<List> instance;
Instance<List<?>> instance;

public Instance<List> get() {
public Instance<List<?>> get() {
return instance;
}

Expand Down

0 comments on commit 67b99f2

Please sign in to comment.