[hibernate-commits] Hibernate SVN: r11649 - in trunk/HibernateExt/commons-annotations/src: test/org/hibernate/annotations/common/test/reflection/java and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jun 7 10:34:51 EDT 2007


Author: nusco
Date: 2007-06-07 10:34:51 -0400 (Thu, 07 Jun 2007)
New Revision: 11649

Added:
   trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java
Modified:
   trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java
   trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java
   trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java
   trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java
   trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java
Log:
ANN-612

Modified: trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java	2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -97,18 +97,12 @@
 		return new TypeSwitch<Boolean>() {
 			@Override
 			public Boolean caseClass(Class clazz) {
-				return !clazz.isArray() && !isCollectionClass( clazz );// hum probably not fully accurate
-				//return classType != void.class;
+				return !clazz.isArray() && !isCollectionClass( clazz ); // probably not fully accurate
 			}
 
 			@Override
 			public Boolean caseParameterizedType(ParameterizedType parameterizedType) {
-				for ( Type actualTypeArgument : parameterizedType.getActualTypeArguments() ) {
-					if ( !isSimple( actualTypeArgument ) ) {
-						return false;
-					}
-				}
-				return true;
+				return isSimple( parameterizedType.getRawType() );
 			}
 
 			@Override

Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java	2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -64,7 +64,7 @@
 
 	public void testExtractsPublicMethodsAsProperties() {
 		List<XProperty> methodProperties = fatherAsSeenFromSon.getDeclaredProperties( "property" );
-		assertEquals( 7, methodProperties.size() );
+		assertEquals( 9, methodProperties.size() );
 	}
 
 	public void testCanBeAbstract() {

Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java	2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -1,5 +1,7 @@
 package org.hibernate.annotations.common.test.reflection.java;
 
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -31,6 +33,8 @@
 		properties.add( "primitiveProperty" );
 		properties.add( "primitiveArrayProperty" );
 		properties.add( "arrayProperty" );
+		properties.add( "genericCollectionProperty" );
+		properties.add( "nongenericCollectionProperty" );
 		properties.add( "propertyStartingWithIs" );
 		properties.add( "language" );
 		List<XProperty> methodProperties = dadAsSeenFromSon.getDeclaredProperties( "property" );
@@ -44,7 +48,7 @@
 	}
 
 	public void testReturnsPropertiesWithUnresolvedParametricTypes() {
-		assertEquals( 7, dadAsSeenFromItself.getDeclaredProperties( "property" ).size() );
+		assertEquals( 9, dadAsSeenFromItself.getDeclaredProperties( "property" ).size() );
 	}
 
 	public void testKnowsWhetherItsTypeIsFullyResolved() {
@@ -62,7 +66,7 @@
 
 	public void testCanBeFiltered() {
 		assertEquals(
-				8, dadAsSeenFromSon.getDeclaredProperties(
+				10, dadAsSeenFromSon.getDeclaredProperties(
 				"property", new Filter() {
 
 			public boolean returnStatic() {

Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java	2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -2,6 +2,7 @@
 
 import java.util.List;
 import java.util.Map;
+
 import javax.persistence.Entity;
 
 /**
@@ -41,6 +42,14 @@
 		return null;
 	}
 
+	public List<T> getGenericCollectionProperty() {
+		return null;
+	}
+
+	public List<String> getNongenericCollectionProperty() {
+		return null;
+	}
+
 	public static Integer getStaticThing() {
 		return null;
 	}

Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java	2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -1,8 +1,11 @@
 package org.hibernate.annotations.common.test.reflection.java.generics;
 
 import java.lang.reflect.Type;
+import java.util.LinkedList;
+import java.util.List;
 
 import junit.framework.TestCase;
+
 import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment;
 import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironmentFactory;
 import org.hibernate.annotations.common.reflection.java.generics.TypeUtils;
@@ -17,15 +20,26 @@
 		assertTrue( TypeUtils.isResolved( Dad.class ) );
 	}
 
-	public void testKnowsIfAParametricTypeIsFullyResolved() throws Exception {
-		Type simpleType = Dad.class.getMethod( "returnsGeneric", new Class[0] ).getGenericReturnType();
+	private Type getPropertyFromDad(String propertyName) throws NoSuchMethodException {
+		return Dad.class.getMethod( propertyName, new Class[0] ).getGenericReturnType();
+	}
+
+	public void testKnowsWhetherAParametricTypeIsFullyResolved() throws Exception {
+		Type simpleType = getPropertyFromDad( "returnsGeneric" );
 		assertFalse( TypeUtils.isResolved( dadContext.bind( simpleType ) ) );
 		assertTrue( TypeUtils.isResolved( sonContext.bind( simpleType ) ) );
 	}
 
-	public void testKnowsIfAnArrayTypeIsFullyResolved() throws Exception {
-		Type arrayType = Dad.class.getMethod( "getArrayProperty", new Class[0] ).getGenericReturnType();
+	public void testKnowsWhetherAnArrayTypeIsFullyResolved() throws Exception {
+		Type arrayType = getPropertyFromDad( "getArrayProperty" );
 		assertFalse( TypeUtils.isResolved( dadContext.bind( arrayType ) ) );
 		assertTrue( TypeUtils.isResolved( sonContext.bind( arrayType ) ) );
 	}
+	
+	public void testKnowsWhetherATypeIsSimple() throws Exception {
+		assertTrue( TypeUtils.isSimple( String.class ) );
+		assertFalse( TypeUtils.isSimple( new String[1].getClass() ) );
+		assertFalse( TypeUtils.isSimple( getPropertyFromDad( "getNongenericCollectionProperty" ) ) );
+		assertFalse( TypeUtils.isSimple( getPropertyFromDad( "getGenericCollectionProperty" ) ) );
+	}
 }

Added: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java	                        (rev 0)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java	2007-06-07 14:34:51 UTC (rev 11649)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.annotations.common.test.reflection.java.generics.deep;
+
+import java.util.List;
+
+import javax.persistence.Transient;
+
+import junit.framework.TestCase;
+
+import org.hibernate.annotations.common.reflection.XClass;
+import org.hibernate.annotations.common.reflection.XProperty;
+import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
+
+
+/**
+ * @author Paolo Perrotta
+ */
+public class ANN612IssueTest extends TestCase {
+
+
+	public static class J<T> {}
+
+	public static class C {
+		public J<Object> thisOneAlwaysWorkedFine;
+		public J<Object[]> thisOneUsedToCauseProblems;
+	}
+	
+	public void testANN612IssueIsFixed() throws Exception {
+		JavaReflectionManager factory = new JavaReflectionManager();
+		XClass clazz = factory.toXClass( C.class );
+		List<XProperty> properties = clazz.getDeclaredProperties( XClass.ACCESS_FIELD );
+		for( XProperty property : properties ) 
+			assertTrue( property.isTypeResolved() );
+	}
+}




More information about the hibernate-commits mailing list