RuntimeException - Context not valid for type [message #1793151] |
Tue, 31 July 2018 16:42 |
Maude Sabourin Messages: 11 Registered: May 2018 |
Junior Member |
|
|
I am getting the following error when attempting to create an instance of my model :
java.lang.RuntimeException: The context 'Domainmodel returns Domainmodel' is not valid for type 'Domainmodel'
Recommended contexts for type 'Domainmodel': [Domainmodel returns Domainmodel]
The context 'Domainmodel returns Domainmodel' is valid for types: Domainmodel, null
Semantic Object: Domainmodel
URI: platform:/resource/canardnoex.sample/testsimple.canNoEx
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
at org.xtext.example.canardNoExtends.serializer.CanNoExSemanticSequencer.sequence(CanNoExSemanticSequencer.java:68)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:118)
...etc
A picture of my ecore
A simplified version of my grammar
Domainmodel:
(elements+=Type | links+=Rel)*;
Type:
Category|Block;
Category:
'cat' nameCat=STRING;
Block:
'block' name=STRING;
Rel:
'source' src=Block 'destination' des=Block;
I know that the problem is in the xtext definition of domainmodel, as I've done a test where 'Rel' was a subtype of 'Type' and this problem didn't pop.
I can't use the version mentioned just above because the 'Rel' isn't, in that case, doing a verification check to make sure the 'Block' linked do exist.
Thus, I would like to find a way to make the initial definition work.
Notes :
- Any instance of the grammar gives this error, even if it contains only 1 'Type', no 'Type', only 1 'Rel', and so on..
- Attached are :
the actual ecore file
the full grammar version
Thanks a lot!
|
|
|
Re: RuntimeException - Context not valid for type [message #1793162 is a reply to message #1793151] |
Tue, 31 July 2018 19:24 |
|
Hi, can you please provide a reproducing unit test? i could not reproduce it with a simple one
package org.xtext.example.mydsl.tests
import com.google.inject.Inject
import com.google.inject.Provider
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.serializer.ISerializer
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith
import org.xtext.example.mydsl.myDsl.MyDslFactory
@ExtendWith(InjectionExtension)
@InjectWith(MyDslInjectorProvider)
class DummyTest {
@Inject extension ISerializer
@Inject Provider<ResourceSet> rsp
@Test
def void testIt() {
val rs = rsp.get
val r = rs.createResource(URI.createURI("dummy.mydsl"))
val m = MyDslFactory.eINSTANCE.createDomainmodel=> [
elements += MyDslFactory.eINSTANCE.createCategory=>[
nameCat="Hugo"
]
]
r.contents+=m
println(m.serialize)
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03176 seconds