[JSR308] Others possible syntaxes for type annotations

Rémi Forax forax at univ-mlv.fr
Thu May 17 06:21:33 EDT 2007

Eugene Kuleshov a écrit :
>  I am not sure if type aliasing is either a good idea or in scope of 
> the JSR 308. Though it is been considered a bad idea to add new 
> keywords to Java language, including "typedef" or "syntax".
These keywords can be local (i.e only active at some point of the grammar).
I think gilad bracha has proposed a syntax equivalent to typedef but 
more java-like,
something like:
import java.util.List<String> as StringList;

based on the fact that import is already a kind of type aliasing.

So if type annotation are prefixed, the syntax could be
import <T> @NonNull T as T!;

Anyway, it will transform you code to an unreadable mess for someone 
accustomed to use
other type aliases than yours.
>  As for alternative syntaxes, I spoke to Neal Gafter at the JavaOne 
> last week and he explained his idea for non-ambiguous syntax for 
> annotations to me. He was planning to send his proposal along with 
> Java language grammar changes to this list.
>  regards,
>  Eugene
> Maxim Kizub wrote:
>> Hello.
>> 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).
> _______________________________________________
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308

More information about the JSR308 mailing list