geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1438661 - in /geronimo/xbean/trunk/xbean-finder/src: main/java/org/apache/xbean/finder/AnnotationFinder.java main/java/org/apache/xbean/finder/Parameter.java test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
Date Fri, 25 Jan 2013 19:38:21 GMT
Author: dblevins
Date: Fri Jan 25 19:38:20 2013
New Revision: 1438661

URL: http://svn.apache.org/viewvc?rev=1438661&view=rev
Log:
Excellent patch from Matt Benson.
Thank you, Matt!
XBEAN-237: AnnotationFinder should provide methods to search for annotated method/constructor
parameters

Added:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java
  (with props)
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
  (with props)
Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java?rev=1438661&r1=1438660&r2=1438661&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AnnotationFinder.java
Fri Jan 25 19:38:20 2013
@@ -149,7 +149,13 @@ public class AnnotationFinder implements
         classInfos.put(info.name, info);
         index(info);
         index(info.constructors);
+        for (MethodInfo ctor : info.constructors) {
+            index(ctor.parameters);
+        }
         index(info.methods);
+        for (MethodInfo method : info.methods) {
+            index(method.parameters);
+        }
         index(info.fields);
     }
 
@@ -636,6 +642,52 @@ public class AnnotationFinder implements
         return methods;
     }
 
+    public List<Parameter<Method>> findAnnotatedMethodParameters(Class<? extends
Annotation> annotation) {
+        classesNotLoaded.clear();
+        
+        final Set<ClassInfo> seen = checkRuntimeAnnotation ? new HashSet<ClassInfo>()
: null;
+        final List<Parameter<Method>> result = new ArrayList<Parameter<Method>>();
+        for (Info info : getAnnotationInfos(annotation.getName())) {
+            if (!(info instanceof ParameterInfo)) {
+                continue;
+            }
+            final ParameterInfo parameterInfo = (ParameterInfo) info;
+            if ("<init>".equals(parameterInfo.getDeclaringMethod().getName())) {
+                continue;
+            }
+            final ClassInfo classInfo = parameterInfo.getDeclaringMethod().getDeclaringClass();
+
+            if (checkRuntimeAnnotation) {
+                if (!seen.add(classInfo)) {
+                    continue;
+                }
+                try {
+                    Class<?> clazz = classInfo.get();
+                    for (Method method : clazz.getDeclaredMethods()) {
+                        for (Annotation[] annotations : method.getParameterAnnotations())
{
+                            for (int i = 0; i < annotations.length; i++) {
+                                if (annotations[i].annotationType().equals(annotation)) {
+                                    result.add(Parameter.declaredBy(method, i));
+                                }
+                            }
+                        }
+                    }
+                } catch (ClassNotFoundException e) {
+                    classesNotLoaded.add(classInfo.getName());
+                }
+            } else {
+                try {
+                    @SuppressWarnings("unchecked")
+                    final Parameter<Method> parameter = (Parameter<Method>) parameterInfo.get();
+                    result.add(parameter);
+                } catch (ClassNotFoundException e) {
+                    classesNotLoaded.add(parameterInfo.getDeclaringMethod().getDeclaringClass().getName());
+                }
+            }
+        }
+        return result;
+    }
+
     public List<Annotated<Method>> findMetaAnnotatedMethods(Class<? extends
Annotation> annotation) {
         classesNotLoaded.clear();
 
@@ -792,6 +844,54 @@ public class AnnotationFinder implements
         return constructors;
     }
 
