geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r788526 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/container/ test/java/org/apache/geronimo/blueprint/container/
Date Thu, 25 Jun 2009 22:06:50 GMT
Author: gawor
Date: Thu Jun 25 22:06:50 2009
New Revision: 788526

URL: http://svn.apache.org/viewvc?rev=788526&view=rev
Log:
handle arrays better - take 2

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java?rev=788526&r1=788525&r2=788526&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
Thu Jun 25 22:06:50 2009
@@ -268,8 +268,8 @@
         if (!obj.getClass().isArray()) {
             throw new Exception("Unable to convert from " + obj + " to " + type);
         }
-        Class componentType = type.getRawClass().getComponentType();
-        Object array = Array.newInstance(componentType, Array.getLength(obj));
+        CollapsedType componentType = type.getActualTypeArgument(0);
+        Object array = Array.newInstance(toClass(componentType), Array.getLength(obj));
         for (int i = 0; i < Array.getLength(obj); i++) {
             try {
                 Array.set(array, i, convert(Array.get(obj, i), componentType));

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java?rev=788526&r1=788525&r2=788526&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java
Thu Jun 25 22:06:50 2009
@@ -47,7 +47,7 @@
         // Check if this is an array
         if (type.endsWith("[]")) {
             GenericType t = parse(type.substring(0, type.length() - 2), loader);
-            return new GenericType(Array.newInstance(t.getRawClass(), 0).getClass(), t.parameters);
+            return new GenericType(Array.newInstance(t.getRawClass(), 0).getClass(), t);
         }
         // Check if this is a generic
         int genericIndex = type.indexOf('<');
@@ -97,13 +97,12 @@
     @Override
     public String toString() {
         Class cl = getRawClass();
-        StringBuilder sb = new StringBuilder();
         if (cl.isArray()) {
-            sb.append(cl.getComponentType().getName());
-        } else {
-            sb.append(cl.getName());
+            return parameters[0].toString() + "[]";
         }
         if (parameters.length > 0) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(cl.getName());    
             sb.append("<");
             for (int i = 0; i < parameters.length; i++) {
                 if (i > 0) {
@@ -111,17 +110,21 @@
                 }
                 sb.append(parameters[i].toString());
             }
-            sb.append(">");            
-        }        
-        if (cl.isArray()) {
-            sb.append("[]");
+            sb.append(">");   
+            return sb.toString();
         }
-        return sb.toString();
+        return cl.getName();
     }
 
     static GenericType[] parametersOf(Type type ) {
-		if ( type instanceof Class )
-			return EMPTY;
+		if ( type instanceof Class ) {
+		    Class clazz = (Class) type;
+		    if (clazz.isArray()) {
+		        return new GenericType[] { new GenericType(clazz.getComponentType()) };
+		    } else {
+		        return EMPTY;
+		    }
+		}
         if ( type instanceof ParameterizedType ) {
             ParameterizedType pt = (ParameterizedType) type;
             Type [] parameters = pt.getActualTypeArguments();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java?rev=788526&r1=788525&r2=788526&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
Thu Jun 25 22:06:50 2009
@@ -36,18 +36,23 @@
         
         GenericType type = parse("java.util.List<java.lang.String[]>");
         assertEquals(List.class, type.getRawClass());
+        assertEquals(1, type.size());
         assertEquals(String[].class, type.getActualTypeArgument(0).getRawClass());
-        assertEquals(0, type.getActualTypeArgument(0).size());
+        assertEquals(1, type.getActualTypeArgument(0).size());
+        assertEquals(String.class, type.getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
 
         type = parse("java.util.Map<int,java.util.List<java.lang.Integer>[]>");
         assertEquals(Map.class, type.getRawClass());
+        assertEquals(2, type.size());
         assertEquals(int.class, type.getActualTypeArgument(0).getRawClass());
         assertEquals(List[].class, type.getActualTypeArgument(1).getRawClass());
-        assertEquals(Integer.class, type.getActualTypeArgument(1).getActualTypeArgument(0).getRawClass());
+        assertEquals(1, type.getActualTypeArgument(1).size());
+        assertEquals(Integer.class, type.getActualTypeArgument(1).getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
 
         type = parse("java.util.List<java.lang.Integer>[]");
         assertEquals(List[].class, type.getRawClass());
-        assertEquals(Integer.class, type.getActualTypeArgument(0).getRawClass());
+        assertEquals(1, type.size());
+        assertEquals(Integer.class, type.getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
     }
 
     public void testBasic() throws Exception {        



Mime
View raw message