X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2Freflection%2FClassBindingFactory.java;h=ac860d3923d4661e3ef79a8bddbb88498cf4c94a;hb=240fea4f9c0aa8dba1e1af496aebb4157740fa20;hp=8d29ad70c24ac4c8896293b22ac82817b1c617f3;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java index 8d29ad70c..ac860d392 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBindingFactory.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2019 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - gitlab #313 + *******************************************************************************/ package org.simantics.databoard.binding.reflection; import java.lang.annotation.Annotation; @@ -6,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.Method; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -200,8 +213,7 @@ public class ClassBindingFactory { if(request.hasAnnotation(Optional.class)) { Optional optional = request.getAnnotation(Optional.class); - Annotation[] newAnnotations = ArrayUtils.dropElements(request.annotations, optional); - BindingRequest componentRequest = new BindingRequest(request.getClazz(), newAnnotations); + BindingRequest componentRequest = request.withAnnotations(ArrayUtils.dropElements(request.annotations, optional)); OptionalType type = new OptionalType(); OptionalBinding binding = new OptionalBindingDefault(type, null); inprogress.put(request, binding); @@ -209,6 +221,7 @@ public class ClassBindingFactory { type.componentType = binding.componentBinding.type(); inprogress.remove(request); + repository.put(request, binding); return binding; } @@ -570,7 +583,7 @@ public class ClassBindingFactory { Identifier idAnnotation = componentRequest.getAnnotation( Identifier.class ); if ( idAnnotation!=null ) { - componentRequest.dropAnnotations(1, idAnnotation); + componentRequest = componentRequest.withAnnotations(componentRequest.dropAnnotations(1, idAnnotation)); identifierIndices.add( i ); } Binding componentBinding = componentBindings[i] = construct( componentRequest ); @@ -602,8 +615,6 @@ public class ClassBindingFactory { binding = defaultBinding; } - repository.put(request, binding); - return binding; } catch (RangeException e) { inprogress.remove( request ); @@ -719,7 +730,23 @@ public class ClassBindingFactory { Class fieldClass = list.remove(0); Class[] parameterClasses = list.isEmpty() ? NO_CLASSES : list.toArray( NO_CLASSES ); - if (Set.class.isAssignableFrom(fieldClass) && parameterClasses!=null &¶meterClasses.length==1) { + return getTypeAnnotations(annotations, fieldClass, parameterClasses); + } + + public static Annotation[] getMethodAnnotations(Method method) + { + Annotation[] annotations = method.getAnnotations().clone(); + ArrayList> list = new ArrayList>(); + 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 &¶meterClasses.length==1) { Annotation[] a2 = new Annotation[annotations.length+1]; System.arraycopy(annotations, 0, a2, 0, annotations.length);