Annotation Type TypeSystem
-
@Retention(CLASS) @Target(TYPE) public @interface TypeSystemEach
Nodehas oneTypeSystemat its root to define the types that can be used throughout the system. MultipleTypeSystems are allowed, but they cannot be mixed inside a singleNodehierarchy. ATypeSystemdefines a list of types as its child elements, in which every type precedes its super types.The latter condition ensures that the most concrete type is found first when searching the list sequentially for the type of a given generic value.Each
value()is represented as a java type. A type can specify two annotations:TypeCheckandTypeCast. TheTypeCheckchecks whether a given generic value matches to the current type. TheTypeCastcasts a generic type value to the current type. If theTypeCheckandTypeCastannotations are not declared in theTypeSystemthe a default implementation is provided. The default implementation ofTypeCheckreturnstrueonly on an exact type match andTypeCastis only a cast to this type. Specified methods withTypeCheckandTypeCastmay be used to extend the definition of a type in the language. In our example, theisIntegerandasIntegermethods are defined in a way so that they accept alsoIntegervalues, implicitly converting them toDouble. This example points out how we express implicit type conversions.Example: The
TypeSystemcontains the typesBoolean,Integer, andDouble. The typeObjectis always used implicitly as the generic type represent all values.@TypeSystem(types = {boolean.class, int.class, double.class}) public abstract class ExampleTypeSystem { @TypeCheck public boolean isInteger(Object value) { return value instanceof Integer || value instanceof Double; } @TypeCast public double asInteger(Object value) { return ((Number)value).doubleValue(); } }
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.Class<?>[]valueThe list of types as child elements of theTypeSystem.
-
-
-
Element Detail
-
value
java.lang.Class<?>[] value
The list of types as child elements of theTypeSystem. Each precedes its super type.
-
-