commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1444930 - /commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java
Date Mon, 11 Feb 2013 19:24:51 GMT
Author: mbenson
Date: Mon Feb 11 19:24:51 2013
New Revision: 1444930

URL: http://svn.apache.org/r1444930
Log:
array typing

Modified:
    commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java

Modified: commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java?rev=1444930&r1=1444929&r2=1444930&view=diff
==============================================================================
--- commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java
(original)
+++ commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java
Mon Feb 11 19:24:51 2013
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -13,7 +14,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.proxy.stub.AnnotationFactory;
 import org.apache.xbean.asm.AnnotationVisitor;
 import org.apache.xbean.asm.Attribute;
 import org.apache.xbean.asm.ClassReader;
@@ -47,6 +49,20 @@ class Finder extends AnnotationFinder {
 
         @Override
         protected void storeValue(String name, Object value) {
+            Validate.notNull(value, "null annotation element");
+            if (value.getClass().isArray()) {
+                final int len = Array.getLength(value);
+                final Object typedArray;
+                try {
+                    typedArray =
+                        Array.newInstance(annotationType.getDeclaredMethod(name).getReturnType().getComponentType(),
+                            len);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+                System.arraycopy(value, 0, typedArray, 0, len);
+                value = typedArray;
+            }
             elements.put(name, value);
         }
     }
@@ -80,7 +96,6 @@ class Finder extends AnnotationFinder {
 
                 @Override
                 public void visitEnd() {
-                    // TODO hmm, best way to strongly type the array
                     owner.storeValue(name, values.toArray());
                 }
 



Mime
View raw message