]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java
Use type reflection tools from databoard in objmap2.
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / reflection / ClassBindingFactory.java
index 1295c1099ac0c8731b3be597dd967370e0b52afc..ac860d3923d4661e3ef79a8bddbb88498cf4c94a 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -729,7 +730,23 @@ public class ClassBindingFactory {
        Class<?> fieldClass = list.remove(0);
        Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
        
        Class<?> fieldClass = list.remove(0);
        Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
        
-       if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &&parameterClasses.length==1) {
+       return getTypeAnnotations(annotations, fieldClass, parameterClasses);
+    }
+
+    public static Annotation[] getMethodAnnotations(Method method) 
+    {
+        Annotation[] annotations = method.getAnnotations().clone();
+        ArrayList<Class<?>> list = new ArrayList<Class<?>>();
+        getTypes( method.getGenericReturnType(), list );
+        Class<?> valueClass = list.remove(0);
+        Class<?>[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES );
+        
+        return getTypeAnnotations(annotations, valueClass, parameterClasses);
+    }
+
+    private static Annotation[] getTypeAnnotations(Annotation[] annotations, Class<?> fieldClass,
+            Class<?>[] parameterClasses) {
+        if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &&parameterClasses.length==1) {
                Annotation[] a2 = new Annotation[annotations.length+1];
                System.arraycopy(annotations, 0, a2, 0, annotations.length);
                
                Annotation[] a2 = new Annotation[annotations.length+1];
                System.arraycopy(annotations, 0, a2, 0, annotations.length);