X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2Freflection%2FBindingRequest.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2Freflection%2FBindingRequest.java;h=ac2d9cf1b7246f6be353c8a15aea887ce3b8d45b;hp=51feb39c3815861e4edde721cb4970ddf33898c0;hb=95bce3521a3c97f463c3d533a36a606c7ae6f0aa;hpb=f015145947a0aaf44bd11f8dab45aef96feed149 diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java index 51feb39c3..ac2d9cf1b 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/BindingRequest.java @@ -8,7 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation - * Semantum Oy - gitlab #82 + * Semantum Oy - gitlab #82, gitlab #313 *******************************************************************************/ package org.simantics.databoard.binding.reflection; @@ -60,6 +60,23 @@ public class BindingRequest { transient int hash; + /** + * Cloning constructor with replacement annotations. + * + * @param other the request to clone + * @param annotations the annotations to use while cloning + */ + private BindingRequest(BindingRequest other, Annotation...annotations) + { + this.clazz = other.clazz; + this.cl = other.cl; + this.annotations = annotations; + this.className = other.className; + this.signature = other.signature; + this.descriptor = other.descriptor; + hash = calcHash(clazz.getName()); + } + /** * Create BindingRequest that creates class lazily. * @@ -76,10 +93,7 @@ public class BindingRequest { this.signature = classSignature; this.annotations = annotations; this.descriptor = classDescriptor; - hash = className.hashCode(); - for (Annotation a : annotations) { - hash = 7*hash + a.hashCode(); - } + hash = calcHash(className); } /** @@ -114,17 +128,23 @@ public class BindingRequest { className = clazz.getCanonicalName(); signature = getSignature(clazz); - List> args = createArgsList(); - StringBuilder desc = new StringBuilder(); - _buildDescriptor(desc, clazz, args, new MutableInteger(0)); - descriptor = desc.toString(); - hash = clazz.getName().hashCode(); - for (Annotation a : annotations) { - hash = 7*hash + a.hashCode(); + descriptor = _buildDescriptor(new StringBuilder(), clazz, createArgsList(), new MutableInteger(0)).toString(); + hash = calcHash(clazz.getName()); + } + + public BindingRequest withAnnotations(Annotation... newAnnotations) { + return new BindingRequest(this, newAnnotations); + } + + private int calcHash(String className) { + int hash = className.hashCode(); + for (Annotation a : this.annotations) { + hash += a.hashCode(); } + return hash; } - - private void _buildDescriptor(StringBuilder sb, Class c, List> classes, MutableInteger pos) + + private StringBuilder _buildDescriptor(StringBuilder sb, Class c, List> classes, MutableInteger pos) { int genericCount = c.getTypeParameters().length; int genericsLeft = classes.size()-pos.value; @@ -142,6 +162,7 @@ public class BindingRequest { } else { sb.append( getSignature(c) ); } + return sb; } public BindingRequest(Class clazz, List annotations)