geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r788508 - in /geronimo/sandbox/blueprint: blueprint-api/src/main/java/org/osgi/service/blueprint/container/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ blueprint-core/src/test/java/org/apache/geronimo/blueprint/con...
Date Thu, 25 Jun 2009 20:56:35 GMT
Author: gawor
Date: Thu Jun 25 20:56:35 2009
New Revision: 788508

URL: http://svn.apache.org/viewvc?rev=788508&view=rev
Log:
fix array handling

Modified:
    geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/CollapsedType.java
    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-api/src/main/java/org/osgi/service/blueprint/container/CollapsedType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/CollapsedType.java?rev=788508&r1=788507&r2=788508&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/CollapsedType.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/CollapsedType.java
Thu Jun 25 20:56:35 2009
@@ -104,5 +104,9 @@
     public int size() {
         return 0;
     }
+    
+    public String toString() {
+        return clazz.toString();
+    }
 
 }

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=788508&r1=788507&r2=788508&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 20:56:35 2009
@@ -268,8 +268,8 @@
         if (!obj.getClass().isArray()) {
             throw new Exception("Unable to convert from " + obj + " to " + type);
         }
-        CollapsedType componentType = type.getActualTypeArgument(0);
-        Object array = Array.newInstance(toClass(componentType), Array.getLength(obj));
+        Class componentType = type.getRawClass().getComponentType();
+        Object array = Array.newInstance(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=788508&r1=788507&r2=788508&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 20:56:35 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);
+            return new GenericType(Array.newInstance(t.getRawClass(), 0).getClass(), t.parameters);
         }
         // Check if this is a generic
         int genericIndex = type.indexOf('<');
@@ -97,12 +97,13 @@
     @Override
     public String toString() {
         Class cl = getRawClass();
+        StringBuilder sb = new StringBuilder();
         if (cl.isArray()) {
-            return parameters[0].toString() + "[]";
+            sb.append(cl.getComponentType().getName());
+        } else {
+            sb.append(cl.getName());
         }
         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) {
@@ -110,10 +111,12 @@
                 }
                 sb.append(parameters[i].toString());
             }
-            sb.append(">");
-            return sb.toString();
+            sb.append(">");            
+        }        
+        if (cl.isArray()) {
+            sb.append("[]");
         }
-        return cl.getName();
+        return sb.toString();
     }
 
     static GenericType[] parametersOf(Type type ) {

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=788508&r1=788507&r2=788508&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 20:56:35 2009
@@ -18,19 +18,42 @@
  */
 package org.apache.geronimo.blueprint.container;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
 public class GenericTypeTest extends TestCase {
 
-    public void testParseTypes() throws ClassNotFoundException {
-        GenericType type = GenericType.parse("java.util.List<java.lang.String[]>",
getClass().getClassLoader());
-        System.out.println(type);
-
-        type = GenericType.parse("java.util.Map<int, java.util.List<java.lang.Integer>[]>",
getClass().getClassLoader());
-        System.out.println(type);
-
-        type = GenericType.parse("java.util.List<java.lang.Integer>[]", getClass().getClassLoader());
-        System.out.println(type.toString());
+    private GenericType parse(String expression) throws Exception {
+        GenericType type = GenericType.parse(expression, getClass().getClassLoader());
+        assertEquals(expression, type.toString());
+        return type;
+    }
+    
+    public void testParseTypes() throws Exception {
+        
+        GenericType type = parse("java.util.List<java.lang.String[]>");
+        assertEquals(List.class, type.getRawClass());
+        assertEquals(String[].class, type.getActualTypeArgument(0).getRawClass());
+        assertEquals(0, type.getActualTypeArgument(0).size());
+
+        type = parse("java.util.Map<int,java.util.List<java.lang.Integer>[]>");
+        assertEquals(Map.class, type.getRawClass());
+        assertEquals(int.class, type.getActualTypeArgument(0).getRawClass());
+        assertEquals(List[].class, type.getActualTypeArgument(1).getRawClass());
+        assertEquals(Integer.class, type.getActualTypeArgument(1).getActualTypeArgument(0).getRawClass());
+
+        type = parse("java.util.List<java.lang.Integer>[]");
+        assertEquals(List[].class, type.getRawClass());
+        assertEquals(Integer.class, type.getActualTypeArgument(0).getRawClass());
     }
 
+    public void testBasic() throws Exception {        
+        GenericType type = new GenericType(int[].class);
+        assertEquals("int[]", type.toString());
+        assertEquals(int[].class, type.getRawClass());
+        assertEquals(0, type.getActualTypeArgument(0).size());
+    }
 }



Mime
View raw message