Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6-beta-1
-
None
-
WinXP
-
Patch
Description
One way to find out if an expression like x = 3 * (2 + 1) has parenthesis is to have a look in the original file.
(2 + 1) represents a BinaryExpression in the AST but the line information does not include the parenthesis.
There were several problem with that:
- Need of search back the opening parenthesis from the beginning of the BinaryExpression to find out if parenthesis were used.
- in "for (i = 0; i < 10; i++)" i = 0 represents a BinaryExpression too. Applying the solution above would cause parenthesis around the
expression i = 0 because an opening parenthesis would be found. But its the parenthesis of the for-statement.
With the patch the line information of every parenthised expression (e.g. BinaryExpression) contains the parenthesis if there are any.
This is reached by wrapping the EXPR node for the parenthised expression with a new EXPR node that has line information including the parenthesis.
During the conversion from the CST to the AST the new added EXPR node is used to set the line information for the BinaryExpression. (have a look at the screenshots)
Well, it's nowhere documented how the line information must be in situation like that. But it simplifies to find out whether parenthesis are used or not.
The tests provided depend on the test environment in GROOVY-259