[JSR308] Others possible syntaxes for type annotations

Maxim Kizub mkizub at gmail.com
Wed May 16 17:32:02 EDT 2007


For type annotations there may be others syntax solutions, not only 
prefix vs postfix.

First, annotations may be seen as "external" type parameters. This can 
be expressed as

Type<@NonNull> or List<String, @ConcurentAccess("write")> (or maybe use 
; to separate arguments and annotations)

Next, type annotations may be shortened using typedefs, like

typedef StringNN String<@NotNull>;
typedef String0 String<@Nullable>;

I tried to use typedefs (in my KievCompiler, which is used now as the 
core language for SymADE project, http://www.symade.org),
but found, that much more useful (for me) were postfix operators for 
types, defined by typedefs. For instance, we can define

typedef type? type<@Nullable>;
typedef type! type<@NotNull>;
typedef type# type<@Immutable>;

and then we can use operators on any type or combine multiple postfix 
operators together

String? (equivalent to String<@Nullable>)
String!# (equivalent to String<@NotNull, at Immutable>)

The same "type operator" definition syntax can be unified and used for 
all type parameters, for instance,

typedef tp& WeakRef<tp>;

will allow define weak references using & postfix type operator. Of 
cause, since there is little ASCII operators left,
it will be better to allow unicode operators (punctuation, mathematical, 
arrows, technical symbols and others
unicode subranges).

Actually, [] and ... may be seen as "standard" type operators defined as

typedef type[] java.lang.Array<type>;
typedef type... java.lang.Vararg<type>;

Also, since typedefs are expected to be common for the whole project, 
java can have special import for syntax,
i.e. like it has "import static ...;" we may add "import syntax ...;" 
and record typedefs (as well as common imports for
the project) in the named section (in KievCompiler I also use "import 
syntax" to define operators - unicode image
plus priority, arity and association).

More information about the JSR308 mailing list