Author: mmerz
Date: Wed Jan 26 15:21:57 2005
New Revision: 126559

URL: http://svn.apache.org/viewcvs?view=rev&rev=126559
Log:
Fix for apt's mirror adapters working w/ complex types w/ inner classes.

Modified:
   
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java?view=diff&rev=126559&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java&r1=126558&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java&r2=126559
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java
     (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/processor/apt/TypeMirrorUtil.java
     Wed Jan 26 15:21:57 2005
@@ -28,12 +28,14 @@
     // returns a class object of the specified type.
     public static Class classForName(TypeMirror type) throws 
ClassNotFoundException {
 
+        Class clazz = null;
+        
         try {
             if (type instanceof PrimitiveType) {
-                return getPrimitiveClass(((PrimitiveType) type).getKind());
+                clazz = getPrimitiveClass(((PrimitiveType) type).getKind());
             }
             else if (type instanceof VoidType) {
-                return void.class;
+                clazz = void.class;
             }
             else if (type instanceof ArrayType) {
                 Object[] typeOfArray = new Object[]{new Object()};
@@ -51,13 +53,16 @@
                     // e.g.   an array of String will be "[Ljava.lang.String;".
                     className.append("L").append(((TypeMirror) 
typeOfArray[0]).toString()).append(";");
                 }
-                return Class.forName(className.toString());
+                clazz = findClass(className.toString());
+            }
+            else {
+                clazz = findClass(type.toString());
             }
-            return Class.forName(type.toString());
         }
         catch (ClassNotFoundException e) {
             throw new ClassNotFoundException(type.toString());
         }
+        return clazz;
     }
 
     private static Class getPrimitiveClass(PrimitiveType.Kind kind) throws 
ClassNotFoundException {
@@ -115,5 +120,37 @@
             typeOfArray[0] = type.getComponentType();
         }
         return ++depth;
+    }
+    
+    /**
+     * Since we work using the Mirror API, we need to look for inner classes
+     * ourselves. This method assumes that the class we're looking for is
+     * readily available through the class loader.
+     * @param className
+     * @return
+     * @throws ClassNotFoundException
+     */
+    private static Class findClass(String className) throws 
ClassNotFoundException {
+        Class clazz = null;
+        int idx = className.lastIndexOf('.');
+        if (-1 == idx) {
+            clazz = Class.forName(className);
+        }
+        else {
+            try {
+                clazz = Class.forName(className);
+            }
+            catch (ClassNotFoundException e) {
+                char[] chars = className.toCharArray();
+                for (int i = chars.length - 1; i >= 0 ; i--) {
+                    if ('.' == chars[i]) {
+                        chars[i] = '$';
+                        break;
+                    }
+                }
+                clazz = findClass(new String(chars));
+            }
+        }       
+        return clazz;
     }
 }

Reply via email to