Table of Contents
On a large scale, classes and interfaces are declared as defined in the Java Language Specification:
Type Declaration | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
However, when looking at the details, the XL programming language defines three extensions:
Classes, interfaces, and their members, can be marked with annotations (Section 11.1, “Annotations”) similarly to annotations as specified by the Java Language Specification, Third Edition.
Classes and interfaces may contain declarations of generator methods (Section 11.2.1, “Generator Method Declarations”). Generator methods successively yield values to their invoker, instead of returning just a single value.
Classes and interfaces may contain declarations of operator methods (Section 11.2.2, “Operator Method Declarations”). Operator methods follow a special syntax and are used for the overloading of operators.
Classes may contain declarations of instancing methods (Section 11.2.3, “Instancing Method Declarations”). They are useful for the implementation of object instancing which is common in 3D computer graphics.
The purpose of an annotation is to associate information with a program element. Annotations are used as modifiers in declarations of classes, interfaces, fields, methods, and constructors. The associated information is an instance of an annotation type. The annotations of the XL programming language are similar to the annotations defined in the Java Language Specification, Third Edition; the syntax of annotations is exactly the same.
An annotation type is a concrete, public class
A
with a public constructor with no parameters
which implements the interface
de.grogra.reflect.Annotation
.
An annotation type defines a number of elements:
A
has an element named
e
if and only if A
has as member a public and non-static method with a single parameter and the
name set_
e
or init_
e
. It is
a compile-time error if several such methods with
differing parameter types exist; A
is no
legal annotation type in this case.
The type of the element e
is the type
of the method parameter. If a method named
set_
e
exists
as a member of A
, the element is an
element with default-value. Otherwise, only a method
named init_
e
exists
as a member of A
, and the element is an
element without default-value.
Now an annotation is a modifier consisting of the
token @
, the
name of an annotation type, and zero or more
element-value pairs, each of which associates a value with a different
element of the annotation type:
Modifiers and Annotations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
The identifier in an element-value pair of a normal annotation
must be the simple name of one of
the elements of the annotation type. The value
may only be composed of constants of primitive type
or String
, class literals, annotations, and arrays
of those values (using the production
ElementValueArrayInitializer).
The value is associated with the element, or,
if the element type is an array type and the value is not an
array, the associated value is an array whose sole element is the
original value. It is a compile-time error if the value to associate
is not assignable to the element type.
A marker annotation is treated as a normal annotation with no element-value
pairs. A single-element annotation is treated as a normal annotation
with a single element-value pair where the element identifier is
value
and the value is the provided value.
It is a compile-time error if more than one value is associated with a single element, or if no value is associated with an element without default-value.
As examples for a normal annotation, a marker annotation, and a single-element annotation, consider the following annotated declarations of fields, which could be interpreted by a graphical user interface in order to generate suitable input components:
@Range(min=0, max=360) private float angle; @Editable String name; @Choice({"Center", "Left", "Right"}) int alignment;