Bug 477964 - [Formatter] '1+1>0' XBase expression brakes the formatter/serializer
Summary: [Formatter] '1+1>0' XBase expression brakes the formatter/serializer
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.9.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-21 10:55 EDT by Boris Brodski CLA
Modified: 2015-11-11 04:15 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Brodski CLA 2015-09-21 10:55:05 EDT
Xtext Complete SDK: 2.9.0.v201509210904

Steps to reproduce

- Create new domainmodel example projects
- Open FormatterTest.xtend and add following new test method

  @Test def void example4() {
    assertFormatted[
      toBeFormatted = '''
        entity Foo {
          op x() {
            1+1 > 0
          }
        }
      '''
    ]
  }

Running the test you will get the assertion error

org.junit.ComparisonFailure: expected:<...inaryOperation     X[AdditiveExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
     B XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
27 1 S "1"                  XNumberLiteral:value=Number
     E XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
28 0 H
28 1 S "+"                  XAdditiveExpression:feature=[JvmIdentifiableElement|OpAdd]
29 0 H
     B XNumberLiteral       XAdditiveExpression:rightOperand=XMultiplicativeExpression path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
29 1 S "1"                  XNumberLiteral:value=Number
     E XNumberLiteral       XAdditiveExpression:rightOperand=XMultiplicativeExpression path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
     E XBinaryOperation     XAdditive]Expression:{XBinaryO...> but was:<...inaryOperation     X[RelationalExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
     B XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
27 1 S "1"                  XNumberLiteral:value=Number
     E XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
28 0 H
28 1 S "+"                  XAdditiveExpression:feature=[JvmIdentifiableElement|OpAdd]
29 0 H
     B XNumberLiteral       XAdditiveExpression:rightOperand=XMultiplicativeExpression path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
29 1 S "1"                  XNumberLiteral:value=Number
     E XNumberLiteral       XAdditiveExpression:rightOperand=XMultiplicativeExpression path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XBlockExpression/expressions[0]=Operation'x'/body=Entity'Foo'/features[0]=DomainModel/elements[0]
     E XBinaryOperation     XRelational]Expression:{XBinaryO...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)


Extracting the sense out of it (first unmatched region):

Expected:
23 4 H "\r\n\t\t"           Whitespace:TerminalRule'WS'
     B XBinaryOperation     XBlockExpression:expressions+=XExpressionOrVarDeclaration 
     B XBinaryOperation     XAdditiveExpression:{XBinaryOperation.leftOperand=} 
     B XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} 

Got:

23 4 H "\r\n\t\t"           Whitespace:TerminalRule'WS'
     B XBinaryOperation     XBlockExpression:expressions+=XExpressionOrVarDeclaration 
     B XBinaryOperation     XRelationalExpression:{XBinaryOperation.leftOperand=}
     B XNumberLiteral       XAdditiveExpression:{XBinaryOperation.leftOperand=} 

As you may notice, XRelationalExpression was substituted by XAdditiveExpression.