Annotation Type TypeCheck


@Retention(CLASS) @Target(METHOD) public @interface TypeCheck

Provides a way to define a custom type check for a defined type. The name of the annotated method must fit to the pattern is${typeName} (eg. isInteger), where ${typeName} must be a valid type defined in the parent TypeSystem. The annotated method must have exactly one argument where the type of the argument is the generic type Object or a more specific one from the TypeSystem. You can define multiple overloaded TypeCheck methods for the same type. This can be used to reduce the boxing overhead in type conversions.

By default the system generates type checks for all types in the parent TypeSystem which look like the follows:

 @TypeCheck
 boolean is${typeName}(Object value) {
         return value instanceof ${typeName};
 }
 
Example:

A type check for BigInteger with one overloaded optimized variant to reduce boxing.



 @TypeSystem(types = {int.class, BigInteger.class, String.class}, nodeBaseClass = TypedNode.class)
 public abstract class Types {
 
     @TypeCheck
     public boolean isBigInteger(Object value) {
         return value instanceof Integer || value instanceof BigInteger;
     }
 
     @TypeCheck
     public boolean isBigInteger(int value) {
         return true;
     }
 
 }