Enhancement
TypedAnnotatable can be used to store dynamic properties on objects, see TL/TypedAnnotatable.
Improvement
Properties with collection type
- Property<List<T>> TypedAnnotatable.propertyList(...),
- Property<Set<T>> TypedAnnotatable.propertySet(...),
- Property<Map<K,V>> TypedAnnotatable.propertyMap(...),
Creates properties that return an empty collection as default value. If something is to be stored in such a collection, instead of get(MY_LIST_PROPERTY), you must then call mkList(MY_LIST_PROPERTY) to generate a mutable list and store it under the property.
Properties with dynamic default value
If you don't want to give a constant default value when defining the property, but want to calculate the default value, you can create a dynamic property:
#!java Property<String> MY_PROPERTY = TypedAnnotatable.propertyDynamic(String.class, "myProp", x -> computeDefault(x));
As an argument, the function receives the object on which the property should be looked up, but on which the property has not yet been set.
Code migration
- Instead of calling the constructor of TypedAnnotation.Property directly, a factory method TypedAnnotation.propertyXXX(...) must be used.
Test
- test.com.top_logic.basic.col.AbstractTypedAnnotationTest.testDynamicDefault()
- test.com.top_logic.basic.col.AbstractTypedAnnotationTest.testListProperty()
- test.com.top_logic.basic.col.AbstractTypedAnnotationTest.testSetProperty()
- test.com.top_logic.basic.col.AbstractTypedAnnotationTest.testMapProperty()