Annotation Type TypeSystem
-
@Retention(CLASS) @Target(TYPE) public @interface TypeSystem
Each
Node
has oneTypeSystem
at its root to define the types that can be used throughout the system. MultipleTypeSystem
s are allowed, but they cannot be mixed inside a singleNode
hierarchy. ATypeSystem
defines 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:TypeCheck
andTypeCast
. TheTypeCheck
checks whether a given generic value matches to the current type. TheTypeCast
casts a generic type value to the current type. If theTypeCheck
andTypeCast
annotations are not declared in theTypeSystem
the a default implementation is provided. The default implementation ofTypeCheck
returnstrue
only on an exact type match andTypeCast
is only a cast to this type. Specified methods withTypeCheck
andTypeCast
may be used to extend the definition of a type in the language. In our example, theisInteger
andasInteger
methods are defined in a way so that they accept alsoInteger
values, implicitly converting them toDouble
. This example points out how we express implicit type conversions.Example: The
TypeSystem
contains the typesBoolean
,Integer
, andDouble
. The typeObject
is 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<?>[]
value
The 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.
-
-