Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problems with formatter2 in Xtext 2.9
problems with formatter2 in Xtext 2.9 [message #1714663] Sun, 15 November 2015 09:44 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I started to port one of my DSLs to Xtext 2.9
(https://github.com/LorenzoBettini/javamm). I'm using the nightly
update site.

After the adaption of validator and compiler tests (due to some small
changes in the errors), tests are green but for the formatter tests.

I'm having lots of IllegalStateExceptions in many test cases from this
method
org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(INode,
NodeModelBasedRegionAccess)
in particular
if (!stack.isEmpty() && semanticElement.eContainer() !=
stack.peek().getSemanticElement())
throw new IllegalStateException();

in other test cases I have IllegalStateExceptions from here
(AbstractSyntacticSequencer):

@Override
public boolean enterAssignedParserRuleCall(RuleCall rc, EObject
semanticChild, ICompositeNode node) {
navigateToAbsorber(rc, node);
boolean shouldEnter = delegate.enterAssignedParserRuleCall(rc,
semanticChild, node);
if (shouldEnter) {
ISerializationContext child =
SerializationContext.forChild(contexts.peek().context, rc, semanticChild);
ISynAbsorberState pda = syntacticSequencerPDAs.get(child);
if (pda == null)
throw new IllegalStateException();
SyntacticalContext j = new SyntacticalContext(child, semanticChild,
pda, node);
contexts.push(j);
}
return shouldEnter;
}

any hint on how to understand what's going on?

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: problems with formatter2 in Xtext 2.9 [message #1715011 is a reply to message #1714663] Wed, 18 November 2015 13:25 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 15/11/2015 10:44, Lorenzo Bettini wrote:
> Hi
>
> I started to port one of my DSLs to Xtext 2.9
> (https://github.com/LorenzoBettini/javamm). I'm using the nightly
> update site.
>
> After the adaption of validator and compiler tests (due to some small
> changes in the errors), tests are green but for the formatter tests.
>
> I'm having lots of IllegalStateExceptions in many test cases from this
> method
> org.eclipse.xtext.formatting2.regionaccess.internal.NodeModelBasedRegionAccessBuilder.process(INode,
> NodeModelBasedRegionAccess)
> in particular
> if (!stack.isEmpty() && semanticElement.eContainer() !=
> stack.peek().getSemanticElement())
> throw new IllegalStateException();
>
> in other test cases I have IllegalStateExceptions from here
> (AbstractSyntacticSequencer):
>
> @Override
> public boolean enterAssignedParserRuleCall(RuleCall rc, EObject
> semanticChild, ICompositeNode node) {
> navigateToAbsorber(rc, node);
> boolean shouldEnter = delegate.enterAssignedParserRuleCall(rc,
> semanticChild, node);
> if (shouldEnter) {
> ISerializationContext child =
> SerializationContext.forChild(contexts.peek().context, rc, semanticChild);
> ISynAbsorberState pda = syntacticSequencerPDAs.get(child);
> if (pda == null)
> throw new IllegalStateException();
> SyntacticalContext j = new SyntacticalContext(child, semanticChild,
> pda, node);
> contexts.push(j);
> }
> return shouldEnter;
> }
>
> any hint on how to understand what's going on?
>
> thanks in advance
> Lorenzo
>

So I think I solved that myself...

it looks like the new formatter2 in Xtext 2.9 uses both the serializer
and the node model (and it also checks that the two representations are
the same)... in my DSL I was probably doing some dirty hacks ;) in
particular, I was manually rewriting the AST in one case. I fixed that
dirty hack.

In any case, I had to adjust the serializer as well in some cases,
especially when redefining/reusing some rules from Xbase.

The latter scenario can be common to other Xbase DSLs; in particular,
the homeautomation example's test3 in the FormatterTest fails, I think
because the NodeModel representation and the Serializer representation
differ:

org.junit.ComparisonFailure: expected:<...inaryOperation
X[AdditiveExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
B XFeatureCall
XAdditiveExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
286 2 S "t1"
XFeatureCall:feature=[JvmIdentifiableElement|IdOrSuper]
E XFeatureCall
XAdditiveExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
288 1 H " " Whitespace:TerminalRule'WS'
289 1 S "-"
XAdditiveExpression:feature=[JvmIdentifiableElement|OpAdd]
290 1 H " " Whitespace:TerminalRule'WS'
B XFeatureCall
XAdditiveExpression:rightOperand=XMultiplicativeExpression
path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
291 2 S "t0"
XFeatureCall:feature=[JvmIdentifiableElement|IdOrSuper]
E XFeatureCall
XAdditiveExpression:rightOperand=XMultiplicativeExpression
path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
E XBinaryOperation XAdditive]Expression:{XBinaryO...> but
was:<...inaryOperation
X[RelationalExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
B XFeatureCall
XAdditiveExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
286 2 S "t1"
XFeatureCall:feature=[JvmIdentifiableElement|IdOrSuper]
E XFeatureCall
XAdditiveExpression:{XBinaryOperation.leftOperand=}
path:XBinaryOperation/leftOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
288 1 H " " Whitespace:TerminalRule'WS'
289 1 S "-"
XAdditiveExpression:feature=[JvmIdentifiableElement|OpAdd]
290 1 H " " Whitespace:TerminalRule'WS'
B XFeatureCall
XAdditiveExpression:rightOperand=XMultiplicativeExpression
path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
291 2 S "t0"
XFeatureCall:feature=[JvmIdentifiableElement|IdOrSuper]
E XFeatureCall
XAdditiveExpression:rightOperand=XMultiplicativeExpression
path:XBinaryOperation/rightOperand=XBinaryOperation/leftOperand=XIfExpression/if=XBlockExpression/expressions[4]=Rule/thenPart=Model/declarations[2]
E XBinaryOperation XRelational]Expression:{XBinaryO...>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at
org.eclipse.xtext.junit4.formatter.FormatterTester.createRegionAccess(FormatterTester.java:160)
at
org.eclipse.xtext.junit4.formatter.FormatterTester.assertFormatted(FormatterTester.java:99)
at
org.eclipse.xtext.junit4.formatter.FormatterTester.assertFormatted(FormatterTester.java:117)
at
org.eclipse.xtext.example.homeautomation.tests.FormatterTest.test(FormatterTest.java:24)
at
org.eclipse.xtext.example.homeautomation.tests.AbstractTest.test3(AbstractTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(XtextRunner.java:49)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)



--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: problems with formatter2 in Xtext 2.9 [message #1720832 is a reply to message #1715011] Thu, 21 January 2016 10:26 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
hi Lorenzo,

could this be this bug?

https://bugs.eclipse.org/bugs/show_bug.cgi?id=485118

regards,
Moritz
Re: problems with formatter2 in Xtext 2.9 [message #1721033 is a reply to message #1720832] Fri, 22 January 2016 18:38 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 21/01/2016 11:26, Moritz Eysholdt wrote:
> hi Lorenzo,
> could this be this bug?
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=485118
>
> regards,
> Moritz

Hi

I modified my DSL so not to use dirty hacks ;)

but I haven't checked the homeautomation example I was mentioning...

Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Couldn't resolve reference to JvmType 'ecore2xtext.FormatterFragment'
Next Topic:Programatically triggering a clean and full build
Goto Forum:
  


Current Time: Fri Apr 26 03:31:03 GMT 2024

Powered by FUDForum. Page generated in 0.03066 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top