*
* 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;
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.
*
this.signature = classSignature;
this.annotations = annotations;
this.descriptor = classDescriptor;
- hash = className.hashCode();
- for (Annotation a : annotations) {
- hash = 7*hash + a.hashCode();
- }
+ hash = calcHash(className);
}
/**
className = clazz.getCanonicalName();
signature = getSignature(clazz);
- List<Class<?>> 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<Class<?>> classes, MutableInteger pos)
+
+ private StringBuilder _buildDescriptor(StringBuilder sb, Class<?> c, List<Class<?>> classes, MutableInteger pos)
{
int genericCount = c.getTypeParameters().length;
int genericsLeft = classes.size()-pos.value;
} else {
sb.append( getSignature(c) );
}
+ return sb;
}
public BindingRequest(Class<?> clazz, List<Annotation> annotations)