JSR-14 v2.4 signature details

The 2.4 prototype compiler uses the variance specifiers '-', '+', or '*' of the 2.0 prototype to start a TypeArgument; they are no longer allowed after the open-brackets in an ArrayTypeSignature. The Java syntax corresponding to '-' is "? super ", corresponding to '+' is "? extends ", and '*' corresponds to "?". The old '=' variance specifier is no longer allowed/generated. The only difference between the 2.2 grammar and the 2.4 grammar (that I know of at the moment) is in the grammar for ParameterSignature, where an extra colon has been added. A corrected version of the original JSR-14 spec follows.


Classfiles need to carry generic type information in a backwards compatible way. This is accomplished by introducing a new "Signature" attribute for classes, methods, and fields. The structure of this attributes is as follows:

  "Signature" (u4 attr-length, u2 signature-index)

When used as an attribute of a method or field, a signature gives the full (possibly generic) type of that method or field. When used as a class attribute, a signature indicates the type parameters of the class, followed by its supertype, followed by all its interfaces.

The type syntax in signatures is extended to parameterized types and type variables. There is also a new signature syntax for formal type parameters. The syntax extensions for signature strings are as follows:

MethodOrFieldSignature ::= TypeSignature

ClassSignature         ::= ParameterPartOpt super_TypeSignature interface_TypeSignatures

TypeSignatures         ::= TypeSignatures TypeSignature
                        |

TypeSignature          ::= ...
                        |  ArrayTypeSignature
                        |  ClassTypeSignature
                        |  MethodTypeSignature
                        |  TypeVariableSignature

VariantTypeSignature   ::= '-' TypeSignature
                        |  '+' TypeSignature
                        |  TypeSignature
                        |  '*'

VariantTypeSignatures  ::= VariantTypeSignatures VariantTypeSignature
                        |

ClassTypeSignature     ::= 'L' Ident TypeArgumentsOpt ';'
                        |  ClassTypeSignature '.' 'L' Ident TypeArgumentsOpt ';'

MethodTypeSignature    ::= ParameterPartOpt '(' TypeSignatures ')'
                           TypeSignature ThrowsSignatureListOpt

ThrowsSignatureList    ::= ThrowsSignature ThrowsSignatureList
                        |  ThrowsSignature

ThrowsSignature        ::= '^' TypeSignature

TypeVariableSignature  ::= 'T' Ident ';'

TypeArguments          ::= '<' VariantTypeSignature VariantTypeSignatures '>'

ParameterPart          ::= '<' ParameterSignature ParameterSignatures '>'

ParameterSignatures    ::= ParameterSignatures ParameterSignature
                        |

ParameterSignature     ::= Ident ':' TypeSignature
                        |  Ident ':' TypeSignatureOpt InterfaceBounds

InterfaceBound         ::= ':' TypeSignature

InterfaceBounds        ::= InterfaceBound InterfaceBounds
                        |  InterfaceBound

ArrayTypeSignature     ::= '[' TypeSignature

interface_TypeSignature::= TypeSignature

super_TypeSignature    ::= TypeSignature

In the prototype compilers only, vararg methods are indicated by a zero-length attribute named "Varargs" attached to the method [Clarified by Neal Gafter in a post on the GJ forum].


cscott cscott.net

Valid XHTML 1.0!