+    public List<Parameter<Constructor<?>>> findAnnotatedConstructorParameters(Class<?
extends Annotation> annotation) {
+        classesNotLoaded.clear();
+        
+        final Set<ClassInfo> seen = checkRuntimeAnnotation ? new HashSet<ClassInfo>()
: null;
+        final List<Parameter<Constructor<?>>> result = new ArrayList<Parameter<Constructor<?>>>();
+        for (Info info : getAnnotationInfos(annotation.getName())) {
+            if (!(info instanceof ParameterInfo)) {
+                continue;
+            }
+            final ParameterInfo parameterInfo = (ParameterInfo) info;
+            if (!"<init>".equals(parameterInfo.getDeclaringMethod().getName())) {
+                continue;
+            }
+            final ClassInfo classInfo = parameterInfo.getDeclaringMethod().getDeclaringClass();
+
+            if (checkRuntimeAnnotation) {
+                if (!seen.add(classInfo)) {
+                    continue;
+                }
+                try {
+                    Class<?> clazz = classInfo.get();
+                    for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
+                        for (Annotation[] annotations : ctor.getParameterAnnotations()) {
+                            for (int i = 0; i < annotations.length; i++) {
+                                if (annotations[i].annotationType().equals(annotation)) {
+                                    @SuppressWarnings({ "rawtypes", "unchecked" })
+                                    final Parameter<Constructor<?>> parameter
= Parameter.declaredBy((Constructor) ctor, i);
+                                    result.add(parameter);
+                                }
+                            }
+                        }
+                    }
+                } catch (ClassNotFoundException e) {
+                    classesNotLoaded.add(classInfo.getName());
+                }
+            } else {
+                try {
+                    @SuppressWarnings("unchecked")
+                    final Parameter<Constructor<?>> parameter = (Parameter<Constructor<?>>)
parameterInfo.get();
+                    result.add(parameter);
+                } catch (ClassNotFoundException e) {
+                    classesNotLoaded.add(parameterInfo.getDeclaringMethod().getDeclaringClass().getName());
+                }
+            }
+        }
+        return result;
+    }
+
     public List<Field> findAnnotatedFields(Class<? extends Annotation> annotation)
{
         classesNotLoaded.clear();
         List<ClassInfo> seen = new ArrayList<ClassInfo>();
@@ -1019,11 +1119,23 @@ public class AnnotationFinder implements
         infos.add(classInfo);
         classInfos.put(clazz.getName(), classInfo);
         for (Method method : clazz.getDeclaredMethods()) {
-            infos.add(new MethodInfo(classInfo, method));
+            MethodInfo methodInfo = new MethodInfo(classInfo, method);
+            infos.add(methodInfo);
+            for (Annotation[] annotations : method.getParameterAnnotations()) {
+                for (int i = 0; i < annotations.length; i++) {
+                    infos.add(new ParameterInfo(methodInfo, i));
+                }
+            }
         }
 
-        for (Constructor constructor : clazz.getConstructors()) {
-            infos.add(new MethodInfo(classInfo, constructor));
+        for (Constructor<?> constructor : clazz.getConstructors()) {
+            MethodInfo methodInfo = new MethodInfo(classInfo, constructor);
+            infos.add(methodInfo);
+            for (Annotation[] annotations : constructor.getParameterAnnotations()) {
+                for (int i = 0; i < annotations.length; i++) {
+                    infos.add(new ParameterInfo(methodInfo, i));
+                }
+            }
         }
 
         for (Field field : clazz.getDeclaredFields()) {
@@ -1306,6 +1418,7 @@ public class AnnotationFinder implements
         private final String descriptor;
         private final String name;
         private final List<List<AnnotationInfo>> parameterAnnotations = new ArrayList<List<AnnotationInfo>>();
+        private final List<ParameterInfo> parameters = new SingleLinkedList<ParameterInfo>();
         private Member method;
 
         public MethodInfo(ClassInfo info, Constructor constructor) {
@@ -1362,6 +1475,10 @@ public class AnnotationFinder implements
             return parameterAnnotations.get(index);
         }
 
+        public List<ParameterInfo> getParameters() {
+            return parameters;
+        }
+
         public String getName() {
             return name;
         }
@@ -1420,6 +1537,61 @@ public class AnnotationFinder implements
 
     }
 
+    public class ParameterInfo extends Annotatable implements Info {
+        private final MethodInfo declaringMethod;
+        private final int index;
+        private final List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
+        private Parameter<?> parameter;
+
+        public ParameterInfo(MethodInfo parent, int index) {
+            super();
+            this.declaringMethod = parent;
+            this.index = index;
+        }
+        
+        public ParameterInfo(MethodInfo parent, Parameter<?> parameter) {
+            super(parameter);
+            this.declaringMethod = parent;
+            this.index = parameter.getIndex();
+            this.parameter = parameter;
+        }
+
+        public String getName() {
+            return Integer.toString(index);
+        }
+
+        public Parameter<?> get() throws ClassNotFoundException {
+            if (parameter == null) {
+                Member member = declaringMethod.get();
+                if (member instanceof Method) {
+                    parameter = Parameter.declaredBy((Method) member, index);
+                } else if (member instanceof Constructor<?>) {
+                    parameter = Parameter.declaredBy((Constructor<?>) member, index);
+                    
+                }
+            }
+            return parameter;
+        }
+        
+        @Override
+        public Annotation[] getDeclaredAnnotations() {
+            try {
+                return get().getDeclaredAnnotations();
+            } catch (ClassNotFoundException e) {
+                return super.getDeclaredAnnotations();
+            }
+        }
+
+        public MethodInfo getDeclaringMethod() {
+            return declaringMethod;
+        }
+
+        @Override
+        public String toString() {
+            return String.format("%s(arg%s)", declaringMethod, index);
+        }
+    }
+
     public class FieldInfo extends Annotatable implements Info {
         private final String name;
         private final String type;
@@ -1531,6 +1703,10 @@ public class AnnotationFinder implements
             this.info = info;
         }
 
+        public Info getInfo() {
+            return info;
+        }
+
         @Override
         public void visit(int version, int access, String name, String signature, String
superName, String[] interfaces) {
             if (name.endsWith("package-info")) {
@@ -1599,6 +1775,11 @@ public class AnnotationFinder implements
             List<AnnotationInfo> annotationInfos = methodInfo.getParameterAnnotations(param);
             AnnotationInfo annotationInfo = new AnnotationInfo(desc);
             annotationInfos.add(annotationInfo);
+
+            ParameterInfo parameterInfo = new ParameterInfo(methodInfo, param);
+            methodInfo.getParameters().add(parameterInfo);
+            index(annotationInfo, parameterInfo);
+
             return new InfoBuildingVisitor(annotationInfo);
         }
     }

Added: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java?rev=1438661&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java
(added)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java
Fri Jan 25 19:38:20 2013
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xbean.finder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+public abstract class Parameter<E extends java.lang.reflect.Member> implements AnnotatedElement
{
+    private final E declaringExecutable;
+    private final int index;
+
+    private Parameter(E declaringExecutable, int index) {
+        super();
+        if (declaringExecutable == null) {
+            throw new NullPointerException("declaringExecutable");
+        }
+        this.declaringExecutable = declaringExecutable;
+        if (index < 0) {
+            throw new IndexOutOfBoundsException(Integer.toString(index));
+        }
+        this.index = index;
+    }
+
+    public E getDeclaringExecutable() {
+        return declaringExecutable;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
+        for (Annotation annotation : getAnnotations()) {
+            if (annotationClass.equals(annotation.annotationType())) {
+                @SuppressWarnings("unchecked")
+                final T result = (T) annotation;
+                return result;
+            }
+        }
+        return null;
+    }
+
+    public Annotation[] getAnnotations() {
+        return getDeclaredAnnotations();
+    }
+
+    public Annotation[] getDeclaredAnnotations() {
+        return getParameterAnnotations()[index];
+    }
+
+    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
+        return getAnnotation(annotationClass) != null;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == this) {
+            return true;
+        }
+        if (o instanceof Parameter == false) {
+            return false;
+        }
+        Parameter<?> p = (Parameter<?>) o;
+        return declaringExecutable.equals(p.declaringExecutable) && index == p.index;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = declaringExecutable.hashCode() << 4;
+        result |= index;
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Parameter[index %s of %s]", index, declaringExecutable);
+    }
+
+    protected abstract Annotation[][] getParameterAnnotations();
+
+    public static <T> Parameter<Constructor<T>> declaredBy(Constructor<T>
ctor, int index) {
+        return new Parameter<Constructor<T>>(ctor, index) {
+
+            @Override
+            protected Annotation[][] getParameterAnnotations() {
+                return getDeclaringExecutable().getParameterAnnotations();
+            }
+        };
+    }
+
+    public static Parameter<Method> declaredBy(Method method, int index) {
+        return new Parameter<Method>(method, index) {
+
+            @Override
+            protected Annotation[][] getParameterAnnotations() {
+                return getDeclaringExecutable().getParameterAnnotations();
+            }
+        };
+    }
+}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xbean.finder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+public abstract class Parameter<E extends java.lang.reflect.Member> implements AnnotatedElement
{
+    private final E declaringExecutable;
+    private final int index;
+
+    private Parameter(E declaringExecutable, int index) {
+        super();
+        if (declaringExecutable == null) {
+            throw new NullPointerException("declaringExecutable");
+        }
+        this.declaringExecutable = declaringExecutable;
+        if (index < 0) {
+            throw new IndexOutOfBoundsException(Integer.toString(index));
+        }
+        this.index = index;
+    }
+
+    public E getDeclaringExecutable() {
+        return declaringExecutable;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
+        for (Annotation annotation : getAnnotations()) {
+            if (annotationClass.equals(annotation.annotationType())) {
+                @SuppressWarnings("unchecked")
+                final T result = (T) annotation;
+                return result;
+            }
+        }
+        return null;
+    }
+
+    public Annotation[] getAnnotations() {
+        return getDeclaredAnnotations();
+    }
+
+    public Annotation[] getDeclaredAnnotations() {
+        return getParameterAnnotations()[index];
+    }
+
+    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
+        return getAnnotation(annotationClass) != null;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == this) {
+            return true;
+        }
+        if (o instanceof Parameter == false) {
+            return false;
+        }
+        Parameter<?> p = (Parameter<?>) o;
+        return declaringExecutable.equals(p.declaringExecutable) && index == p.index;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = declaringExecutable.hashCode() << 4;
+        result |= index;
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Parameter[index %s of %s]", index, declaringExecutable);
+    }
+
+    protected abstract Annotation[][] getParameterAnnotations();
+
+    public static <T> Parameter<Constructor<T>> declaredBy(Constructor<T>
ctor, int index) {
+        return new Parameter<Constructor<T>>(ctor, index) {
+
+            @Override
+            protected Annotation[][] getParameterAnnotations() {
+                return getDeclaringExecutable().getParameterAnnotations();
+            }
+        };
+    }
+
+    public static Parameter<Method> declaredBy(Method method, int index) {
+        return new Parameter<Method>(method, index) {
+
+            @Override
+            protected Annotation[][] getParameterAnnotations() {
+                return getDeclaringExecutable().getParameterAnnotations();
+            }
+        };
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/Parameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java?rev=1438661&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
(added)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
Fri Jan 25 19:38:20 2013
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.xbean.finder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.acme.NotAnnotated;
+import org.acme.bar.FullyAnnotated;
+import org.acme.bar.ParamA;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.junit.Test;
+
+public class AnnotatedParametersTest {
+
+    @Test
+    public void testFindAnnotatedMethodParameters() {
+        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class,
NotAnnotated.class));
+        List<Parameter<Method>> methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);
+        assertEquals(1, methodParameters.size());
+        Parameter<Method> parameter = methodParameters.get(0);
+        assertEquals(0, parameter.getIndex());
+        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
+        assertEquals("setMoreStrings", parameter.getDeclaringExecutable().getName());
+        assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);
+        assertEquals(String[][].class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
+        assertTrue(parameter.isAnnotationPresent(ParamA.class));
+    }
+
+    @Test
+    public void testFindAnnotatedConstructorParameters() {
+        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class,
NotAnnotated.class));
+        List<Parameter<Constructor<?>>> constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);
+        assertEquals(1, constructorParameters.size());
+        Parameter<Constructor<?>> parameter = constructorParameters.get(0);
+        assertEquals(0, parameter.getIndex());
+        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
+        assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);
+        assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
+        assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()[1]);
+        assertTrue(parameter.isAnnotationPresent(ParamA.class));
+    }
+}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.xbean.finder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.acme.NotAnnotated;
+import org.acme.bar.FullyAnnotated;
+import org.acme.bar.ParamA;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.junit.Test;
+
+public class AnnotatedParametersTest {
+
+    @Test
+    public void testFindAnnotatedMethodParameters() {
+        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class,
NotAnnotated.class));
+        List<Parameter<Method>> methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);
+        assertEquals(1, methodParameters.size());
+        Parameter<Method> parameter = methodParameters.get(0);
+        assertEquals(0, parameter.getIndex());
+        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
+        assertEquals("setMoreStrings", parameter.getDeclaringExecutable().getName());
+        assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);
+        assertEquals(String[][].class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
+        assertTrue(parameter.isAnnotationPresent(ParamA.class));
+    }
+
+    @Test
+    public void testFindAnnotatedConstructorParameters() {
+        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class,
NotAnnotated.class));
+        List<Parameter<Constructor<?>>> constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);
+        assertEquals(1, constructorParameters.size());
+        Parameter<Constructor<?>> parameter = constructorParameters.get(0);
+        assertEquals(0, parameter.getIndex());
+        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
+        assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);
+        assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
+        assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()[1]);
+        assertTrue(parameter.isAnnotationPresent(ParamA.class));
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/AnnotatedParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message