16.5. Bracket Access Expressions

Bracket access expressions are those expressions which are classified as array access expressions by the Java programming language, i.e., expressions of the form e[i].

Bracket Access Expressions and Other Selector Expressions
[45]SelectorExpression::=Primary | BracketAccessExpression | ArrayGeneratorExpression | InstanceScopeExpression | SelectorExpression '.' Identifier [ Arguments ] | SelectorExpression '.' new Identifer Arguments [ AnonymousClassBody ]  
[46]BracketAccessExpression::=SelectorExpression '[' BracketSelector ']'  
[47]BracketSelector::=Identifier | Name | Expression  

The XL programming language reclassifies these expressions

  1. as property access expressions which may access a property variable of an object (see Section 7.1, “Property Variables”),

  2. as invocation expressions of operator methods (Section 11.2.2, “Operator Method Declarations”),

  3. or as conventional array access expressions.

These kinds of expressions cannot be distinguished syntactically, a distinction is made by the compiler with the help of semantic information. Namely, the expression e[i] is reclassified by the first applicable of the following rules:

  1. If i is a single identifier n, e is a property access expression for a property p, and p has a subproperty named n, then the whole expression is a property access expression for this subproperty.

  2. If i is a single identifier n, e is a local variable access expression for a query variable v which is wrapped by a query variable w (Section 17.1, “Query Variables”), and if the invocation of the method getWrapProperty of the current compile-time model returns a property q for the type of w, then the previous rule is checked again, with the expression e being replaced by a property access expression for q's type-cast property of v's type on the instance which is the value of w.

  3. If i is a single identifier n and the type of e has a direct property named n, then the whole expression is a property access expression for this property on the instance which is the result of the evaluation of e.

  4. If the type of e is an array type, the index expression undergoes unary numeric promotion; the promoted type must be int. Now if e is a property access expression for a property p which has an array type, and if p has a component property, then the whole expression is a property access expression for this component property; its index value is the result of the evaluation of i. Otherwise, the whole expression is classified as a conventional array access expression.

  5. If none of the above rules is applicable, the whole expression is reclassified as an invocation expression of an operator method named operator$index (Section 11.2.2, “Operator Method Declarations”).

The result of a property access expression is a variable of the type of the property.