Package eu.mihosoft.vmf.core
Annotation Type Annotation
-
@Retention(RUNTIME) @Target({METHOD,TYPE}) @Repeatable(Annotations.class) public @interface Annotation
An annotation can be used to add custom metadata to entities and properties of a model.Example Model:
package mypkg.vmfmodel; import eu.mihosoft.vmf.core.*; interface Node { String getId(); @Annotation(key="api",value="input") Node getA(); @Annotation(key="api",value="input") Node getB(); @Annotation(key="api",value="output") Node getC(); }
Retrieving Annotations:
We can retrieve property annotations with the following API call:Property p = ... List
annotations = p.annotations(); Filter Annotations:
Using the stream API, one can query a specific annotation (e.g. filtered by key). Here's an example that prints all properties of a node instance annotated as input (key="api", value="input").// predicate to filter inputs Predicate
isInput = (p) -> { return p.annotationByKey("api"). map(ann->"input".equals(ann.getValue())).orElse(false); }; // query inputs: n.vmf().reflect().properties().stream().filter(isInput).forEach(p->{ System.out.println( "-> input param '" + p.getName() + "' -> node: " + ((Node)p.get()).getId() ); }); Created by miho on 05.12.2018.
- See Also:
- Tutorial on Annotation Support