next up previous
Next: Retargeting legacy reflective code Up: Pluggability Previous: Pluggability


Reconciliation via Abstract Representation

Figure [*] describes a simple abstract grammar for Java's structural reflection akin to similar representations in Smalltalk [14,7]. Left-hand-side variables are classes; right-hand-side fields are instance variables. In the figure, fields have the general form label:type, meaning that the class has an instance variable named label. The type of the instance variable can be a primitive type, as in name:String, or one of the left-hand-side variables--that is, a reference to another class as in type:Class.

A type in square brackets is optional, as in superclass:[Class]. That means an instance of Class may have a null superclass. Suffixing a type with ``[]" describes a container of values. For example, in interfaces:Class[], ``interfaces'' is the name of an instance variable of type ``Array of Class.'' If the label is missing, we assume the instance variable's name to be the plural of the component type. So Member[] means there is an instance variable named ``members'' of type ``Array of Member.''

The grammar describes a subset of reflection syntax. Java's reflection includes information that is not revealed in this grammar, such as modifiers of methods and fields. These were excluded to simplify the exposition. The grammar displayed in Figure [*] is not, however, an ordinary BNF specification. It is an abstract grammar. Information about the concrete syntax of classes, fields, and methods is missing. Hence it is worthless for parsing, but we do not intend to parse class declarations with this grammar.

In sum, this grammar serves as a semantic description of class declarations. An instance of the hierarchy in Figure [*] is better thought of as a typed semantic net than a parse tree. For example, the superclass field of Class is not an instance variable of type String with the name of the superclass. Rather, it is a reference to an instance of type Class that is the superclass itself (if one exists). Another example: Method knows its declaringClass--information that requires semantic analysis on top of parsing.

Figure: Implementation strategies for a reflective javadoc tool



Subsections
next up previous
Next: Retargeting legacy reflective code Up: Pluggability Previous: Pluggability
David H. Lorenz 2003-02-17