Defines a user-defined annotation class that represents a strongly typed annotation. Annotation classes are used to declare metadata that can be associated with classes and class members and later retrieved at runtime through the ABL reflection API. Annotation definitions are compiled into r-code and validated by the compiler for correctness and consistency.

An annotation class is defined in its own .cls file and contains only property definitions that describe the metadata carried by the annotation. It cannot define methods, constructors, events, or other executable elements.

Syntax

ANNOTATION annotation-type-name :
  [ property-definition ... ]
END [ ANNOTATION ].
annotation-type-name
Specifies the name of the annotation class. The name follows the same naming rules as an ABL class and typically includes a package qualifier. The annotation class name must match the name of the .cls file in which it is defined.
property-definition
Defines a property that represents a piece of metadata carried by the annotation. Properties are defined using a restricted form of the DEFINE PROPERTY statement:
DEFINE [PUBLIC] PROPERTY property-name AS primitive-type-name 
  [ INITIAL constant ].

Only built-in primitive data types (INTEGER, INT64, CHARACTER, DECIMAL, DATE, DATETIME, DATETIME-TZ, and LOGICAL) are allowed for annotation properties.

Example

The following example defines an annotation class named service.ResourceMapping with several properties that describe how a service method is exposed:

/* service/ResourceMapping.cls */
ANNOTATION service.ResourceMapping: 
  DEFINE PUBLIC PROPERTY type      AS CHARACTER. 
  DEFINE PUBLIC PROPERTY operation AS CHARACTER.
  DEFINE PUBLIC PROPERTY URI       AS CHARACTER. 
  DEFINE PUBLIC PROPERTY alias     AS CHARACTER.
  DEFINE PUBLIC PROPERTY mediaType AS CHARACTER.
END ANNOTATION.

The annotation can then be applied to a class member by enclosing the annotation usage in square brackets:

USING service.ResourceMapping FROM PROPATH.

CLASS com.sales.MyClass:

    [service.ResourceMapping(
        type       = "REST",
        operation  = "read",
        URI        = "?filter=~{filter~}",
        alias      = "",
        mediaType  = "application/json")
    ].
    METHOD PUBLIC VOID ReadTestBE(
        INPUT filter AS CHARACTER,
        OUTPUT DATASET dsTestBE):
    END METHOD.

END CLASS.

When the class is compiled, the annotation and its property values are stored in r-code and can be accessed at runtime via reflection.

Notes

  • Only one annotation class definition is allowed per .cls file.
  • Annotation classes may define properties only. Methods, constructors, events, inheritance from regular classes, and interfaces are not allowed.
  • Annotation properties are always public, implicitly read-only, and cannot be assigned values programmatically at runtime. Their values are set only through annotation usage in source code.
  • Annotation classes cannot be directly instantiated using NEW, DYNAMIC-NEW(), or reflection class constructors. Annotation instances are created implicitly by the runtime when accessed through the reflection API.
  • An annotation class implicitly inherits from Progress.Lang.Annotation. This inheritance cannot be specified explicitly in the annotation definition.
  • An annotation class may be used as a marker annotation by defining no properties. In this case, the presence of the annotation alone conveys meaning.

See also

[ ] Strongly typed annotation, DEFINE PROPERTY statement, Progress.Lang.Annotation class, IsAnnotation( ) method, GetAnnotation( ) method, GetAnnotations( ) method,