You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2012/11/19 08:33:05 UTC
svn commit: r1411091 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/util/ClassUtil.java
test/java/org/apache/webbeans/newtests/instance/
test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java
Author: rmannibucau
Date: Mon Nov 19 07:33:04 2012
New Revision: 1411091
URL: http://svn.apache.org/viewvc?rev=1411091&view=rev
Log:
OWB-722 @Typed not respected for bean with generics
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1411091&r1=1411090&r2=1411091&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Mon Nov 19 07:33:04 2012
@@ -229,7 +229,16 @@ public final class ClassUtil
return PRIMITIVE_TO_WRAPPERS_MAP.get(clazz);
}
-
+
+ public static Class<?> identityOrGetPrimitiveWrapper(Class<?> clazz)
+ {
+ if (clazz.isPrimitive())
+ {
+ return getPrimitiveWrapper(clazz);
+ }
+ return clazz;
+
+ }
/**
* Gets the class of the given type arguments.
@@ -565,9 +574,9 @@ public final class ClassUtil
{
boolean ok = true;
ParameterizedType ptBean = (ParameterizedType)beanType;
- Class<?> clazzBeanType = (Class<?>)ptBean.getRawType();
- Class<?> clazzReqType = (Class<?>)requiredType;
- if(isClassAssignable(clazzReqType, clazzBeanType ))
+ Class<?> clazzBeanType = identityOrGetPrimitiveWrapper((Class<?>)ptBean.getRawType());
+ Class<?> clazzReqType = identityOrGetPrimitiveWrapper((Class<?>)requiredType);
+ if(clazzBeanType.equals(clazzReqType))
{
Type[] beanTypeArgs = ptBean.getActualTypeArguments();
for(Type actual : beanTypeArgs)
@@ -720,7 +729,7 @@ public final class ClassUtil
{
rhs = getPrimitiveWrapper(rhs);
}
-
+
if (lhs.isAssignableFrom(rhs))
{
return true;
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java?rev=1411091&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/instance/InstanceWithTypedTest.java Mon Nov 19 07:33:04 2012
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.instance;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.test.component.PaymentProcessorComponent;
+import org.junit.Test;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Typed;
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static junit.framework.Assert.assertNotNull;
+
+public class InstanceWithTypedTest extends AbstractUnitTest
+{
+ @Test
+ public void testTypedIsRespected()
+ {
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(TypedBean.class);
+ beanClasses.add(InstanceHolder.class);
+ beanClasses.add(RealRunnable.class);
+
+ startContainer(beanClasses, null);
+
+ InstanceHolder instance = getInstance(InstanceHolder.class);
+
+ assertNotNull(instance);
+ assertNotNull(instance.bean());
+
+ shutDownContainer();
+ }
+
+ public static class InstanceHolder
+ {
+ @Inject
+ @Any
+ private Instance<Runnable> bean;
+
+ public Runnable bean()
+ {
+ return bean.get();
+ }
+ }
+
+ public static class RealRunnable implements Runnable
+ {
+ public void run()
+ {
+ // no-op
+ }
+ }
+
+ @Typed({ TypedBean.class })
+ public static class TypedBean<X> implements Runnable
+ {
+ public void run() {
+ // no-op
+ }
+ }
+}